0

In my chrome extension, I'm using a v3 manifest. It starts a background script which starts the extension's page (extension.html) in the browser. The page also has a service script (extension.js) which handles things happening on that page. Extension.js is started from the last line of the HTML body. All of this seems to be working fine.

I've tried to encapsulate the complicated portions of the code into relevant function blocks (and seperate files), which are then called as functions from the main code stream. These functions get pulled into the background.js using importScripts('function.js'); - and this works great.

In the page's service script (extension.js), attempting to do the same importScripts('function.js'); results in Uncaught ReferenceError: importScripts is not defined,

Shouldn't this functionality work the same in both the background.js and extension.js scripts?

I've tried the various wrappers and permutations found in other similar questions. Since these are not really 'worker' scripts, those suggestions simply result in the importScript not being called. Thanks!

ChinaBOb
  • 11
  • 1
  • See the documentation for importScripts: it exists only in workers, not in normal pages. You can use a `script` tag in the html with `type=module` and then `import` statement inside the code. Do the same in your background script as well by [declaring it as a module](https://stackoverflow.com/a/66408379) in manifest.json. – wOxxOm Feb 02 '23 at 03:18

0 Answers0