Closed Bug 1360870 Opened 8 years ago Closed 3 months ago

Implement "module" service workers

Categories

(Core :: DOM: Service Workers, enhancement, P3)

enhancement

Tracking

()

RESOLVED FIXED
147 Branch
Tracking Status
relnote-firefox --- 147+
firefox147 --- fixed

People

(Reporter: bkelly, Assigned: hsingh)

References

(Blocks 5 open bugs)

Details

(4 keywords)

User Story

web-feature: js-modules-service-workers
platform-scheduled:2025-12-31
user-impact-score:200

Attachments

(6 files, 1 obsolete file)

The spec has support for loading service workers built on modules instead of classic importScripts(). See things that reference: https://w3c.github.io/ServiceWorker/#dfn-type
Ben, feel free to comment if you think this should be prioritized and need resource to work on it.
Priority: -- → P3

It might be helpful to error and link to this bug when users attempt to navigator.serviceWorker.register(url, {type: 'module'}) to make it more clear that the implementation of this is not complete. This is Chrome's current behaviour.

Blocks: 1775574
Severity: normal → S3

I'll update the in progress patch, but here is the current state:

the patch largely works, however we are breaking certain constraints: Specifically,

  • we need to disable top level await for service workers via a flag that is passed to spidermonkey
  • we need to disable dynamic import once it lands.

Otherwise we are passing a good chunk of the tests here.

Duplicate of this bug: 1775574
No longer duplicate of this bug: 1775574
Blocks: 1807919

It seems like this shouldn't be too hard to do, going to take the bug although this will not be immediate and it may end up making sense to fix bug 1808685 as part of our tech debt cleanups first. (Note that the landed patch was a disabling of a prior attempt to do that, not a fix.)

