summaryrefslogtreecommitdiff
path: root/src/bg
diff options
context:
space:
mode:
authorhackademix2018-07-24 23:21:01 +0200
committerhackademix2018-07-24 23:21:01 +0200
commit8d6f96302292dbfdccf88966013ce8d67d64f475 (patch)
tree86f10a429213e39d386a52bd438738a4161d4455 /src/bg
parentec79210bd195d3b47804893509f2287798502b69 (diff)
downloadnoscript-8d6f96302292dbfdccf88966013ce8d67d64f475.tar.gz
noscript-8d6f96302292dbfdccf88966013ce8d67d64f475.tar.xz
noscript-8d6f96302292dbfdccf88966013ce8d67d64f475.zip
Work-around for serviceWorker loads bypassing webRequest.
Diffstat (limited to 'src/bg')
-rw-r--r--src/bg/RequestGuard.js21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/bg/RequestGuard.js b/src/bg/RequestGuard.js
index 6f507fe..8191f3e 100644
--- a/src/bg/RequestGuard.js
+++ b/src/bg/RequestGuard.js
@@ -72,6 +72,7 @@ var RequestGuard = (() => {
},
initTab(tabId, records = this.newRecords()) {
+ if (tabId < 0) return;
this.map.set(tabId, records);
return records;
},
@@ -109,6 +110,8 @@ var RequestGuard = (() => {
},
record(request, what, optValue) {
+ let {tabId} = request;
+ if (tabId < 0) return;
let records = this._record(request, what, optValue);
if (records) {
this.updateTab(request.tabId);
@@ -118,6 +121,7 @@ var RequestGuard = (() => {
_pendingTabs: new Set(),
updateTab(tabId) {
+ if (tabId < 0) return;
if (this._pendingTabs.size === 0) {
window.setTimeout(() => { // clamp UI updates
for (let tabId of this._pendingTabs) {
@@ -217,7 +221,7 @@ var RequestGuard = (() => {
case "pageshow":
TabStatus.recordAll(sender.tab.id, message.seen);
return true;
- case "enable":
+ case "enable": {
let {url, documentUrl, policyType} = message;
let TAG = `<${policyType.toUpperCase()}>`;
let origin = Sites.origin(url);
@@ -258,10 +262,17 @@ var RequestGuard = (() => {
ns.savePolicy();
}
return true;
- case "canScript":
- let records = TabStatus.map.get(sender.tab.id);
- debug("Records.noscriptFrames %o, canScript: %s", records && records.noscriptFrames, !(records && records.noscriptFrames[sender.frameId]));
- return !(records && records.noscriptFrames[sender.frameId]);
+ }
+ case "canScript": {
+ let {frameId, url, tab} = sender;
+ let tabId = tab.id;
+ let records = TabStatus.map.get(tabId);
+ let noscriptFrames = records && records.noscriptFrames;
+ let canScript = !(noscriptFrames && noscriptFrames[sender.frameId]);
+ let shouldScript = ns.isEnforced(tabId) && ns.policy.can(url, "script");
+ debug("Frame %s %s of %o, canScript: %s, shouldScript: %s", frameId, url, noscriptFrames, canScript, shouldScript);
+ return {canScript, shouldScript};
+ }
}
},