summaryrefslogtreecommitdiff
path: root/content
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2021-09-10 17:46:24 +0200
committerWojtek Kosior <koszko@koszko.org>2021-09-10 17:46:24 +0200
commitd658cadf5184b127ec6ae6d6d8900f5e428095b0 (patch)
treec96367f01ba62c45b2ce51f46deec32e6c90bf84 /content
parent5c75d7446187a01409eff1a1e5946f66267f61fb (diff)
downloadbrowser-extension-d658cadf5184b127ec6ae6d6d8900f5e428095b0.tar.gz
browser-extension-d658cadf5184b127ec6ae6d6d8900f5e428095b0.zip
disable service workers when scripts are blocked
Diffstat (limited to 'content')
-rw-r--r--content/main.js22
1 files changed, 22 insertions, 0 deletions
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)
]);