You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We propose adding a new option to the SharedWorker constructor that serves as a request to extend its lifetime after all current clients have unloaded:
The primary use case here is to allow pages to perform some async work that requires JavaScript after a page unloads, without needing to rely on a service worker.
Since @annevk mentioned WebKit has some trepidation about the existing extended lifetime service workers, let me emphasize a point from the explainer that we intend this new feature to provide parity with such service workers, and not give any capabilities beyond. For example, if WebKit decided to shut down all service workers for non-running pages, they would also do so for these shared workers.
The main motivation here is to reduce redundant service worker (ab)use that people currently have to resort to for this sort of work. (And which we've seen evidence of in the wild.)
I discussed this with colleagues and we do indeed consider the extended lifetime of service workers an issue. It's 10 seconds at the moment, but there's not a lot of guarantees around it so you might get far short of that number.
And while we concede that this in principle does not have to give new capabilities, we don't think it's a good idea for these reasons:
It's a bit unclear how to apply the principle in this case. I would argue that allowing web developers to use less user resources (by not spinning up long-running and persistently-stored service workers) is leaving the web better than you found it, i.e. "Where possible, build new web capabilities that improve the overall platform quality by mitigating existing defects.".
2. It doesn't seem worth building out the infrastructure for this.
This is fair. Do you have any thoughts on what sort of data might change your assessment on this? For example, if we were able to estimate how many user CPU-hours / disk loads / etc. were saved by Chromium's implementation with an A/B experiment? Or maybe just as simple as how many page loads go through a service worker vs. not?
An A/B experiment could be interesting for sure as well as more information as to which websites would want to adopt this (but would not want to work offline).
(I think there might be ways of initiating fetches that trigger that 70 second delay as part of unloading, but maybe the smaller delays win. Doesn't matter much.)
That sounds good. We'll report back with results from the origin trial and other statistics when they're available.
Following up on our earlier discussion by @domenic, I'd like to share the key findings from our Origin Trial (OT) involving 35 participating origins and how they’ve shaped the finalized proposal.
Interoperability and the "Navigation Gap" The OT confirmed a strong developer demand for a guaranteed way to maintain state during same-origin navigations within a single tab. While the HTML Standard encourages implementations to keep SharedWorkers alive briefly after unload, current implementations vary, leading to "races" where workers may terminate prematurely. extendedLifetime provides a spec-defined, interoperable mechanism to bridge this gap reliably.
Addressing Technical "Footguns": Web Locks A technical takeaway from the OT was the identification of a potential issue with Web Locks. We discussed that a long-lived worker could indefinitely hold a lock required by a client that had already unloaded. To ensure safety, we decided to enforce a strict separation between extended and non-extended lifetime workers, preventing resource management issues that could arise from overlapping lifetimes.
Operational Constraints vs. Service Workers The OT highlighted that while Service Workers are a possible alternative, the operational burden of hosting a same-origin script file is a major blocker for many third-party library providers. Feedback showed that the ability to instantiate SharedWorkers via blob: URLs (where CSP allows) offers a much more lightweight and deployable integration path for cleanup and final synchronization tasks.
Standardization The feature was successfully integrated into the HTML Standard during the trial period. We believe these technical refinements and the evidenced demand make this a safe and valuable addition to the web platform.
Activity
annevk commentedon May 19, 2025
I discussed this with colleagues and we do indeed consider the extended lifetime of service workers an issue. It's 10 seconds at the moment, but there's not a lot of guarantees around it so you might get far short of that number.
And while we concede that this in principle does not have to give new capabilities, we don't think it's a good idea for these reasons:
We rather have people continue to use service workers for this, with the reliability that service workers advertise.
As such, I suggest we resolve this with "position: oppose" one week from now.
domenic commentedon May 20, 2025
Thanks for the quick response!
Are you sure? https://github.com/WebKit/WebKit/blob/a4ab006bdf55fb59302f8cffb4c8ade78cdf0dad/Source/WebKit/NetworkProcess/NetworkProcess.cpp#L2964 seems to imply 70 seconds.
It's a bit unclear how to apply the principle in this case. I would argue that allowing web developers to use less user resources (by not spinning up long-running and persistently-stored service workers) is leaving the web better than you found it, i.e. "Where possible, build new web capabilities that improve the overall platform quality by mitigating existing defects.".
This is fair. Do you have any thoughts on what sort of data might change your assessment on this? For example, if we were able to estimate how many user CPU-hours / disk loads / etc. were saved by Chromium's implementation with an A/B experiment? Or maybe just as simple as how many page loads go through a service worker vs. not?
annevk commentedon May 21, 2025
That's the time a service worker has to handle a navigation fetch, as I understand it. https://github.com/WebKit/WebKit/blob/ab1ae05fa010398600e34dd4914aab14239717f9/Source/WebCore/workers/service/server/SWServer.h#L260-L261 is the one I was talking about.
An A/B experiment could be interesting for sure as well as more information as to which websites would want to adopt this (but would not want to work offline).
domenic commentedon May 22, 2025
(I think there might be ways of initiating fetches that trigger that 70 second delay as part of unloading, but maybe the smaller delays win. Doesn't matter much.)
That sounds good. We'll report back with results from the origin trial and other statistics when they're available.
yoshisatoyanagisawa commentedon Apr 2, 2026
Hi @annevk, @youennf,
Following up on our earlier discussion by @domenic, I'd like to share the key findings from our Origin Trial (OT) involving 35 participating origins and how they’ve shaped the finalized proposal.
Interoperability and the "Navigation Gap" The OT confirmed a strong developer demand for a guaranteed way to maintain state during same-origin navigations within a single tab. While the HTML Standard encourages implementations to keep SharedWorkers alive briefly after unload, current implementations vary, leading to "races" where workers may terminate prematurely.
extendedLifetimeprovides a spec-defined, interoperable mechanism to bridge this gap reliably.Addressing Technical "Footguns": Web Locks A technical takeaway from the OT was the identification of a potential issue with Web Locks. We discussed that a long-lived worker could indefinitely hold a lock required by a client that had already unloaded. To ensure safety, we decided to enforce a strict separation between extended and non-extended lifetime workers, preventing resource management issues that could arise from overlapping lifetimes.
Operational Constraints vs. Service Workers The OT highlighted that while Service Workers are a possible alternative, the operational burden of hosting a same-origin script file is a major blocker for many third-party library providers. Feedback showed that the ability to instantiate SharedWorkers via
blob:URLs (where CSP allows) offers a much more lightweight and deployable integration path for cleanup and final synchronization tasks.Standardization The feature was successfully integrated into the HTML Standard during the trial period. We believe these technical refinements and the evidenced demand make this a safe and valuable addition to the web platform.