I’d like to write an extension that redirects all web traffic to a specific domain, let’s say wikipedia.org, to an intermediate page that says something like, “Whoa, bub. You’re about to go to Wikipedia. Are you sure about this?” followed by Yes and No buttons.
How do I respond to a specific URL request and replace the desired page with a custom one when it meets the condition of being a page with “wikipedia.org” in the domain?
You can do this using
webRequestfeature, a background page, and custom page with yes and no buttons. For example, write something similar in the background page:This example does not strictly check if wikipedia is mentioned in domain, but I did this for clarity. In my real code a special class ‘URL’ is used which parses passed url and provides properties for every part of it, so they can be checked selectively.
In the
confirmation.htmljust place 2 buttons, and bind them to an appropriate code, for example redirecting to requested site, if a user answered “yes”.Don’t forget to mention “webRequest” and “webRequestBlocking” in
permissionssection of your manifest.