Iordanis Iordanis - 4 months ago 13x
Javascript Question

Negating "urls" pattern with onBeforeRequest

chrome.webRequest.onBeforeRequest.addListener(function(details) {
if (localStorage.on == '1') {
return {cancel:true};
}, {urls: ["*://**","*://**","*://**"], types: ["script","xmlhttprequest","other"]}, ["blocking"]);

I don't see any way I can negate the URL pattern. Basically I want to match and block everything except those 3 domains. I thought of returning cancel:true for and the exact content for the 3 domains. First of will that work or will one listener "over-take" the other? How can I return the exact content (So no more cancel:true).


The following example illustrates how to block all requests, except requests to and

       function(details) {
         return {cancel: details.url.indexOf("") == -1 && details.url.indexOf("") == -1};
    {urls: ["<all_urls>"]},

I can't see any way to negate the URL pattern in the documentation