-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] How can I trigger a service worker update by modifying the HTTP response? #14711
Comments
Intercepting the service-worker.js request is not yet implemented in Playwright. We are almost there, but it needs some final touches. I'll let @rwoll comment on when it becomes available. The rest of your test seems to be ok. You'll reload the page, it'll re-request service worker, then sw will load and your page will be able to detect a new sw. You could also do something like |
@pavelfeldman thank you for the reply! I am a little confused by your links regarding the Thanks for the tip! I will definitely look into integrating service worker update checks into my SPA router navigations. |
Yes, this set of changes does intercept the main request as well! |
Folding into #1090 as per above. |
Re-opening as this may require additional upstream patching (https://crbug.com/1334900, https://crbug.com/1335463). For now the only workaround I know of is running a server out-of-band and intercepting/modifying the SW main script requests there. (You can still route the other requests via context/page.) Since SW main scripts must be same-origin, the page under test would also have to be served/proxied. |
…#14716) Adds Chromium support for Service Worker Networking (interception/routing, Request/Response events, and HAR). Resolves #1090. Depends on #14714 and #14714. Supercedes #14321. Follow up #14711. Landed upstream patches: - https://chromium-review.googlesource.com/c/chromium/src/+/3510917 - https://chromium-review.googlesource.com/c/chromium/src/+/3526571 - https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3566669 - https://chromium-review.googlesource.com/c/chromium/src/+/3544685 - https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3610924 - https://chromium-review.googlesource.com/c/chromium/src/+/3689949
a possible workaround right now could be to use the CDP directly with the ServiceWorker domain const cdp = await context.newCDPSession(page);
await cdp.send('ServiceWorker.enable');
await cdp.send('ServiceWorker.unregister', { scopeURL: 'https://localhost:3000/' }); and then reload the page |
Thanks! I've added tests to cover the update case: #15537. For now, the workaround or using an external server to send the new bites is the recommended approach. |
tl;dr: Today, you'll get the new Service Worker from the update, but Playwright is currently unable to intercept the update request itself. |
Why was this issue closed?Thank you for your involvement. This issue was closed due to limited engagement (upvotes/activity), lack of recent activity, and insufficient actionability. To maintain a manageable database, we prioritize issues based on these factors. If you disagree with this closure, please open a new issue and reference this one. More support or clarity on its necessity may prompt a review. Your understanding and cooperation are appreciated. |
I am working on an SPA that I recently added a service worker to, which pre-caches the application shell using a cache-first strategy and caches navigation requests using a network -first strategy.
The SPA contains some logic that displays a "A new version is available!" banner with a "Reload" button at the top of the page when it detects a "waiting" service worker. I would like to write an end-to-end test for this logic and the logic behind the "Reload" button but cannot figure out how to trigger a service worker update in Playwright.
The approach that I have been playing with is modifying the service worker response after the service worker has been installed and a page reload has been triggered. I can modify the response and its response headers but it is not triggering an update event in the browser.
Here is the test code:
Here is the initial service worker response
Here is the modified service worker response
stackoverflow post
The text was updated successfully, but these errors were encountered: