1

I have a business requirement where I need to execute dynamic arbitrary strings.

function executeScript(script){
  if (!script) {
    return;
  }
  try {
      return new Function(script)();
    }catch (err) {
    console.log('Script execution error....');
  }
}
console.log(executeScript(`if (document) {return true;}`));

According to Manifest V3 I cannot use eval() or New Function(). Are there any other libraries or solutions for this problem? I cannot package this as part of extension as user has ability to update this script any time. So bundling as part of extension would not solve my business use case. Your suggestions would be greatly appreciated.

  • 2
    No, it is forbidden by design. The workaround is to [add code to the page](https://stackoverflow.com/a/70949953) or https://crbug.com/1239976. – wOxxOm Feb 06 '22 at 10:25

0 Answers0