From d658cadf5184b127ec6ae6d6d8900f5e428095b0 Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Fri, 10 Sep 2021 17:46:24 +0200 Subject: disable service workers when scripts are blocked --- content/main.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/content/main.js b/content/main.js index cc7692a..6478ea0 100644 --- a/content/main.js +++ b/content/main.js @@ -304,6 +304,27 @@ http-equiv="Content-Security-Policy" content="${make_csp_rule(policy)}"\ start_data_urls_sanitizing(doc); } +async function disable_service_workers() +{ + if (!navigator.serviceWorker) + return; + + const registrations = await navigator.serviceWorker.getRegistrations(); + if (registrations.length === 0) + return; + + console.warn("Service Workers detected on this page! Unregistering and reloading"); + + try { + await Promise.all(registrations.map(r => r.unregister())); + } finally { + location.reload(); + } + + /* Never actually return! */ + return new Promise(() => 0); +} + if (!is_privileged_url(document.URL)) { let policy_received_callback = () => undefined; let policy; @@ -343,6 +364,7 @@ if (!is_privileged_url(document.URL)) { const doc_ready = Promise.all([ policy.allow ? Promise.resolve() : sanitize_document(document, policy), + policy.allow ? Promise.resolve() : disable_service_workers(), wait_loaded(document) ]); -- cgit v1.2.3