Skip to content

Instantly share code, notes, and snippets.

@gorhill
Created January 23, 2018 17:10
Show Gist options
  • Save gorhill/81e01119f78dac46ead5b8ba0c34bf18 to your computer and use it in GitHub Desktop.
Save gorhill/81e01119f78dac46ead5b8ba0c34bf18 to your computer and use it in GitHub Desktop.
var blockedRequestIds = new Set();
browser.webRequest.onBeforeRequest.addListener(
function(details) {
if ( details.url.includes('favicon') === false ) { return; }
blockedRequestIds.add(details.requestId);
console.log('blocking tabId=' + details.tabId + ' requestId=' + details.requestId + ' url=' + details.url);
return { cancel: true };
},
{ urls: [ '<all_urls>' ] },
[ 'blocking' ]
);
browser.webRequest.onResponseStarted.addListener(
function(details) {
if ( details.url.includes('favicon') === false ) { return; }
if ( blockedRequestIds.has(details.requestId) === false ) {
console.error('onResponseStarted: favicon request not reported to onBeforeRequest: ' + details.requestId);
return;
}
console.error('onResponseStarted: favicon request: ' + details.requestId);
blockedRequestIds.delete(details.requestId);
},
{ urls: [ '<all_urls>' ] }
);
browser.webRequest.onErrorOccurred.addListener(
function(details) {
if ( details.url.includes('favicon') === false ) { return; }
if ( blockedRequestIds.has(details.requestId) === false ) {
console.error('onErrorOccurred: favicon request not reported to onBeforeRequest: ' + details.requestId);
return;
}
console.log('onErrorOccurred: favicon request: ' + details.requestId);
blockedRequestIds.delete(details.requestId);
},
{ urls: [ '<all_urls>' ] }
);
{
"manifest_version": 2,
"name": "umatrix-issue-925",
"version": "1.0",
"background": {
"scripts": ["background.js"]
},
"permissions": [
"webRequest",
"webRequestBlocking",
"<all_urls>"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment