From d468b51e6bc4c71376bec29253c36e599df16bbc Mon Sep 17 00:00:00 2001 From: jorg-vr Date: Wed, 6 Dec 2023 16:10:04 +0100 Subject: [PATCH 1/2] Unregister old serviceworkers manualy --- app/assets/javascripts/coding_scratchpad.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/assets/javascripts/coding_scratchpad.ts b/app/assets/javascripts/coding_scratchpad.ts index 3745d28d84..93e3ac9c75 100644 --- a/app/assets/javascripts/coding_scratchpad.ts +++ b/app/assets/javascripts/coding_scratchpad.ts @@ -28,6 +28,15 @@ function initCodingScratchpad(programmingLanguage: ProgrammingLanguage): void { showButton.classList.remove("hidden"); showButton.addEventListener("click", async function () { if (!papyros) { // Only create Papyros once per session, but only when required + // Papyros registers a service worker on a specific path + // We used to do this on a different path + // So we need to unregister old serviceworkers manually as these won't get overwritten + navigator.serviceWorker.getRegistrations().then(function (registrations) { + for (const registration of registrations) { + registration.unregister(); + } + }); + papyros = new Papyros( { programmingLanguage: Papyros.toProgrammingLanguage(programmingLanguage), From cc391d0d752468071ba9cf7bd7a3d04b4c455fd1 Mon Sep 17 00:00:00 2001 From: jorg-vr Date: Wed, 6 Dec 2023 16:25:55 +0100 Subject: [PATCH 2/2] Do not unregister current serviceworker location --- app/assets/javascripts/coding_scratchpad.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/coding_scratchpad.ts b/app/assets/javascripts/coding_scratchpad.ts index 93e3ac9c75..e55720ff10 100644 --- a/app/assets/javascripts/coding_scratchpad.ts +++ b/app/assets/javascripts/coding_scratchpad.ts @@ -33,7 +33,9 @@ function initCodingScratchpad(programmingLanguage: ProgrammingLanguage): void { // So we need to unregister old serviceworkers manually as these won't get overwritten navigator.serviceWorker.getRegistrations().then(function (registrations) { for (const registration of registrations) { - registration.unregister(); + if (registration.scope !== document.location.origin + "/") { + registration.unregister(); + } } });