# Redirect to new URL when an error is encountered

**URL:** https://discourse.mozilla.org/t/redirect-to-new-url-when-an-error-is-encountered/16300
**Category:** Development
**Created:** [June 14, 2017, 10:10am UTC](https://discourse.mozilla.org/t/redirect-to-new-url-when-an-error-is-encountered/16300 "2017-06-14T10:10:05Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![user123](https://avatars.discourse-cdn.com/v4/letter/u/ed655f/32.png) [@user123](https://discourse.mozilla.org/u/user123)
#### Post date: [June 14, 2017, 10:10am UTC](https://discourse.mozilla.org/t/redirect-to-new-url-when-an-error-is-encountered/16300/1 "2017-06-14T10:10:05Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![noitidart](https://avatars.discourse-cdn.com/v4/letter/n/9f8e36/32.png) [@noitidart](https://discourse.mozilla.org/u/noitidart)
#### Post date: [June 14, 2017, 5:46pm UTC](https://discourse.mozilla.org/t/redirect-to-new-url-when-an-error-is-encountered/16300/2 "2017-06-14T17:46:44Z")

</div>

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](mailto:dev-addons@mozilla.org) mailing list -

[https://mail.mozilla.org/listinfo/dev-addons](https://mail.mozilla.org/listinfo/dev-addons)

---

<div class="post-metadata">

### Author: ![user123](https://avatars.discourse-cdn.com/v4/letter/u/ed655f/32.png) [@user123](https://discourse.mozilla.org/u/user123)
#### Post date: [June 14, 2017, 7:06pm UTC](https://discourse.mozilla.org/t/redirect-to-new-url-when-an-error-is-encountered/16300/3 "2017-06-14T19:06:14Z")

</div>

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

---

<div class="post-metadata">

### Author: ![noitidart](https://avatars.discourse-cdn.com/v4/letter/n/9f8e36/32.png) [@noitidart](https://discourse.mozilla.org/u/noitidart)
#### Post date: [June 14, 2017, 7:27pm UTC](https://discourse.mozilla.org/t/redirect-to-new-url-when-an-error-is-encountered/16300/4 "2017-06-14T19:27:04Z")

</div>

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

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

> **[tabs](https://developer.mozilla.org/en-US/docs/Archive/Add-ons/Add-on_SDK/High-Level_APIs/tabs)**
>
> Open, manipulate, and access tabs, and receive tab events.

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

---

<div class="post-metadata">

### Author: ![user123](https://avatars.discourse-cdn.com/v4/letter/u/ed655f/32.png) [@user123](https://discourse.mozilla.org/u/user123)
#### Post date: [June 15, 2017, 8:12am UTC](https://discourse.mozilla.org/t/redirect-to-new-url-when-an-error-is-encountered/16300/5 "2017-06-15T08:12:49Z")

</div>

> [@user123](#):
>
> browser.tabs.update

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.
