Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

I'm currently building a Google Chrome extension which tests for certain patterns and if found, redirects them to a new URL.

I've gotten the pattern checking done via a content script, and now I'm not sure how can I proceed with getting the redirect done. Any suggestions ?

like image 232
Sathyajith Bhat Avatar asked Feb 01 '11 06:02

Sathyajith Bhat


People also ask

How do I redirect a Web page to a specific URL?

To redirect from an HTML page, use the META Tag. With this, use the http-equiv attribute to provide an HTTP header for the value of the content attribute. The value of the content is the number of seconds; you want the page to redirect after.

How do I create a redirect URL?

Redirects allow you to forward the visitors of a specific URL to another page of your website. In Site Tools, you can add redirects by going to Domain > Redirects. Choose the desired domain, fill in the URL you want to redirect to another and add the URL of the new page destination. When ready, click Create.


1 Answers

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}); }); 
like image 173
serg Avatar answered Oct 24 '22 18:10

serg