DocsNetwork Interceptionbrowser_add_network_rule

browser_add_network_rule

browser_add_network_rule

Add a rule to intercept network requests matching a URL pattern. Rules can block requests (e.g., ads, trackers), mock responses with custom data (useful for testing), or redirect to different URLs. Supports glob patterns (*.js, *://api.example.com/*) or regex for flexible matching. Returns a rule_id for later removal.

When to use browser_add_network_rule

Use browser_add_network_rule when you need to intercept, block, mock, or monitor network requests. It is part of Owl Browser's Network Interception toolset and runs inside a self-hosted, source-level stealth engine, so every call inherits the same undetectable browser fingerprint as the rest of your automation — no separate anti-detect setup required.

Usage Example

12345678910111213
import asyncio
from owl_browser import OwlBrowser, RemoteConfig
# Async usage
async with OwlBrowser(config) as browser:
context = await browser.create_context()
context_id = context["context_id"]
await browser.add_network_rule(
context_id=context_id,
url_pattern="value",
action="allow"
)

Parameters

Required

context_idstringrequired

The unique identifier of the browser context (e.g., 'ctx_000001')

url_patternstringrequired

URL pattern to match requests against. Supports glob patterns (e.g., '*://api.example.com/*', '*.js') or regex if is_regex=true. Glob uses * for any characters, ? for single character

actionenum
allowblockmockredirect
required

What to do with matching requests: 'allow' lets them through (useful with blocking enabled), 'block' drops the request, 'mock' returns a fake response, 'redirect' sends to different URL

Optional

is_regexboolean

Treat url_pattern as a regular expression instead of glob pattern. Default: false (uses glob). Example regex: '^https://api\\.example\\.com/v[0-9]+/'

redirect_urlstring

The URL to redirect matching requests to. Only used when action='redirect'. Example: redirect tracking scripts to empty response

mock_bodystring

Response body to return for mocked requests. Only used when action='mock'. Can be JSON, HTML, or any text content. Example: '{"success": true}'

mock_statusinteger

HTTP status code for mocked responses (e.g., 200, 404, 500). Only used when action='mock'. Default: 200

mock_content_typestring

Content-Type header for mocked responses. Only used when action='mock'. Examples: 'application/json', 'text/html', 'text/plain'. Default: 'text/plain'

Response

Returns a JSON object with the operation result.

{
  "success": true,
  "result": <value>
}

Frequently Asked Questions

What does browser_add_network_rule do?

Add a rule to intercept network requests matching a URL pattern. Rules can block requests (e.g., ads, trackers), mock responses with custom data (useful for testing), or redirect to different URLs. Supports glob patterns (*.js, *://api.example.com/*) or regex for flexible matching. Returns a rule_id for later removal. It belongs to Owl Browser's Network Interception category and is available through the REST API, the Python SDK (browser.add_network_rule()), the Node.js SDK, and the MCP server.

What parameters does browser_add_network_rule accept?

browser_add_network_rule accepts 3 required parameters (context_id, url_pattern, action) and 5 optional parameters. All parameters are sent as JSON in a POST request to /api/execute/browser_add_network_rule.

Is browser_add_network_rule detectable by anti-bot systems like Cloudflare or DataDome?

No. browser_add_network_rule executes inside Owl Browser's Chromium engine, which applies fingerprint spoofing at the C++ source level rather than through JavaScript patches. Every tool call shares the same consistent, human-like fingerprint, so anti-bot systems such as Cloudflare, DataDome, and Akamai see an ordinary browser.

Related Tools

Browse the full Owl Browser API reference or get started with the Python SDK and Node.js SDK.