This is my first time ever touching any sort of client sided web programming language, and, I’m attempting to make my first chrome addon. Basically what I want to do is code something which redirects from:-
ABC.com/ID
to
A.ABC.com/ID
So far I have it all coded, however, what it does is it loads ABC.com/ID, waits for it to complete, then injects my content script and re-loads A.ABC.com/ID. This is obviously a huge waste of time. Is there any way I can tell chrome to load this script either before the DNS lookup (Because that’s useless, because it’s on a new subdomain), or, before opening a connection to the site (Because this isn’t the page we’re looking for)? I understand a content script may not be the best idea, if it’s not, then what would be?
Yes, you can achieve with web request API without any content scripts. The following demonstration blocks all
FacebookURL’s and redirects them toGoogle, similarly useABC.com/IDinstead ofFacebookand useA.ABC.com/IDinstead ofGooglefor this use case.References
manifest.jsonEnsure all permissions are available and register background page with extension.
background.jsThis code blocks all URL request to
Facebookand redirects them toGoogle.OutputAll request(s) to
Facebookare redirected toGoogle.