Cannot import script to service worker with `self.importScripts`

I'm getting the following error when I try to import my service worker script:

[Error] Failed to load resource: unsupported URL (background_ah.worker.js, line 0)
[Error] NetworkError: Load failed

Using the following code:

try {
  self.importScripts('./background_ah.worker.js');
} catch (e) {
  console.error(e);
}

Am I doing something wrong? The file is there but from the error it seems the extension protocol is not supported at all.

It works in Chrome and it's based on this:
https://stackoverflow.com/questions/66406672/chrome-extension-mv3-modularize-service-worker-js-file

Post not yet marked as solved Up vote post of Juraj_M Down vote post of Juraj_M
1.8k views

Replies

Maybe this bug is fixed in v16 or later. https://trac.webkit.org/changeset/289236/webkit/