W3cubDocs

/Web Extensions

webRequest.StreamFilter.onerror

An event handler that will be called when an error occurs. This is most often because an invalid request ID was passed into webRequest.filterResponseData().

After this event is fired, the webRequest.StreamFilter.error property will contain a message giving more information about the error.

Note that this event is not triggered for network errors.

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
onerror
No
No
57
?
No
No
?
?
57
?
?
?

Examples

This example adds an onerror listener which logs the value of webRequest.StreamFilter.error.

function listener(details) {
  // This example seems not useful because,
  // a extension would use "details.requestId"
  let filter = browser.webRequest.filterResponseData("12345");

  filter.onerror = event => {
    console.log(`Error: ${filter.error}`);
  }
}

browser.webRequest.onBeforeRequest.addListener(
  listener,
  {urls: ["<all_urls>"], types: ["main_frame"]},
  ["blocking"]
);

This example uses no "blocking".

function listener(details) {
  let filter = browser.webRequest.filterResponseData(details.requestId);

  filter.onerror = event => {
    console.log(`Error: ${filter.error}`); // Error: Invalid request ID
  }
}

browser.webRequest.onBeforeRequest.addListener(
  listener,
  {urls: ["<all_urls>"], types: ["main_frame"]}
);

© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/webRequest/StreamFilter/onerror