Fired when a web request is about to be made, to give the extension an opportunity to proxy it.

This event is closely modelled on the events defined in the webRequest API. Like those events, its addListener() function takes three arguments:

  • the listener which will be called when the event is fired.
  • a RequestFilter object controlling which requests cause the event to be fired.
  • an array of strings to control other aspects of the event's behavior.

The event is fired before any of the webRequest events for the same request.

When the event is fired, the listener is called with an object containing information about the request. The listener returns a proxy.ProxyInfo object representing a proxy to use (or an array of such objects, enabling the browser to fail over if a proxy is unreachable).

To use proxy.onRequest, an extension must have the "proxy" API permission, and also  the host permission for the URLs of the requests that it intercepts - this means essentially that the match patterns in the filter argument must be a subset of the extension's host permissions.


  listener,             //  function
  filter,               //  object
  extraInfoSpec         //  optional array of strings

Events have three functions:

addListener(listener, filter, extraInfoSpec)
Adds a listener to this event.
Stop listening to this event. The listener argument is the listener to remove.
Check whether listener is registered for this event. Returns true if it is listening, false otherwise.

addListener syntax



Function that will be called when this event occurs. The function will be passed a single argument, which is a proxy.RequestDetails object containing details of the request.

The listener can return any one of:

  • a proxy.ProxyInfo object
  • an array of proxy.ProxyInfo objects
  • a Promise that resolves to a ProxyInfo object
  • a Promise that resolves to an array of ProxyInfo objects.

If the listener returns an array, or a Promise that resolves to an array, then all ProxyInfo objects after the first one represent failovers: if the proxy at position N in the array is not reachable when its ProxyInfo.failoverTimeout expires, then the browser will try the proxy at position N+1.

If there is an error specifying the proxy.ProxyInfo objects, then proxy.onError will be called.

webRequest.RequestFilter. A set of filters that restricts the events that will be sent to this listener.
array of string. Extra options for the event. You can pass a single value, "requestHeaders", to include the request headers in the details object passed to the listener.

Browser compatibility

ChromeEdgeFirefoxFirefox for AndroidOpera
Basic support No No6060 No


This code intercepts requests to <all_urls>, and proxies them if they are not for a top-level frame.

function shouldProxyRequest(requestInfo) {
  return requestInfo.parentFrameId != -1;

function handleProxyRequest(requestInfo) {
  if (shouldProxyRequest(requestInfo)) {
    console.log(`Proxying: ${requestInfo.url}`);
    return {type: "http", host: "", port: 65535};
  return {type: "direct"};

browser.proxy.onRequest.addListener(handleProxyRequest, {urls: ["<all_urls>"]});

Document Tags and Contributors

Contributors to this page: wbamberg
Last updated by: wbamberg,