hubcap intercept - Intercept and modify network requests or responses

When to use

Intercept and modify network requests or responses in flight, such as replacing text in response bodies. Use block to simply block URLs without modification. Use --disable to stop interception when finished.

Usage

hubcap intercept [flags]

Arguments

None.

Flags

FlagTypeDefaultDescription
--patternstring"*"URL pattern to match
--responseboolfalseIntercept responses instead of requests
--replacestring""Text replacement as old:new
--disableboolfalseDisable interception

Output

When enabling interception:

FieldTypeDescription
enabledboolWhether interception is active
patternstringURL pattern being matched
responseboolWhether responses are intercepted
replacementstringText replacement rule
{"enabled":true,"pattern":"*","response":false,"replacement":"old:new"}

When disabling interception:

FieldTypeDescription
enabledboolAlways false
{"enabled":false}

Errors

ConditionExit codeStderr
Chrome not connected2error: connecting to Chrome: ...
Invalid pattern1error: invalid pattern "<value>"
Invalid replace format1error: invalid replace format "<value>"

Examples

Intercept all requests matching an API pattern:

hubcap intercept --pattern "*/api/*"

Replace text in response bodies:

hubcap intercept --response --pattern "*.js" --replace "oldFunction:newFunction"

Disable interception:

hubcap intercept --disable

Intercept responses, modify them, then verify the change:

hubcap intercept --response --pattern "*/config.json" --replace "false:true" && hubcap goto "https://example.com" && hubcap eval "fetch('/config.json').then(r => r.json())"

See also

  • block - Block network requests by URL pattern
  • network - Stream network requests and responses
  • responsebody - Get the response body for a captured request