mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2024-12-22 21:00:23 +01:00
Only use onHeadersReceived listener when necessary
As mentioned in #214
This commit is contained in:
parent
d020c55e11
commit
bde8ac3e8e
@ -41,11 +41,10 @@
|
||||
}
|
||||
|
||||
scope.init = function(){
|
||||
browser.webRequest.onHeadersReceived.addListener(
|
||||
function(details){
|
||||
const cspMatch = (blockBlob? "": "blob: ") + "filesystem: *";
|
||||
function listener(details){console.log("listener");
|
||||
const headers = details.responseHeaders;
|
||||
if (settings.blockDataURLs){
|
||||
const cspMatch = (blockBlob? "": "blob: ") + "filesystem: *";
|
||||
logging.verbose("Adding CSP header to", details);
|
||||
setHeader(headers, {
|
||||
name: "Content-Security-Policy",
|
||||
@ -56,13 +55,33 @@
|
||||
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