Skip to main content
The Web Request command (Command Type: 18) hooks into the browser’s web request lifecycle and intercepts HTTP requests at specified stages (before sending headers, on response, on error, etc.).

Command Type

Command Type ID: 18

Parameters

ParameterTypeDescriptionRequired
listenerstringWeb request lifecycle event to listen forYes
namestringUnique identifier for this listenerYes
timeoutnumberTimeout in millisecondsYes
filtersWebRequest.RequestFilterCriteria to filter which requests trigger the listenerNo
optionsWebRequestOptionsAdditional options for request handlingNo

Listener Values

ValueDescription
"onBeforeRequest"Triggered before a request is made
"onBeforeSendHeaders"Triggered before headers are sent
"onSendHeaders"Triggered after headers are sent
"onHeadersReceived"Triggered after headers are received
"onAuthRequired"Triggered when server requires authentication
"onBeforeRedirect"Triggered before a redirect
"onCompleted"Triggered when request completes successfully
"onErrorOccurred"Triggered when an error occurs
"onResponseStarted"Triggered when the response body starts arriving

WebRequest.RequestFilter

FieldTypeDescriptionRequired
urlsArray of stringURL patterns to matchYes
typesArray of stringResource types to matchNo
tabIdnumberMatch specific tabNo
incognitobooleanMatch incognito stateNo

Usage Examples

Capture API Responses

{
  "command": "web-request",
  "params": {
    "listener": "onCompleted",
    "name": "apiListener",
    "timeout": 30000,
    "filters": {
      "urls": ["*://api.example.com/*"],
      "types": ["xmlhttprequest"]
    }
  }
}

Intercept Before Headers Are Sent

{
  "command": "web-request",
  "params": {
    "listener": "onBeforeSendHeaders",
    "name": "headerInterceptor",
    "timeout": 15000,
    "filters": { "urls": ["*://example.com/*"] }
  }
}