0

I am writing a very very little extension to append an argument to a specific URL

Here is what I have now in a background script:

chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
        if (tab.url.indexOf("developer.apple.com/reference") != -1 && tab.url.indexOf("?language=objc") == -1) {
            var objcURL = tab.url + "?language=objc";
            chrome.tabs.update(tab.id, {url: objcURL});
        }
});

The issue with this is that it ruins my navigation stack. For example, if a user goes to

https://developer.apple.com/reference/appkit/nsapplication

it will then navigate the user to

https://developer.apple.com/reference/appkit/nsapplication?language=objc

And if they hit back, it will go back to the first link, which then just redirects the user to the second link again. So you can never back out

My question is, is there any way to redirect the user directly to the second link when they make a request for the first link?

A O
  • 5,516
  • 3
  • 33
  • 68
  • Try using the redirect request as specified in this [SO thread](http://stackoverflow.com/questions/4859689/how-do-i-redirect-to-a-url-using-a-google-chrome-extension-content-script). You may also check another way of doing this by using [onBeforeRequest](https://developer.chrome.com/extensions/webRequest#event-onBeforeRequest) from [this thread](http://stackoverflow.com/questions/30922586/chrome-extension-to-check-a-link-and-redirect-to-another-website) – ReyAnthonyRenacia Nov 30 '16 at 12:05
  • the issue with `chrome.tabs.update` is that it adds that extra site to the navigation stack – A O Nov 30 '16 at 15:59

0 Answers0