Reputation: 358
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.
Upvotes: 5
Views: 3835
Reputation: 706
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>
Upvotes: 9