1

I'm working with Microsoft Edge extension.

I would to redirect users if they navigate in a specific url. In my background.js script I have this:

browser.webNavigation.onBeforeNavigate.addListener(
  function(details) {
   if(details.url.indexOf("url_path") > -1){
     alert("caught");
     window.location = "http://new_url.com";
   }
  }    
);

The alert work, but not the redirect. What I'm doing wrong? Also is a good idea pass user e pass for http auth in the redirect? For example: windows.location = "http://user:pass@new_url.com" ?

thanks :)

Robert
  • 33
  • 3

1 Answers1

0

browser.webNavigation.onBeforeNavigate is called in background page, when you call window.location = xxx, the window means the background page window, which is not the current web page, that's why the redirection doesn't work.

To redirect web request, take a look at webRequest.onBeforeRequest. It also provides sample code about how to redirect user navigation.

As for password for http auth in the url, as long as you use https, the entire communication is encrypted.

Community
  • 1
  • 1
Haibara Ai
  • 10,703
  • 2
  • 31
  • 47