(In reply to Yulia Startsev [:yulia] | Back in Oct. from comment #5)

I'll update the in progress patch, but here is the current state:

the patch largely works, however we are breaking certain constraints: Specifically,

  • we need to disable top level await for service workers via a flag that is passed to spidermonkey

Here's the CompileOptions flag to set.

  • we need to disable dynamic import once it lands.

Yulia already implemented the check to bail out in this case, although it's currently after we do the work to create the dynamic loader, which is weird, but the initial landing state was that way per the diff for that section.

Assignee: nobody → bugmail
Status: NEW → ASSIGNED
Duplicate of this bug: 1884257

Hey I'm interested in pushing this forward. Is it necessary to fix 1808685, or can we replicate Yulia's change on top of current HEAD and it should be mostly there?

Took a crack at implementation and was able to run it against a local app (with module serviceworkers and import statements) I've been working on!

I'm assuredly missing some implementations of equality checks and things like that, so it would be helpful to get someone who knows the surrounding code to take a look.

I'd love to pull in the related WPT tests for service worker modules, but I'm not familiar with how to do that.

Thanks for trying your hand! I think the main things that are missing are disabling top-level await and the ServiceWorkerRegistrar persistence which requires a schema version change to the file. As a heads-up, we have a few in-flight priority patch stacks right now that are likely going to bit-rot some of the plumbing in the patch over the next 1-2 weeks.

Awesome. Could we get away with sticking the new field at the end of the serialization and default to ModuleType::Classic if we hit the terminator early? (or would that constitute a version change anyway).

No worries about the bitrot. I won't rest until every -Info -Data -Registrar -Parent and -Child has a WorkerType aType in its constructor.

thanks for taking this over!

(In reply to John Renner from comment #13)

Awesome. Could we get away with sticking the new field at the end of the serialization and default to ModuleType::Classic if we hit the terminator early? (or would that constitute a version change anyway).

That would constitute a version change anyway, because the logic that makes sure the registration terminator is where we expect it would discard the registrations anyways on (unsupported[1]) downgrade.

A nice part of bumping the rev is that we can also then potentially write "module" or "classic" adjacent to the cache UUID that makes the file format a little bit more human readable than just stashing it as a new last line.

1: So although there is a defensive build id ratchet on profiles now that yells at users if they try and downgrade, we do try and "handle" downgrades so that people doing bisection or having to roll-back at least won't get into super-weird states.

Assignee: bugmail → john+bugzilla

The bug assignee is inactive on Bugzilla, so the assignee is being reset.

Assignee: john+bugzilla → nobody
Status: ASSIGNED → NEW

Hey there -- I just wanted to voice some support for this issue. I've been working on building a cross-platform service worker for a library called Automerge which works across the Blink family of browsers, Safari, and Firefox. Unfortunately, Firefox (in service workers) is the odd platform out right now and my users are complaining. I'd really really like not to open the can of worms that it would entail to develop and test yet another version of the library that works cross platform that is only for service workers based on importScripts, particularly since there seems to be some energy around landing this feature in Firefox.

I'm happy to test builds, and provide validation (technical or emotional) if it helps get this patch landed.

WebGPU CTS uses module workers for coverage of service workers. Also, most service worker demos I'm aware of for WebGPU use module scripts. This makes deployment of service workers for WebGPU applications in Firefox require additional work, and hurts our story for Firefox as a developer's primary developer browser.

The WebGPU project and our internal ML team has blockers that are (now) depending upon this. Additionally, we have people at huggingface.io who are also wanting to have this available--a vast majority of the service worker dependencies they have are with module workers. Can we get this issue resuscitated and its priority elevated?

Flags: needinfo?(smaug)

Apologies for not coming back to this (despite an admittedly my bold declaration above). I continue to not have time amongst the many responsiblities of life. The change shouldn't be too bad for someone with knowledge of the code since most of the underlying support in the runtime is there, it's mostly just threading the flag.

Just a note that over here at Ink & Switch we're building local-first projects that rely heavily on Service Workers and don't support Firefox because of this missing feature. We have had a few sad folks as a result and I'd love to have Firefox support.

Flags: needinfo?(smaug) → needinfo?(jstutte)

Hi all! I'd also like to voice support for this issue. I'm the lead maintainer of Transformers.js, a JavaScript library for running ML models in the browser, and many of our users (and those testing our demos) have mentioned that they often run into browser issues when using Firefox. One of which, is this one: module support in service workers. So, it would be great to have this working!

We've released a bunch of demos that can help with testing; hopefully they will be useful:

(In reply to Joshua Lochner from comment #22)

We've released a bunch of demos that can help with testing; hopefully they will be useful:

Hi Josh, can you point to a specific demo that requires module support in service workers?

Flags: needinfo?(joshua)

(In reply to Peter van Hardenberg from comment #21)

Just a note that over here at Ink & Switch we're building local-first projects that rely heavily on Service Workers and don't support Firefox because of this missing feature. We have had a few sad folks as a result and I'd love to have Firefox support.

Peter, can you share some examples?

Flags: needinfo?(pvh)

Sure thing!

One easy example is this project here which uses our Automerge library
in a service-worker: https://github.com/pvh/trail-runner

There's a copy of it uploaded here: https://am.pvh.ca/@pvh.ca/www/
(If I remember correctly the service worker simply fails to load on FF
without a lot of helpful error messages but that might have been a
different bug.)

It should report an error linking to the bug in Firefox but the code
of the service-worker can illustrate the use:
https://github.com/pvh/trail-runner/blob/main/src/service-worker.js

You can see that I am importing modules there. This code works in all
other browsers I'm aware of, including Chrome, Edge, and Safari.

Our as-yet-unpublished Patchwork project has a horrifying workaround
with a custom one-off build & bundle for the service worker due to the
fact that Vite reasonably assumes every part of Firefox has support for
the same language features. That does work in Firefox but makes me very
very sad and was expensive to build and is annoying to maintain.

Let me know if I can provide any further examples. I've spent an extraordinary
amount of time working on build systems and fighting package managers
because of this bug and I would love to help make sure nobody else does.

Flags: needinfo?(pvh)
Flags: needinfo?(jstutte) → needinfo?(htsai)

Thanks for forwarding the needinfo. Will bring to team backlog discussion.

Flags: needinfo?(htsai)
User Story: (updated)
User Story: (updated)

Redirect a needinfo that is pending on an inactive user to the triage owner.
:edenchuang, since the bug has recent activity, could you have a look please?

For more information, please visit BugBot documentation.

Flags: needinfo?(joshua) → needinfo?(echuang)
Assignee: nobody → hsingh

Harveer -- thanks for picking this one up. Getting this fixed will make a big difference to supporting our work (and indeed a lot of modern JS) in Firefox. Let me know if there's anything I can test or give input on. Also -- I see that there's a needinfo flag on the bug. I believe my response above should have cleared that so I'll mark it thus below.

Flags: needinfo?(echuang)
Attachment #9512649 - Attachment description: WIP: Bug 1360870: webidl changes to support module service workers.r=asuth → Bug 1360870: idl changes to support module service workers.r=asuth,edenchuang
Attachment #9512650 - Attachment description: WIP: Bug 1360870: Some source code plumbing and refactorings to support new serviceworker type.r=asuth → Bug 1360870: Some source code plumbing and refactorings to support new serviceworker type.r=asuth,edenchuang
Attachment #9512651 - Attachment description: WIP: Bug 1360870: on-disk schema changes to persist new serviceworker type parameter.r=asuth → Bug 1360870: on-disk schema changes to persist new serviceworker type parameter.r=asuth,edenchuang
Attachment #9512652 - Attachment description: WIP: Bug 1360870: wpt test changes.r=asuth → Bug 1360870: wpt test changes.r=asuth,edenchuang
Attachment #9512652 - Attachment description: Bug 1360870: wpt test changes.r=asuth,edenchuang → Bug 1360870: Test changes.r=asuth,edenchuang
User Story: (updated)
Depends on: 1989386
Depends on: 1990295
Depends on: 1995558

Comment on attachment 9521470 [details]
Bug 1360870: Service worker module registration should be rejected in case of any evaluation errors.r=edenchuang,asuth

Revision D269457 was moved to bug 1995558. Setting attachment 9521470 [details] to obsolete.

Attachment #9521470 - Attachment is obsolete: true
Pushed by hsingh@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/c8854f0a2725 https://hg.mozilla.org/integration/autoland/rev/f90cf20504a1 idl changes to support module service workers.r=asuth,edenchuang,webidl,smaug,dom-worker-reviewers https://github.com/mozilla-firefox/firefox/commit/040663a23b2f https://hg.mozilla.org/integration/autoland/rev/ec090502c01b Some source code plumbing and refactorings to support new serviceworker type.r=edenchuang,dom-worker-reviewers https://github.com/mozilla-firefox/firefox/commit/bf551670f43f https://hg.mozilla.org/integration/autoland/rev/869bc3731e92 on-disk schema changes to persist new serviceworker type parameter.r=edenchuang,dom-worker-reviewers https://github.com/mozilla-firefox/firefox/commit/5308d85d1342 https://hg.mozilla.org/integration/autoland/rev/2227726e4217 Test changes.r=edenchuang,dom-worker-reviewers
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/55754 for changes under testing/web-platform/tests
Pushed by abutkovits@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/285b305de4a1 https://hg.mozilla.org/integration/autoland/rev/254ce923c1e5 Revert "Bug 1360870, Bug 1995558, Bug 1990925, Bug 1989386: Test changes.r=edenchuang,dom-worker-reviewers" for causing failures at browser_dbg-browser-toolbox-workers.js.
Upstream PR merged by moz-wptsync-bot
Pushed by hsingh@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/2b4f2ed60e7c https://hg.mozilla.org/integration/autoland/rev/1b6f0f57bbe9 idl changes to support module service workers.r=asuth,edenchuang,webidl,smaug,dom-worker-reviewers https://github.com/mozilla-firefox/firefox/commit/e813c3de2fea https://hg.mozilla.org/integration/autoland/rev/9b7865adfc98 Some source code plumbing and refactorings to support new serviceworker type.r=edenchuang,dom-worker-reviewers https://github.com/mozilla-firefox/firefox/commit/9f740083c944 https://hg.mozilla.org/integration/autoland/rev/fbab3e41daef on-disk schema changes to persist new serviceworker type parameter.r=edenchuang,dom-worker-reviewers https://github.com/mozilla-firefox/firefox/commit/7604e737bedb https://hg.mozilla.org/integration/autoland/rev/a14f11dd63a4 Test changes.r=edenchuang,dom-worker-reviewers
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/55820 for changes under testing/web-platform/tests
Pushed by chorotan@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/3880a52dfd69 https://hg.mozilla.org/integration/autoland/rev/b8e7bea8aa25 Revert "Bug 1360870, Bug 1989386, Bug 1990925, Bug 1995558: Test changes.r=edenchuang,dom-worker-reviewers" for causing dt failures on browser_webconsole_json_mime.js

Backed out for causing dt failures

Backout link

Push with failures

Failure log

Upstream PR merged by moz-wptsync-bot
Pushed by hsingh@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/f7f43476a276 https://hg.mozilla.org/integration/autoland/rev/d363f27ded29 idl changes to support module service workers.r=asuth,edenchuang,webidl,smaug,dom-worker-reviewers https://github.com/mozilla-firefox/firefox/commit/f8438fb258f7 https://hg.mozilla.org/integration/autoland/rev/e61feb83a39c Some source code plumbing and refactorings to support new serviceworker type.r=edenchuang,dom-worker-reviewers https://github.com/mozilla-firefox/firefox/commit/9e90e5f01e33 https://hg.mozilla.org/integration/autoland/rev/36f6edbe47a4 on-disk schema changes to persist new serviceworker type parameter.r=edenchuang,dom-worker-reviewers https://github.com/mozilla-firefox/firefox/commit/5f838f6b5a52 https://hg.mozilla.org/integration/autoland/rev/776f65638b1f Test changes.r=edenchuang,dom-worker-reviewers https://github.com/mozilla-firefox/firefox/commit/fdacf289d5a7 https://hg.mozilla.org/integration/autoland/rev/ac46df43805a 1989386, 1990925, 1995558: apply code formatting via Lando
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/55842 for changes under testing/web-platform/tests
Regressions: 1998332
Pushed by nbeleuzu@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/88121de0ccd1 https://hg.mozilla.org/mozilla-central/rev/9a81a01d61b6 Revert "Bug 1360870, 1989386, 1990925, 1995558: apply code formatting via Lando" for causing the macOS top crash in Bug 1998332

Backed out for causing the macOS top crash in Bug 1998332

Backout link

Push with failures

Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Target Milestone: 146 Branch → ---
Upstream PR merged by moz-wptsync-bot
Pushed by hsingh@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/b7e87aa1ed6f https://hg.mozilla.org/integration/autoland/rev/6695a4a7a649 idl changes to support module service workers.r=asuth,edenchuang,webidl,smaug,dom-worker-reviewers https://github.com/mozilla-firefox/firefox/commit/ba62ccaac5d8 https://hg.mozilla.org/integration/autoland/rev/5e854a4d5fcc Some source code plumbing and refactorings to support new serviceworker type.r=edenchuang,dom-worker-reviewers https://github.com/mozilla-firefox/firefox/commit/bb54c74efc00 https://hg.mozilla.org/integration/autoland/rev/0dc4ed5913a7 on-disk schema changes to persist new serviceworker type parameter.r=edenchuang,dom-worker-reviewers https://github.com/mozilla-firefox/firefox/commit/14962d82fd6c https://hg.mozilla.org/integration/autoland/rev/61e88493ad15 Test changes.r=edenchuang,dom-worker-reviewers https://github.com/mozilla-firefox/firefox/commit/161c6ab8c0b0 https://hg.mozilla.org/integration/autoland/rev/be5b6a995776 1989386, 1990925, 1995558: apply code formatting via Lando
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/56035 for changes under testing/web-platform/tests
Upstream PR was closed without merging
Upstream PR merged by moz-wptsync-bot
Upstream PR merged by moz-wptsync-bot

Please make sure to request a release note for this.

Flags: needinfo?(hsingh)

FF147 MDN docs work for this can be tracked in https://github.com/mdn/content/issues/42249

QA Whiteboard: [qa-triage-done-c148/b147]

(In reply to Tom S. (please needinfo tschuster) from comment #57)

Please make sure to request a release note for this.

Flags: needinfo?(hsingh)

Release Note Request (optional, but appreciated)
[Why is this notable]: Module service workers has been long supported by other major browser vendors. This has been a critical feature from a web-compat point of view as well.
[Affects Firefox for Android]: Yes
[Suggested wording]: Module service workers are now supported, aligning Firefox with other major browsers and improving compatibility for modern web apps.
[Links (documentation, blog post, etc)]: https://www.w3.org/TR/service-workers/

relnote-firefox: --- → ?
Flags: needinfo?(hsingh)

Added to the Fx147 relnotes.

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: