Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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