commit cfee56ce882d0eb0acbe680458d726a6317240fe
parent e4bb80f8de530209c161c6acaf51d83cf888571c
Author: Anna Sato <annasato@chromium.org>
Date: Wed, 15 Oct 2025 08:59:27 +0000
Bug 1994204 [wpt PR 55410] - Evict BFCached pages with SharedWorker when the last client navigates away, a=testonly
Automatic update from web-platform-tests
Evict BFCached pages with SharedWorker when the last client navigates away
This CL prevents a SharedWorker from remaining active when all of its
clients are in BFCache. When the last active client of a SharedWorker
navigates away:
- The navigating client is blocked from entering BFCache.
- Any other clients of the same SharedWorker that are already in BFCache are evicted.
- As a result, the SharedWorker is left with no clients and is
subsequently terminated.
This change is the minimum behavior required for the SharedWorkerBFCache
launch as described at "Worker state when last client enters BFCache" in
[1]. The better long-term solution is to freeze the worker instead of
evicting clients, which is noted as TODOs.
[1]
https://docs.google.com/document/d/1dZxwmUYOlDmZ-PF97mfoXbzMrFHBsqeUT3XxTkpNIb0/edit?usp=sharing
Bug: 406420935, 431875857
Change-Id: I038b17dc890e50b7a57e6d8c5f496e11cb302f66
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6914636
Reviewed-by: Anders Hartvoll Ruud <andruud@chromium.org>
Reviewed-by: Guillem Perez <guiperez@google.com>
Auto-Submit: Anna Sato <annasato@chromium.org>
Commit-Queue: Anna Sato <annasato@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1529241}
--
wpt-commits: fa068c4ef71141f96cb3481cd241bd454bfc73ab
wpt-pr: 55410
Diffstat:
1 file changed, 49 insertions(+), 0 deletions(-)
diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/back-forward-cache/eligibility/shared-worker-active-client.window.js b/testing/web-platform/tests/html/browsers/browsing-the-web/back-forward-cache/eligibility/shared-worker-active-client.window.js
@@ -0,0 +1,49 @@
+// META: title=BFCache is allowed for a page with SharedWorker if another client is active.
+// META: script=/common/utils.js
+// META: script=/common/dispatcher/dispatcher.js
+// META: script=/html/browsers/browsing-the-web/back-forward-cache/resources/helper.sub.js
+// META: timeout=long
+
+'use strict';
+
+// Check whether the page is BFCached when there is another active client for
+// the shared worker.
+runBfcacheTest(
+ {
+ funcBeforeNavigation: async () => {
+ globalThis.worker = new SharedWorker('../resources/echo-worker.js');
+ await WorkerHelper.pingWorker(globalThis.worker);
+
+ // Create another client in a new window.
+ const workerUrl =
+ new URL('../resources/echo-worker.js', window.location.href).href;
+ const helperPageContent = `
+ <script>
+ new SharedWorker('${workerUrl}');
+ const bc = new BroadcastChannel('worker_ready');
+ bc.postMessage('ready');
+ bc.close();
+ </script>
+ `;
+ const blob = new Blob([helperPageContent], {type: 'text/html'});
+ window.open(URL.createObjectURL(blob), '_blank', 'noopener');
+ await new Promise(resolve => {
+ const bc = new BroadcastChannel('worker_ready');
+ bc.onmessage = e => {
+ if (e.data === 'ready') {
+ bc.close();
+ resolve();
+ }
+ };
+ });
+ },
+ funcAfterAssertion: async (pageA) => {
+ // Confirm that the worker is still there.
+ assert_equals(
+ await pageA.execute_script(
+ () => WorkerHelper.pingWorker(globalThis.worker)),
+ 'PASS',
+ 'SharedWorker should still work after restored from BFCache');
+ }
+ },
+ 'Eligibility: shared workers with another active client in a separate window');