Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a chrome extension that redirects to a particular link automatically?

Hi I want to create a chrome extension so that when the user is on the page example1.com he would automatically be redirected to example2.com even before the page loads. this should work whether or not the user types in the url or goes there through a link.

Please help me in this!

Thanks.

like image 906
user764894 Avatar asked Oct 10 '22 23:10

user764894


1 Answers

In background page:

chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
    if(tab.url.indexOf("http://example1.com") == 0 && changeInfo.status == "loading") {
        chrome.tabs.update(tabId, {url: "http://example2.com"});
    }
});
like image 142
serg Avatar answered Oct 16 '22 14:10

serg