This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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