Is there any way to detect if a certain URL is opened in chrome and redirect to another page. I need it to make a site blocker.
Asked
Active
Viewed 3,767 times
1 Answers
9
Yes, you can it now with Chrome 17.
Add the background page and webRequest permissions to manifest.json:
{
"background_page": "background.html",
"permissions": [
"webRequest", "webRequestBlocking",
"http://www.mozilla.org/*"
]
}
and a redirect 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>
-
Wait... How do I put that in my chrome extension. Does it go in manifest.json or the main html script. Sorry but I know nothing about the Chrome.* API. – Nathan Piercy Feb 17 '12 at 13:00