File tree Expand file tree Collapse file tree
src/components/Pwa/ServiceWorker/client
test/e2e/helpers/pageObjectModels Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -52,6 +52,11 @@ declare global {
5252 */
5353 isPlaywrightControlled ?: boolean
5454
55+ /**
56+ * Allows Playwright tests to disable PWA service worker registration
57+ */
58+ __disableServiceWorkerForE2E ?: boolean
59+
5560 /**
5661 * Snapshot of environment-client results for Playwright assertions
5762 */
Original file line number Diff line number Diff line change @@ -9,6 +9,18 @@ export const registerServiceWorker = () => {
99 return
1010 }
1111
12+ const disableForE2E = typeof window !== 'undefined' && window . __disableServiceWorkerForE2E === true
13+ if ( disableForE2E ) {
14+ console . info ( '[pwa] skipping service worker registration for e2e tests' )
15+ void navigator . serviceWorker . getRegistrations ( ) . then ( ( registrations ) => {
16+ registrations . forEach ( ( registration ) => {
17+ console . info ( '[pwa] unregistering service worker (e2e disable)' , { scope : registration . scope } )
18+ void registration . unregister ( )
19+ } )
20+ } )
21+ return
22+ }
23+
1224 const devMode = isDev ( )
1325 const allowDevServiceWorker = devMode && isE2eTest ( )
1426
Original file line number Diff line number Diff line change @@ -36,6 +36,9 @@ export class BasePage {
3636 protected static async setupPlaywrightGlobals ( page : Page ) : Promise < void > {
3737 await page . addInitScript ( ( ) => {
3838 window . isPlaywrightControlled = true
39+ if ( typeof window . __disableServiceWorkerForE2E === 'undefined' ) {
40+ window . __disableServiceWorkerForE2E = true
41+ }
3942
4043 if ( typeof window . __astroPageLoadCounter !== 'number' ) {
4144 window . __astroPageLoadCounter = 0
You can’t perform that action at this time.
0 commit comments