From 4ce56ba4941163e6160eb6d5fb626b503fdcf911 Mon Sep 17 00:00:00 2001 From: Gion-Andri Cantieni Date: Mon, 4 Dec 2023 09:27:21 +0100 Subject: [PATCH] fix: disable service worker in iframe --- src/app/app.module.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 3c6259e..59ea09d 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -65,6 +65,14 @@ export function jwtOptionsFactory(authService: AuthenticationService) { } } +export function inIframe() { + try { + return window.self !== window.top; + } catch (e) { + return true; + } +} + @NgModule({ declarations: [ AppComponent, @@ -118,7 +126,7 @@ export function jwtOptionsFactory(authService: AuthenticationService) { defaultLanguage: 'rm' }), ServiceWorkerModule.register('ngsw-worker.js', { - enabled: !isDevMode(), + enabled: !isDevMode() && !inIframe(), // Register the ServiceWorker as soon as the application is stable // or after 30 seconds (whichever comes first). registrationStrategy: 'registerWhenStable:30000'