Skip to content

Commit b5c7e97

Browse files
committed
Handle exception when accessing navigator.serviceWorker on sandboxed frames.
1 parent 6493544 commit b5c7e97

2 files changed

Lines changed: 46 additions & 7 deletions

File tree

src/content/content.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,16 @@ ns.on("capabilities", () => {
198198
}
199199

200200
if (!ns.canScript) {
201-
202-
if ("serviceWorker" in navigator && navigator.serviceWorker.controller) {
203-
(async () => {
204-
for (let r of await navigator.serviceWorker.getRegistrations()) {
205-
await r.unregister();
206-
}
207-
})();
201+
try {
202+
if ("serviceWorker" in navigator && navigator.serviceWorker.controller) {
203+
(async () => {
204+
for (let r of await navigator.serviceWorker.getRegistrations()) {
205+
await r.unregister();
206+
}
207+
})();
208+
}
209+
} catch (e) {
210+
debug(e);
208211
}
209212
onScriptDisabled();
210213
}

src/content/experiments.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* NoScript - a Firefox extension for whitelist driven safe JavaScript execution
3+
*
4+
* Copyright (C) 2005-2021 Giorgio Maone <https://maone.net>
5+
*
6+
* SPDX-License-Identifier: GPL-3.0-or-later
7+
*
8+
* This program is free software: you can redistribute it and/or modify it under
9+
* the terms of the GNU General Public License as published by the Free Software
10+
* Foundation, either version 3 of the License, or (at your option) any later
11+
* version.
12+
*
13+
* This program is distributed in the hope that it will be useful, but WITHOUT
14+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15+
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License along with
18+
* this program. If not, see <https://www.gnu.org/licenses/>.
19+
*/
20+
21+
function testBlob() {
22+
if ((location.origin === "https://noscript.net" || location.origin === "null" || location.href.startsWith("data:")) && top !== window ) {
23+
if (!testBlob.log) testBlob.log = "";
24+
testBlob.log += `${document.readyState} - ${document.URL} - Policy: ${JSON.stringify(ns.policy)}<br>`;
25+
if (document.body) {
26+
document.body.style.backgroundColor = "yellow";
27+
let log = document.body.appendChild(document.createElement("div"));
28+
log.textContent = testBlob.log;
29+
testBlog.log = "";
30+
}
31+
}
32+
}
33+
testBlob();
34+
addEventListener("DOMContentLoaded", testBlob);
35+
36+
patchWorkers(() => { self.patched = true; console.log("NoScript-patched worker", self, location) }); // DEV_ONLY

0 commit comments

Comments
 (0)