mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-01-08 20:54:49 +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(){
|
scope.init = function(){
|
||||||
browser.webRequest.onHeadersReceived.addListener(
|
function listener(details){console.log("listener");
|
||||||
function(details){
|
|
||||||
const cspMatch = (blockBlob? "": "blob: ") + "filesystem: *";
|
|
||||||
const headers = details.responseHeaders;
|
const headers = details.responseHeaders;
|
||||||
if (settings.blockDataURLs){
|
if (settings.blockDataURLs){
|
||||||
|
const cspMatch = (blockBlob? "": "blob: ") + "filesystem: *";
|
||||||
logging.verbose("Adding CSP header to", details);
|
logging.verbose("Adding CSP header to", details);
|
||||||
setHeader(headers, {
|
setHeader(headers, {
|
||||||
name: "Content-Security-Policy",
|
name: "Content-Security-Policy",
|
||||||
@ -56,13 +55,33 @@
|
|||||||
return {
|
return {
|
||||||
responseHeaders: headers
|
responseHeaders: headers
|
||||||
};
|
};
|
||||||
},
|
}
|
||||||
|
function addListener(){
|
||||||
|
if (!browser.webRequest.onHeadersReceived.hasListener(listener)){
|
||||||
|
browser.webRequest.onHeadersReceived.addListener(
|
||||||
|
listener,
|
||||||
{
|
{
|
||||||
urls: ["<all_urls>"],
|
urls: ["<all_urls>"],
|
||||||
types: ["main_frame", "sub_frame", "object"]
|
types: ["main_frame", "sub_frame", "object"]
|
||||||
},
|
},
|
||||||
["blocking", "responseHeaders"]
|
["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>
|
<iframe id="blobIframe"></iframe>
|
||||||
<h1>Data-URL object</h1>
|
<h1>Data-URL object</h1>
|
||||||
<object
|
<object
|
||||||
type="invalid"
|
type="text/html"
|
||||||
data="data:invalid;base64,<?php
|
data="data:invalid;base64,<?php
|
||||||
echo base64_encode(
|
echo base64_encode(
|
||||||
str_replace(
|
str_replace(
|
||||||
@ -42,7 +42,7 @@
|
|||||||
></object>
|
></object>
|
||||||
<h1>Data-URL embed</h1>
|
<h1>Data-URL embed</h1>
|
||||||
<embed
|
<embed
|
||||||
type="invalid"
|
type="text/html"
|
||||||
src="data:invalid;base64,<?php
|
src="data:invalid;base64,<?php
|
||||||
echo base64_encode(
|
echo base64_encode(
|
||||||
str_replace(
|
str_replace(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user