Reputation: 21851
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 ?
Upvotes: 25
Views: 35814
Reputation: 38147
If you want to access a file inside your WebExtension, you can add the file and its prerequisites to web_accessible_resources
in manifest.json
, as in
{ ... "web_accessible_resources": [ "images/*.png", "style/double-rainbow.css", "script/double-rainbow.js", "script/main.js", "templates/*" ], ... }
Upvotes: 2
Reputation: 111255
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});
});
Upvotes: 45
Reputation: 792
Ive not worked with Google Chrome extensions... but you may be able to use one of these ways.
As I understand, these extension APIs allow you to inject javascript into the page... after that its simple manipulation of window.location ...
Upvotes: -5