Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@swalkinshaw
Created October 20, 2018 20:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swalkinshaw/cd29b4a774dde2a0fdd14e65d9ca5977 to your computer and use it in GitHub Desktop.
Save swalkinshaw/cd29b4a774dde2a0fdd14e65d9ca5977 to your computer and use it in GitHub Desktop.
const WHITELIST = [
'https://cdn.theathletic.com'
]
const ALLOW = { cancel: false };
const DENY = { cancel: true };
chrome.webRequest.onBeforeSendHeaders.addListener((req) => {
var cancel = null;
if (req.type == 'document') {
return ALLOW;
}
const whitelisted = WHITELIST.find(item => req.url.startsWith(item));
if (whitelisted) {
return ALLOW;
}
req.requestHeaders.forEach((header, i) => {
if (header.name == 'Referer' && header.value.startsWith('https://theathletic.com')) {
cancel = true;
}
});
if (cancel) {
return DENY;
}
},
{ urls: ['<all_urls>'] },
['blocking', 'requestHeaders']
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment