I\'m making a very simple Chrome extension to block requests to some domains (got tired of slow page loads on many websites, waiting on facebook junk). My question is about how
Use something like this:
function blockRequest(details) {
return {cancel: true};
}
function updateFilters(urls) {
if(chrome.webRequest.onBeforeRequest.hasListener(blockRequest))
chrome.webRequest.onBeforeRequest.removeListener(blockRequest);
chrome.webRequest.onBeforeRequest.addListener(blockRequest, {urls: urls}, ['blocking']);
}
You can provide an options page to let the user to specify domains to block (and preferably save them with chrome.storage API). In your background page, update filters by re-registering the listener when it is initialized or the setting is changed.
By the way, you should use the Declarative Web Request API when it is stable since it is much more efficient and doesn't require a persistent background page.