Detect if URL is open - Chrome extension

Is there a way to determine if any URL in chrome is open and redirected to another page. I need this to make a site blocker.

+4
source share
1 answer

Yes, now you can with Chrome 17 .

Add the source page and webRequest permissions to manifest.json:

{ "background_page": "background.html", "permissions": [ "webRequest", "webRequestBlocking", "http://www.mozilla.org/*" ] } 

and redirection logic to background.html:

 <html><body> <script> chrome.webRequest.onBeforeRequest.addListener( function(details) { //console.log('before', details); if (details.url == "http://www.mozilla.org/") { return {redirectUrl: "https://www.google.com/chrome/"}; }; }, { urls: ["http://www.mozilla.org/*"], types: ["main_frame"] }, ["blocking"] ); </script> </body></html> 
+8
source

Source: https://habr.com/ru/post/1397015/


All Articles