mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2024-12-22 12:50:36 +01:00
Only use onHeadersReceived listener when necessary
As mentioned in #214
This commit is contained in:
parent
d020c55e11
commit
bde8ac3e8e
@ -41,28 +41,47 @@
|
||||
}
|
||||
|
||||
scope.init = function(){
|
||||
browser.webRequest.onHeadersReceived.addListener(
|
||||
function(details){
|
||||
function listener(details){console.log("listener");
|
||||
const headers = details.responseHeaders;
|
||||
if (settings.blockDataURLs){
|
||||
const cspMatch = (blockBlob? "": "blob: ") + "filesystem: *";
|
||||
const headers = details.responseHeaders;
|
||||
if (settings.blockDataURLs){
|
||||
logging.verbose("Adding CSP header to", details);
|
||||
setHeader(headers, {
|
||||
name: "Content-Security-Policy",
|
||||
value: `object-src ${cspMatch}; frame-src ${cspMatch}`
|
||||
// + "; report-to https://canvasblocker.invalid/; report-uri https://canvasblocker.invalid/"
|
||||
});
|
||||
}
|
||||
return {
|
||||
responseHeaders: headers
|
||||
};
|
||||
},
|
||||
{
|
||||
urls: ["<all_urls>"],
|
||||
types: ["main_frame", "sub_frame", "object"]
|
||||
},
|
||||
["blocking", "responseHeaders"]
|
||||
);
|
||||
logging.verbose("Adding CSP header to", details);
|
||||
setHeader(headers, {
|
||||
name: "Content-Security-Policy",
|
||||
value: `object-src ${cspMatch}; frame-src ${cspMatch}`
|
||||
// + "; report-to https://canvasblocker.invalid/; report-uri https://canvasblocker.invalid/"
|
||||
});
|
||||
}
|
||||
return {
|
||||
responseHeaders: headers
|
||||
};
|
||||
}
|
||||
function addListener(){
|
||||
if (!browser.webRequest.onHeadersReceived.hasListener(listener)){
|
||||
browser.webRequest.onHeadersReceived.addListener(
|
||||
listener,
|
||||
{
|
||||
urls: ["<all_urls>"],
|
||||
types: ["main_frame", "sub_frame", "object"]
|
||||
},
|
||||
["blocking", "responseHeaders"]
|
||||
);
|
||||
}
|
||||
}
|
||||
function removeListener(){
|
||||
browser.webRequest.onHeadersReceived.removeListener(listener);
|
||||
}
|
||||
function adjustListener(){
|
||||
if (settings.blockDataURLs){
|
||||
addListener();
|
||||
}
|
||||
else {
|
||||
removeListener();
|
||||
}
|
||||
}
|
||||
|
||||
settings.onloaded(adjustListener);
|
||||
settings.on("blockDataURLs", adjustListener);
|
||||
};
|
||||
|
||||
}());
|
@ -29,7 +29,7 @@
|
||||
<iframe id="blobIframe"></iframe>
|
||||
<h1>Data-URL object</h1>
|
||||
<object
|
||||
type="invalid"
|
||||
type="text/html"
|
||||
data="data:invalid;base64,<?php
|
||||
echo base64_encode(
|
||||
str_replace(
|
||||
@ -42,7 +42,7 @@
|
||||
></object>
|
||||
<h1>Data-URL embed</h1>
|
||||
<embed
|
||||
type="invalid"
|
||||
type="text/html"
|
||||
src="data:invalid;base64,<?php
|
||||
echo base64_encode(
|
||||
str_replace(
|
||||
|
Loading…
x
Reference in New Issue
Block a user