Redirect to new URL when an error is encountered

I need to navigate (redirect the URL automatically) to a new page when an error is encountered. I tried this in test.js script:

var target = "<all_urls>"; 
function logError(responseDetails) {
	  errorTab=responseDetails.tabId;
	  console.log("response tab: "+errorTab);
          //direct to the extension's error page
	  browser.tabs.update(errorTab,{url: "data/mypage.html"});
}//end function

browser.webRequest.onErrorOccurred.addListener(
  logError,
  {urls: [target],
  types: ["main_frame"]}
); 

Here is the manifest file:

    {
      "manifest_version": 2,
      "name": "test",
      "version": "1.0",
      "description": "Adds a red border to all webpages matching mozilla.org.",
      "background": {
        "scripts": ["test.js"]
      },
      "permissions": [
    	"<all_urls>",
    	"activeTab",
        "tabs",
        "storage",
    	"webRequest"
      ] 
    }

But, nothing happens when an error is encountered. I need to redirect the error page in such away that the user can not ntoice the redirection and get the extension’s error page directly instead of having two error pages. Is this ever possible?

This looks like it should work.

If it doesn’t work, the folks that implemented this API can be reached n the dev-addons@mozilla.org mailing list -

https://mail.mozilla.org/listinfo/dev-addons

There was something wrong. It worked now :slight_smile:
But, may I ask if you know what is the equivalent for browser.tabs.update in SDK?
That would help in my case.

Awesome. What was the issue? So others can learn from this too.

In SDK for browser.tabs.update you can use the tabs module -

From here you can pin, change url, close, etc tabs.

But does the tab module accept to take the tab id as an argument in its attach method that allows me to attach a script to it? All examples always done on the activTab.

There is no problem with the code above. Probably some fatigue made me confuse and run another code instead.