How do I redirect to a URL using a Google Chrome Extension & Content Script?

Send redirect url from a content script to a background page:

chrome.runtime.sendMessage({redirect: "http://redirect"});

In a background page update tab’s url which would cause redirect:

chrome.runtime.onMessage.addListener(function(request, sender) {
    chrome.tabs.update(sender.tab.id, {url: request.redirect});
});

Leave a Comment