# Scrapfly Documentation

## Table of Contents

### Dashboard

- [Intro](https://scrapfly.io/docs)
- [Project](https://scrapfly.io/docs/project)
- [Account](https://scrapfly.io/docs/account)
- [Workspace & Team](https://scrapfly.io/docs/workspace-and-team)
- [Billing](https://scrapfly.io/docs/billing)

### Products

#### MCP Server

- [Getting Started](https://scrapfly.io/docs/mcp/getting-started)
- [Tools & API Spec](https://scrapfly.io/docs/mcp/tools)
- [Authentication](https://scrapfly.io/docs/mcp/authentication)
- [Examples & Use Cases](https://scrapfly.io/docs/mcp/examples)
- [FAQ](https://scrapfly.io/docs/mcp/faq)
##### Integrations

- [Overview](https://scrapfly.io/docs/mcp/integrations)
- [Claude Desktop](https://scrapfly.io/docs/mcp/integrations/claude-desktop)
- [Claude Code](https://scrapfly.io/docs/mcp/integrations/claude-code)
- [Codex](https://scrapfly.io/docs/mcp/integrations/codex)
- [Gemini CLI](https://scrapfly.io/docs/mcp/integrations/gemini-cli)
- [Antigravity](https://scrapfly.io/docs/mcp/integrations/antigravity)
- [OpenCode](https://scrapfly.io/docs/mcp/integrations/opencode)
- [ChatGPT](https://scrapfly.io/docs/mcp/integrations/chatgpt)
- [Cursor](https://scrapfly.io/docs/mcp/integrations/cursor)
- [Cline](https://scrapfly.io/docs/mcp/integrations/cline)
- [Windsurf](https://scrapfly.io/docs/mcp/integrations/windsurf)
- [Zed](https://scrapfly.io/docs/mcp/integrations/zed)
- [Roo Code](https://scrapfly.io/docs/mcp/integrations/roo-code)
- [VS Code](https://scrapfly.io/docs/mcp/integrations/vscode)
- [LangChain](https://scrapfly.io/docs/mcp/integrations/langchain)
- [LlamaIndex](https://scrapfly.io/docs/mcp/integrations/llamaindex)
- [CrewAI](https://scrapfly.io/docs/mcp/integrations/crewai)
- [OpenAI](https://scrapfly.io/docs/mcp/integrations/openai)
- [n8n](https://scrapfly.io/docs/mcp/integrations/n8n)
- [Make](https://scrapfly.io/docs/mcp/integrations/make)
- [Zapier](https://scrapfly.io/docs/mcp/integrations/zapier)
- [Vapi AI](https://scrapfly.io/docs/mcp/integrations/vapi)
- [Agent Builder](https://scrapfly.io/docs/mcp/integrations/agent-builder)
- [Custom Client](https://scrapfly.io/docs/mcp/integrations/custom-client)


#### Web Scraping API

- [Getting Started](https://scrapfly.io/docs/scrape-api/getting-started)
- [API Specification]()
- [Monitoring](https://scrapfly.io/docs/monitoring)
- [Customize Request](https://scrapfly.io/docs/scrape-api/custom)
- [Debug](https://scrapfly.io/docs/scrape-api/debug)
- [Unblocker (formerly ASP)](https://scrapfly.io/docs/scrape-api/unblocker)
- [Proxy](https://scrapfly.io/docs/scrape-api/proxy)
- [Proxy Mode](https://scrapfly.io/docs/scrape-api/proxy-mode)
- [Proxy Mode - Screaming Frog](https://scrapfly.io/docs/scrape-api/proxy-mode/screaming-frog)
- [Proxy Mode - Apify](https://scrapfly.io/docs/scrape-api/proxy-mode/apify)
- [(Auto) Data Extraction](https://scrapfly.io/docs/scrape-api/extraction)
- [Javascript Rendering](https://scrapfly.io/docs/scrape-api/javascript-rendering)
- [Javascript Scenario](https://scrapfly.io/docs/scrape-api/javascript-scenario)
- [SSL](https://scrapfly.io/docs/scrape-api/ssl)
- [DNS](https://scrapfly.io/docs/scrape-api/dns)
- [Cache](https://scrapfly.io/docs/scrape-api/cache)
- [Batch (Multi-URL Scraping)](https://scrapfly.io/docs/scrape-api/batch)
- [Session](https://scrapfly.io/docs/scrape-api/session)
- [Webhook](https://scrapfly.io/docs/scrape-api/webhook)
- [Schedule](https://scrapfly.io/docs/scrape-api/schedule)
- [Screenshot](https://scrapfly.io/docs/scrape-api/screenshot)
- [Errors](https://scrapfly.io/docs/scrape-api/errors)
- [Timeout](https://scrapfly.io/docs/scrape-api/understand-timeout)
- [Throttling](https://scrapfly.io/docs/throttling)
- [Troubleshoot](https://scrapfly.io/docs/scrape-api/troubleshoot)
- [Billing](https://scrapfly.io/docs/scrape-api/billing)
- [FAQ](https://scrapfly.io/docs/scrape-api/faq)

#### Crawler API

- [Getting Started](https://scrapfly.io/docs/crawler-api/getting-started)
- [API Specification]()
- [Retrieving Results](https://scrapfly.io/docs/crawler-api/results)
- [WARC Format](https://scrapfly.io/docs/crawler-api/warc-format)
- [Data Extraction](https://scrapfly.io/docs/crawler-api/extraction-rules)
- [Search](https://scrapfly.io/docs/crawler-api/search)
- [Prompt & Extract](https://scrapfly.io/docs/crawler-api/prompt)
- [Auto Refresh](https://scrapfly.io/docs/crawler-api/refresh)
- [Webhook](https://scrapfly.io/docs/crawler-api/webhook)
- [Schedule](https://scrapfly.io/docs/crawler-api/schedule)
- [Billing](https://scrapfly.io/docs/crawler-api/billing)
- [Errors](https://scrapfly.io/docs/crawler-api/errors)
- [Troubleshoot](https://scrapfly.io/docs/crawler-api/troubleshoot)
- [FAQ](https://scrapfly.io/docs/crawler-api/faq)

#### Screenshot API

- [Getting Started](https://scrapfly.io/docs/screenshot-api/getting-started)
- [API Specification]()
- [Accessibility Testing](https://scrapfly.io/docs/screenshot-api/accessibility)
- [Webhook](https://scrapfly.io/docs/screenshot-api/webhook)
- [Schedule](https://scrapfly.io/docs/screenshot-api/schedule)
- [Billing](https://scrapfly.io/docs/screenshot-api/billing)
- [Errors](https://scrapfly.io/docs/screenshot-api/errors)

#### Extraction API

- [Getting Started](https://scrapfly.io/docs/extraction-api/getting-started)
- [API Specification]()
- [Rules Template](https://scrapfly.io/docs/extraction-api/rules-and-template)
- [LLM Extraction](https://scrapfly.io/docs/extraction-api/llm-prompt)
- [AI Auto Extraction](https://scrapfly.io/docs/extraction-api/automatic-ai)
- [Webhook](https://scrapfly.io/docs/extraction-api/webhook)
- [Billing](https://scrapfly.io/docs/extraction-api/billing)
- [Errors](https://scrapfly.io/docs/extraction-api/errors)
- [FAQ](https://scrapfly.io/docs/extraction-api/faq)

#### Data API


#### Proxy Saver

- [Getting Started](https://scrapfly.io/docs/proxy-saver/getting-started)
- [Fingerprints](https://scrapfly.io/docs/proxy-saver/fingerprints)
- [Optimizations](https://scrapfly.io/docs/proxy-saver/optimizations)
- [SSL Certificates](https://scrapfly.io/docs/proxy-saver/certificates)
- [Protocols](https://scrapfly.io/docs/proxy-saver/protocols)
- [Pacfile](https://scrapfly.io/docs/proxy-saver/pacfile)
- [Secure Credentials](https://scrapfly.io/docs/proxy-saver/security)
- [Billing](https://scrapfly.io/docs/proxy-saver/billing)

#### Cloud Browser API

- [Getting Started](https://scrapfly.io/docs/cloud-browser-api/getting-started)
- [Proxy & Geo-Targeting](https://scrapfly.io/docs/cloud-browser-api/proxy)
- [Unblock API](https://scrapfly.io/docs/cloud-browser-api/unblock)
- [Captcha Solver](https://scrapfly.io/docs/cloud-browser-api/captcha-solver)
- [Network Policy](https://scrapfly.io/docs/cloud-browser-api/network-policy)
- [File Downloads](https://scrapfly.io/docs/cloud-browser-api/file-downloads)
- [Session Resume](https://scrapfly.io/docs/cloud-browser-api/session-resume)
- [Human-in-the-Loop](https://scrapfly.io/docs/cloud-browser-api/human-in-the-loop)
- [Debug Mode](https://scrapfly.io/docs/cloud-browser-api/debug-mode)
- [Browser Extensions](https://scrapfly.io/docs/cloud-browser-api/extensions)
- [Credential Vault](https://scrapfly.io/docs/cloud-browser-api/credential-vault)
- [Native Browser MCP](https://scrapfly.io/docs/cloud-browser-api/mcp)
- [DevTools Protocol](https://scrapfly.io/docs/cloud-browser-api/cdp-reference)
##### Integrations

- [Puppeteer](https://scrapfly.io/docs/cloud-browser-api/puppeteer)
- [Playwright](https://scrapfly.io/docs/cloud-browser-api/playwright)
- [Selenium](https://scrapfly.io/docs/cloud-browser-api/selenium)
- [Vercel Agent Browser](https://scrapfly.io/docs/cloud-browser-api/agent-browser)
- [Browser Use](https://scrapfly.io/docs/cloud-browser-api/browser-use)
- [Stagehand](https://scrapfly.io/docs/cloud-browser-api/stagehand)
- [1Password](https://scrapfly.io/docs/cloud-browser-api/1password)

- [Billing](https://scrapfly.io/docs/cloud-browser-api/billing)
- [Errors](https://scrapfly.io/docs/cloud-browser-api/errors)


### Tools

- [Antibot Detector](https://scrapfly.io/docs/tools/antibot-detector)

### SDK

- [Golang](https://scrapfly.io/docs/sdk/golang)
- [PHP](https://scrapfly.io/docs/sdk/php)
- [Python](https://scrapfly.io/docs/sdk/python)
- [Rust](https://scrapfly.io/docs/sdk/rust)
- [TypeScript](https://scrapfly.io/docs/sdk/typescript)
- [Scrapy](https://scrapfly.io/docs/sdk/scrapy)

### Integrations

- [Getting Started](https://scrapfly.io/docs/integration/getting-started)
- [LangChain](https://scrapfly.io/docs/integration/langchain)
- [LlamaIndex](https://scrapfly.io/docs/integration/llamaindex)
- [CrewAI](https://scrapfly.io/docs/integration/crewai)
- [Zapier](https://scrapfly.io/docs/integration/zapier)
- [Make](https://scrapfly.io/docs/integration/make)
- [n8n](https://scrapfly.io/docs/integration/n8n)

### Academy

- [Overview](https://scrapfly.io/academy)
- [Web Scraping Overview](https://scrapfly.io/academy/scraping-overview)
- [Tools](https://scrapfly.io/academy/tools-overview)
- [Reverse Engineering](https://scrapfly.io/academy/reverse-engineering)
- [Static Scraping](https://scrapfly.io/academy/static-scraping)
- [HTML Parsing](https://scrapfly.io/academy/html-parsing)
- [Dynamic Scraping](https://scrapfly.io/academy/dynamic-scraping)
- [Hidden API Scraping](https://scrapfly.io/academy/hidden-api-scraping)
- [Headless Browsers](https://scrapfly.io/academy/headless-browsers)
- [Hidden Web Data](https://scrapfly.io/academy/hidden-web-data)
- [JSON Parsing](https://scrapfly.io/academy/json-parsing)
- [Data Processing](https://scrapfly.io/academy/data-processing)
- [Scaling](https://scrapfly.io/academy/scaling)
- [Walkthrough Summary](https://scrapfly.io/academy/walkthrough-summary)
- [Scraper Blocking](https://scrapfly.io/academy/scraper-blocking)
- [Proxies](https://scrapfly.io/academy/proxies)

---

# Network Policy

1. [Cloud Browser](https://scrapfly.io/docs/cloud-browser-api/getting-started)
2. Network Policy

 A network policy decides which hosts your traffic may reach. Set one on a [project](#project-policy) and every product of the project follows it, or pass one to a single Cloud Browser session with the [`network_policy`](#parameter) parameter.

## Policy format

List domains or IP addresses under `allow` or `block`.

```
{"block": ["httpbin.dev"]}
```

 With only block rules, unmatched hosts stay reachable. Adding any allow rule blocks unmatched hosts. Empty lists add no restrictions. Scrapfly’s other resource blocking settings still apply.

## Entries

An entry is one of:

- **A domain**, `web-scraping.dev`. It covers that host and every host under it: `api.web-scraping.dev`, `a.b.web-scraping.dev`. `*.web-scraping.dev` is read as `web-scraping.dev`.
- **An IP address**, IPv4 or IPv6 without brackets. It covers that address and nothing else.

 Write a domain in lower case letters, digits, `-` and `_`, labels of 1 to 63 characters, 253 characters at most. Write an internationalized name in its `xn--` form. An entry has no scheme, port, path or query: `https://web-scraping.dev/products` and `web-scraping.dev:443` are refused. A policy holds at most 1,000 entries in `allow` and `block` together, and the same entry cannot be in both lists.

 Scrapfly stores entries trimmed, in lower case, without a trailing dot, with an IPv6 address in its short form and duplicates removed.

## How a host is decided

### Allow list: only the hosts you list load

 List every host the page needs, including its APIs and CDNs. Requests to unlisted hosts lose those resources.

```
{"allow": ["web-scraping.dev"]}
```

| Host | Result |
|---|---|
| `www.web-scraping.dev` | Allowed, `web-scraping.dev` covers it. |
| `httpbin.dev` | Refused, outside the allow list. |

 A page on `web-scraping.dev` that loads data from `httpbin.dev` needs both hosts in the list. The entry `httpbin.dev` also covers `api.httpbin.dev`:

```
{"allow": ["web-scraping.dev", "httpbin.dev"]}
```

 A `block` entry beside an allow list only carves out a subdomain of an allowed domain. With `{"allow": ["web-scraping.dev"], "block": ["ads.web-scraping.dev"]}`, `www.web-scraping.dev` loads and `ads.web-scraping.dev` is refused, because the longer entry decides.

### Block list: everything loads except the hosts you list

 List the domains or IPs to block. Other hosts stay reachable.

```
{"block": ["ads.web-scraping.dev", "tracker.httpbin.dev"]}
```

| Host | Result |
|---|---|
| `www.web-scraping.dev` | Allowed, outside the block list. |
| `img.ads.web-scraping.dev` | Refused, `ads.web-scraping.dev` covers it. |
| `tracker.httpbin.dev` | Refused, `tracker.httpbin.dev` is in the list. |
| `httpbin.dev` | Allowed, the entry covers `tracker.httpbin.dev` and its subdomains, not the domain above it. |

### The exception: both lists

 Allow a subdomain under a blocked parent domain.

```
{"block": ["web-scraping.dev"], "allow": ["cdn.web-scraping.dev"]}
```

 This policy refuses `www.web-scraping.dev`, allows `img.cdn.web-scraping.dev` under the more specific rule, and refuses `httpbin.dev` because it is outside the allow list.

### The most specific entry decides

 Among the entries of both lists that cover a host, **the longest one decides**. An `allow` entry allows the host and a `block` entry refuses it. A URL with no host (`data:`, `about:blank`) is never refused.

## Use it in a session

 Add the policy to the WebSocket URL as the `network_policy` query parameter, URL-encoded JSON. It is optional, and it only applies to the session it is on. A session policy travels in the connection URL: keep it to a few dozen entries and put a longer list on the [project policy](#project-policy).

 A session keeps every policy it was given and none is ever dropped. A reconnect to a [resumable session](https://scrapfly.io/docs/cloud-browser-api/session-resume) that sends a `network_policy` adds it to the session's policies: the session is narrowed, never widened, and a reconnect without one keeps the policies it has. A client that joins with `share_cdp=true` shares them: one that passes a `network_policy` the session does not already hold is refused. A client that joins with `share_cdp=true` is refused too while the project's policy has changed since the session began, `network_policy` or not: the client that opened the session reconnects without `share_cdp=true` first, which applies the change, then the join goes through.

| Parameter | Required | Description |
|---|---|---|
| `network_policy` | No | The [policy](#policy) of the session as URL-encoded JSON, a few dozen entries at most: a longer list belongs to the project policy. A value that is not a policy is refused with [`ERR::BROWSER::INVALID_NETWORK_POLICY`](https://scrapfly.io/docs/cloud-browser-api/error/ERR::BROWSER::INVALID_NETWORK_POLICY), and its message names the entry. |

```
from scrapfly import BrowserConfig, NetworkPolicy, ScrapflyClient
from playwright.sync_api import sync_playwright

client = ScrapflyClient(key="")
config = BrowserConfig(network_policy=NetworkPolicy.block("httpbin.dev"))

with sync_playwright() as p:
    browser = p.chromium.connect_over_cdp(client.cloud_browser(config))
    page = browser.contexts[0].new_page()
    page.goto("https://web-scraping.dev/products")
    print(page.title())
    browser.close()
```

```
import puppeteer from "puppeteer-core";

// Only web-scraping.dev and its subdomains are reachable in this session.
const policy = { allow: ["web-scraping.dev"] };
const query = new URLSearchParams({ api_key: "", network_policy: JSON.stringify(policy) });

const browser = await puppeteer.connect({ browserWSEndpoint: "wss://browser.scrapfly.io?" + query, defaultViewport: null });
const page = await browser.newPage();
await page.goto("https://web-scraping.dev/products");
console.log(await page.title());
await browser.close();
```

 The [Cloud Browser API player](https://scrapfly.io/dashboard/playground/cloud-browser) has a **Network Policy** section that builds this parameter from rules, with no JSON to write. It shows the policy of your project beside it, can start from the rules of the project, and adds the parameter to the connection URL and to the code it generates. It refuses a policy of more than 100 rules, or longer than 8,192 bytes as JSON, before it opens a session.

## Project policy

 A project policy applies to **every product of the project**: Web Scraping API, Screenshot API, Crawler API, Cloud Browser and Proxy Saver. Open [Projects](https://scrapfly.io/dashboard/project), then **Edit Settings → Compliance → Network policies**. Choose Allow or Block for each host and click **Save policy**. Use **Copy** to start from another project's rules. Only the owner of the account and team members with the Manager or Admin role can change the project policy.

 A change takes up to a minute to apply. Proxy Saver applies it within three minutes to new connections and plain HTTP requests; a connection already open (an HTTPS tunnel, a SOCKS5 connection, a websocket) keeps the policy it was opened with until it closes. A Cloud Browser session keeps every policy it was given: a project policy changed later reaches new sessions, and a reconnect with a network\_policy only narrows it. A crawl judges its links by the policy it was created with, and each page it fetches by the project's policy at that moment. The project policy is the same JSON object as the `network_policy` parameter.

### A session's policy only narrows the project's

 A request must pass the policy of the project *and* the policy of the session: it is refused when either one refuses its host. A session can restrict itself further, never reach what the project refuses. If the project allows only `web-scraping.dev`, a session with `{"allow": ["web-scraping.dev"]}` reaches `web-scraping.dev`, and a session with `{"allow": ["web-scraping.dev", "httpbin.dev"]}` still reaches `web-scraping.dev` only: `httpbin.dev` is refused by the project.

## What a refused host looks like

- A Cloud Browser session whose `target_url` is on a refused host does not start: [`ERR::BROWSER::NETWORK_POLICY_BLOCKED`](https://scrapfly.io/docs/cloud-browser-api/error/ERR::BROWSER::NETWORK_POLICY_BLOCKED).
- `Page.navigate` and `Target.createTarget` to a refused host fail with an error your client reports as a failed navigation.
- In a browser (a Cloud Browser session, a Web Scraping API render, a screenshot), every request the page makes to a refused host fails with `net::ERR_BLOCKED_BY_ADMINISTRATOR`: documents, frames, subresources, each redirect hop, WebSocket connections, and loads the browser would serve from its HTTP cache. Chrome's own background requests (updates, safe browsing) are not the page's and are not ruled.
- The Web Scraping API and the Screenshot API answer [`ERR::SCRAPE::NETWORK_POLICY_BLOCKED`](https://scrapfly.io/docs/scrape-api/error/ERR::SCRAPE::NETWORK_POLICY_BLOCKED) when the URL, or a redirect of an HTTP scrape, reaches a refused host. The Crawler API answers [`ERR::CRAWLER::NETWORK_POLICY_BLOCKED`](https://scrapfly.io/docs/crawler-api/error/ERR::CRAWLER::NETWORK_POLICY_BLOCKED) when its seed URL, its `remote_url_list`, or every URL of its `url_list` is on a refused host, and does not follow a link to one. A URL of the `url_list` on a refused host is skipped while others remain: the crawl report shows it as `skipped` with the reason `input_list:network_policy_blocked` ([URL sources](https://scrapfly.io/docs/crawler-api/url-sources)).
- Proxy Saver refuses a connection to a refused host with `403` [`ERR_PROXY_NETWORK_POLICY_BLOCKED`](https://scrapfly.io/docs/proxy-saver/getting-started#errors) ([Proxy Saver connect errors](https://scrapfly.io/docs/proxy-saver/getting-started#errors)).

These errors are not retryable and not billed.

 Request interception in your own client (Playwright's `page.route`, Puppeteer's `setRequestInterception`) works in a session held to a policy: a request your script rewrites is judged by the policy where the browser sends it.

 Refusing the requests a page makes, inside the browser, needs the next Cloud Browser release. Until it is released, a session is held to the policy for its `target_url` and for the navigations your client starts, not for the other requests of a page.

### An allow list must name every host the page needs

 Under an allow list, a host you do not list is refused even when the page needs it: its CDN, the API its scripts call, the hosts a consent banner or a payment form loads, and the hosts an anti-bot challenge loads. With the Unblocker (`asp`), a challenge whose hosts are refused cannot be passed, and the scrape fails. Start from the hosts the page loads (the network tab of your browser's developer tools lists them) and add them to `allow`.

 A policy only refuses. A host it allows still goes through Scrapfly's own resource blocking (ads and trackers): an `allow` entry does not load what that blocking leaves out.

### What a policy does not cover

- It rules hosts, not paths: `web-scraping.dev/products` is not an entry.
- WebRTC and WebTransport connections of a page are not ruled: they are not URL requests.
- A response a service worker answers from its own cache is not ruled: it makes no network request.
- A policy does not turn the cache off: with `cache=true`, a Cloud Browser session is served from cache for the hosts its policy allows, billed at the [cached bandwidth rate](https://scrapfly.io/docs/cloud-browser-api/billing). A resource of a host the policy refuses is never served from cache: the browser refuses it, and nothing is billed. The Web Scraping API's result cache (`cache=true` of a scrape) is not affected.

## Errors

| Code | When |
|---|---|
| [`ERR::BROWSER::INVALID_NETWORK_POLICY`](https://scrapfly.io/docs/cloud-browser-api/error/ERR::BROWSER::INVALID_NETWORK_POLICY) | The `network_policy` parameter is not a policy. The message names the entry. |
| [`ERR::BROWSER::NETWORK_POLICY_BLOCKED`](https://scrapfly.io/docs/cloud-browser-api/error/ERR::BROWSER::NETWORK_POLICY_BLOCKED) | The `target_url` of the session is on a host a policy refuses. |
| [`ERR::SCRAPE::NETWORK_POLICY_BLOCKED`](https://scrapfly.io/docs/scrape-api/error/ERR::SCRAPE::NETWORK_POLICY_BLOCKED) | The URL of a scrape or a screenshot, or a redirect of it, reaches a host the project policy refuses. |
| [`ERR::CRAWLER::NETWORK_POLICY_BLOCKED`](https://scrapfly.io/docs/crawler-api/error/ERR::CRAWLER::NETWORK_POLICY_BLOCKED) | The seed URL, the `remote_url_list`, or every URL of the `url_list` of a crawl is on a host the project policy refuses. |
| [`ERR_PROXY_NETWORK_POLICY_BLOCKED`](https://scrapfly.io/docs/proxy-saver/getting-started#errors) | Proxy Saver, `403`: the target host of a connection is refused by the network policy of your project. |

## Related

- [Cloud Browser parameters](https://scrapfly.io/docs/cloud-browser-api/getting-started#api_param_network_policy)
- [Proxy &amp; Geo-Targeting](https://scrapfly.io/docs/cloud-browser-api/proxy)
- [Projects and Environments: network policy](https://scrapfly.io/docs/project#network-policy)
- [Cloud Browser errors](https://scrapfly.io/docs/cloud-browser-api/errors)
