browser-compat-data icon indicating copy to clipboard operation
browser-compat-data copied to clipboard

api.ServiceWorkerContainer.register - firefox don't support all options like type=module

Open Eccenux opened this issue 3 years ago • 1 comments

What type of issue is this?

Missing compatibility data

What information was incorrect, unhelpful, or incomplete?

It shows that Firefox supports everything which is misleading. https://bugzilla.mozilla.org/show_bug.cgi?id=1247687

What browsers does this problem apply to, if applicable?

Firefox 102. Works in Chrome since version 91. https://web.dev/es-modules-in-sw/#browser-support

What did you expect to see?

Either split table to separate options support or at least add notes in "*" implementation notes. I guess for future would more useful to have separate options to know in which version modules will be supported.

Also mention that Chrome/Chromium supports this since v. 91. Source: https://web.dev/es-modules-in-sw/#browser-support

Did you test this? If so, how?

As an example this SW is not loading (works fine in Chrome): https://jcubic.github.io/wayne/

if ('serviceWorker' in navigator) {
    const scope = location.pathname.replace(/\/[^\/]+$/, '/');
    navigator.serviceWorker.register('sw.js', {scope, type: 'module'})
             .then(function(reg) {
                 // this is never executed...
                 console.log('Registration succeeded...');
             }).catch(function(error) {
                 // registration failed
                 console.log('Registration failed with ' + error);
                 // result: Registration failed with TypeError: ServiceWorker script at https://jcubic.github.io/wayne/sw.js for scope https://jcubic.github.io/wayne/ threw an exception during script evaluation.
             });
}

sw.js looks something like this (except for that import part nothing should cause problems):

import { Wayne } from 'https://cdn.jsdelivr.net/gh/jcubic/wayne@master/index.js';

// nothing out of ordinary here...

Can you link to any release notes, bugs, pull requests, or MDN pages related to this?

I guess most importantly module support in SW is marked as an open feature: https://bugzilla.mozilla.org/show_bug.cgi?id=1247687

Would be nice to have a link to this bug in notes or somewhere.

Do you have anything more you want to share?

No response

MDN URL

https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/register

MDN metadata

MDN page report details
  • Query: api.ServiceWorkerContainer.register
  • Report started: 2022-07-17T12:07:17.445Z

Eccenux avatar Jul 17 '22 12:07 Eccenux

Safari/Webkit seems to have implemented this in 2021-03, but that was only in a preview version... Seems like this landed in final versions of Safari 15 for desktop and mobile. Haven't tested but there is a mention about ES modules here: https://developer.mozilla.org/en-US/docs/Web/API/Worker#browser_compatibility

Eccenux avatar Jul 17 '22 12:07 Eccenux

Duplicate of #15298.

queengooborg avatar Dec 08 '23 02:12 queengooborg

Actually, I'm going to reopen this and close the other one because this has more information.

queengooborg avatar Dec 08 '23 02:12 queengooborg

Could be worth mentioning with a * that it will not support dynamic / lazy import()

jimmywarting avatar Dec 08 '23 10:12 jimmywarting

Does Firefox not support service worker scripts of type module? My tests are failing in Firefox and it seems to be because of module imports inside the service worker.

daniel-nagy avatar Dec 21 '23 15:12 daniel-nagy

Does Firefox not support service worker scripts of type module? My tests are failing in Firefox and it seems to be because of module imports inside the service worker.

That's the conclusion that I've finally come to as well after a couple days of testing and scratching my head, and caniuse agrees:

https://caniuse.com/mdn-api_serviceworker_ecmascript_modules image

dmchurch avatar Dec 23 '23 20:12 dmchurch

FYI, we do have information for whether ES modules are supported as service workers -- see https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker#browser_compatibility. It is outdated, so I've submitted a PR to fix it up, see https://github.com/mdn/browser-compat-data/pull/21767.

I've also opened a pull request to add a link to the corresponding BCD table on MDN, see https://github.com/mdn/content/pull/31361#pullrequestreview-1797715428.


and caniuse agrees

@dmchurch, that data actually comes from here! CanIUse includes BCD in its search results, and you can tell when the results are from BCD by the URL (the page slug will be prefixed with mdn-) and by the copyright notice ("Support data for this feature provided by: MDN browser-compat-data") underneath the table. 😛

queengooborg avatar Dec 28 '23 06:12 queengooborg