Søg i Support

Avoid support scams. We will never ask you to call or text a phone number or share personal information. Please report suspicious activity using the “Report Abuse” option.

Læs mere

ServiceWorker won't register and crash with TypeError when using import

  • Ingen svar
  • 0 har dette problem
  • 1 visning
more options

Hello all,

I'm building a website which uses a `ServiceWorker`. This worker uses `import` to load another JS module. As far as I understand, this should be possible starting Firefox 114 (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#browser_compatibility). However, it's crashing with an `TypeError: ServiceWorker script at https://localhost:9292/sw.js for scope https://localhost:9292/ threw an exception during script evaluation`. The worker script is loaded as module using `navigator.serviceWorker.register('./sw.js', { type: "module" })`, and working on Safari and Chrome as expected. When I remove the `import`, the worker loads and works. Tested on Firefox 118, 119, 120.

Here is a full sample: https://gist.github.com/fnordfish/9b38b90fba54093ee601887a3bd3e11e

I can't find any related bug in Bugzilla or anywhere else. Which makes me wonder what I am missing.

PS: Non module `importScripts` work.

Hello all, I'm building a website which uses a `ServiceWorker`. This worker uses `import` to load another JS module. As far as I understand, this should be possible starting Firefox 114 (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#browser_compatibility). However, it's crashing with an `TypeError: ServiceWorker script at https://localhost:9292/sw.js for scope https://localhost:9292/ threw an exception during script evaluation`. The worker script is loaded as module using `navigator.serviceWorker.register('./sw.js', { type: "module" })`, and working on Safari and Chrome as expected. When I remove the `import`, the worker loads and works. Tested on Firefox 118, 119, 120. Here is a full sample: https://gist.github.com/fnordfish/9b38b90fba54093ee601887a3bd3e11e I can't find any related bug in Bugzilla or anywhere else. Which makes me wonder what I am missing. PS: Non module `importScripts` work.