Safari Extension: The service_worker script failed to load due to an error.

I have updated my web extension to use Manifest v3. While trying to test, I get the error:

_The service_worker script failed to load due to an error. _

I do not see details on the error, or a place where to find details. Any suggestions?

Answered by arnoudkooi in 712014022

I had a problem in my manifest.json, while porting I changed my manifest permission from contextMenus to context, this should be menus.

Accepted Answer

I had a problem in my manifest.json, while porting I changed my manifest permission from contextMenus to context, this should be menus.

Still having other issues causing a crash. Any clues on how to troubleshoot?

I know it's four months late but I ran into the same issue, I was able to debug mine properly by putting the extension inside of chrome and debugging there. It's stupid but seems like the only way.

Same Problem here 😖 Is there a solution for this in the meantime?

Same problem for me but only when i run it on iOS, works fine on MacOS.

Same here. Converted from chrome to safari with xcrun ../dist -> works on iOS, crashes on macos with a grey background and no errors except when i toggle the extension, I'm getting: The service_worker script failed to load due to an error. Just print a error message, is that so complicated?

Loading into Chrome can be helpful, but I am at the point where Chrome accepts the whole extension just fine and Safari just won't load it for some reason it will not tell me. I am not even transitioning an existing extension I am start from scratch and having this issue.

Please if anyone has a way to make Xcode/Safari give a more helpful error, please post. I'll keep trying on my end, but this... is a weirdly frustrating blocker because it is probably something quite simple... but it won't tell me.

Yeah I have the same issue, a chrome extension and a safari extension but the error message in safari it totally unhelpful. How can we as developers identify the issue?

Same issue here.

I believe this is a bug in Safari. Safari MV3 supports the background.page key (so-called 'Event Pages') which you might be able to use as a workaround. Try something like

  • In manifest: background: {page: background.html}
  • In background.html: <script src="my_service_worker.js"></script>

Since incorporating my "service worker" like this I have stopped seeing the error (touch wood).

Here is how I tried out:

  1. change the service worker to a very simple script, e.g. console.log('hello world'), and see if it works

  2. if it works, open safari -> develop menu -> background script window, try to add the actual service worker script into the background console using copy and paste, and see if there is any error

however, in my case, I actually forgot to add the 'service-worker.js' into the web extension project (i.e. add file reference to the xcode project), since it's a new file created solely for the migration purpose, and it only contains one line of 'importScripts(...)'.

Safari Extension: The service_worker script failed to load due to an error.
 
 
Q