> ## Documentation Index
> Fetch the complete documentation index at: https://docs.gravixlayer.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Control the network

> Block or mock requests, and answer HTTP auth challenges

Intercept requests before they leave the browser — block trackers, stub an API, or answer a basic-auth challenge — without a proxy server. Rules are evaluated inside the runtime, so decisions cost zero round-trips, and they are lazily armed: a browser with no rules pays nothing.

CLI and cURL examples use `$RT` and browser `b1` ([Sessions](https://docs.gravixlayer.ai/documentation/agentruntime/browser-use/browser.md)).

## Block or mock requests

`intercept` installs the browser's full rule set — each call replaces the
previous one. Every rule carries a caller-chosen `id`, a `url_pattern` glob
(`*` matches across `/`), an optional `resource_type` filter (`Document`,
`Script`, `XHR`, `Image`, … — empty matches everything), and an `action`:

* `continue` — let the request through (useful to carve exceptions)
* `block` — fail the request in-page
* `mock` — answer it locally with `mock_status`, `mock_headers`, and
  `mock_body_b64` (the response body, base64-encoded)
* `allowlist` — block everything that does not match this rule

Both calls return `{ok: true}` — remove rules later by passing their `id`s to
`intercept_clear`, or omit `rule_ids` to clear every rule on the scope.

```python Python theme={null}
from gravixlayer import GravixLayer

client = GravixLayer()  # reads GRAVIXLAYER_API_KEY
sandbox = client.runtime.create(template="browser-small")
bid = sandbox.browser.open(url="https://example.com")["browser_id"]

import base64

sandbox.browser.intercept(bid, [
    {"id": "no-trackers", "url_pattern": "*/analytics/*", "action": "block"},
    {"id": "quote", "url_pattern": "*/api/quote", "action": "mock",
     "mock_status": 200,
     "mock_headers": {"content-type": "application/json"},
     "mock_body_b64": base64.b64encode(b'{"price": 42}').decode()},
])

sandbox.browser.intercept_clear(bid, rule_ids=["no-trackers"])
sandbox.browser.intercept_clear(bid)  # clears everything
sandbox.kill()
```

```typescript TypeScript theme={null}
import { GravixLayer } from 'gravixlayer';

const client = new GravixLayer();
const sandbox = await client.runtime.create({ template: 'browser-small' });
const bid = (await sandbox.browser.open({ url: 'https://example.com' })).browserId;

await sandbox.browser.intercept(bid, [
  { id: 'no-trackers', url_pattern: '*/analytics/*', action: 'block' },
  {
    id: 'quote',
    url_pattern: '*/api/quote',
    action: 'mock',
    mock_status: 200,
    mock_headers: { 'content-type': 'application/json' },
    mock_body_b64: Buffer.from('{"price": 42}').toString('base64'),
  },
]);

await sandbox.browser.interceptClear(bid, { ruleIds: ['no-trackers'] });
await sandbox.browser.interceptClear(bid); // clears everything
await sandbox.kill();
```

```bash CLI theme={null}
gravixlayer runtime browser intercept "$RT" --browser b1 --rules '[
  {"id":"no-trackers","url_pattern":"*/analytics/*","action":"block"},
  {"id":"quote","url_pattern":"*/api/quote","action":"mock",
   "mock_status":200,"mock_headers":{"content-type":"application/json"},
   "mock_body_b64":"eyJwcmljZSI6IDQyfQ=="}
]'

gravixlayer runtime browser intercept-clear "$RT" --browser b1 --rule-ids no-trackers
gravixlayer runtime browser intercept-clear "$RT" --browser b1   # all rules
```

```bash cURL theme={null}
API="https://api.gravixlayer.ai/v1"

curl -sS -X POST "$API/agents/runtime/$RT/browser/b1/intercept" \
  -H "Authorization: Bearer $GRAVIXLAYER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"rules":[{"id":"no-trackers","url_pattern":"*/analytics/*","action":"block"}]}'

curl -sS -X POST "$API/agents/runtime/$RT/browser/b1/intercept/clear" \
  -H "Authorization: Bearer $GRAVIXLAYER_API_KEY" \
  -H "Content-Type: application/json" -d '{}'
```

## Answer a login wall

Sites behind HTTP basic or digest auth challenge the browser before any page loads. `auth` installs credentials that answer the challenge in the runtime — the page just loads. Prefer `secret_ref` over `password` so the credential travels as a secret-store reference and never enters agent context; pass `clear=True` to drop the credentials again.

```python Python theme={null}
# Credentials live in the secret store — only the reference crosses the wire
sandbox.browser.auth(bid, username="ci-bot", secret_ref="svc_basic_auth")
sandbox.browser.goto("https://intranet.example.com")
sandbox.browser.auth(bid, clear=True)  # drop the credentials
```

```typescript TypeScript theme={null}
await sandbox.browser.auth(bid, { username: 'ci-bot', secretRef: 'svc_basic_auth' });
await sandbox.browser.goto('https://intranet.example.com');
await sandbox.browser.auth(bid, { clear: true }); // drop the credentials
```

```bash CLI theme={null}
gravixlayer runtime browser auth "$RT" --browser b1 \
  --username ci-bot --secret-ref svc_basic_auth
gravixlayer runtime browser auth "$RT" --browser b1 --clear
```

```bash cURL theme={null}
curl -sS -X POST "$API/agents/runtime/$RT/browser/b1/auth" \
  -H "Authorization: Bearer $GRAVIXLAYER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"username":"ci-bot","secret_ref":"svc_basic_auth"}'
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.