google chrome extension - Event handler when site doesn't match manifest.json 'matches' -


my manifest.json contains block:

"content_scripts": [     {         "all_frames": true,         "matches": [             "*://www.google.com/*",             "*://www.cnn.com/*",             "*://*.foxnews.com/*"         ],         "js": ["js/main.js"]         }     ], 

i need event fire (either in content js or background.js, doesn't matter) whenever user visits website not match 1 of sites in matches setting.

how done?

in background.js add listener tab load. in fetch url of current tab , match list.

chrome.tabs.onupdated.addlistener(function(tabid, info, tab) {     if (info.status == "complete") {         var url = tab.url.replace(/.*?:\/\//g, "").replace(/\/$/, ""); //removes protocol          var allowedurls = ["www.google.com", "www.cnn.com", "foxnews.com"];          for(var in allowedurls) {             if(allowedurls[i].indexof(url) == -1) {                 //url not match                  break;             }         }     } }); 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -