browser

Playwright Network Interception

Playwright's route API intercepts, inspects, and modifies outgoing browser network requests, enabling scrapers to block ads, capture API responses, or mock data during tests.

Playwright's `page.route()` method installs a handler that intercepts matching requests before they are sent over the network. The handler can fulfil the request with a mock response, abort it entirely (useful for blocking images, fonts, or analytics scripts to speed up loads), modify the request URL or headers before forwarding, or simply log the request and let it pass through.

For data extraction, route interception is powerful: it allows the scraper to capture JSON API responses that power a page's dynamic content, without needing to parse the rendered HTML. The captured JSON is typically cleaner and more structured than scraped DOM content.

Route interception also enables performance optimisation: blocking resource types like `image`, `font`, `media`, and `stylesheet` reduces page load time by 50–80% for data-extraction tasks that only need HTML content, and significantly reduces bandwidth consumption in large-scale browser-based scraping.

Examples

// Playwright: intercept API calls to capture JSON directly
await page.route("**/api/products**", route => {
  route.continue();  // let it through but log it
});

page.on("response", response => {
  if (response.url().includes("/api/products")) {
    response.json().then(data => console.log(data));
  }
});

await page.goto("https://example.com/catalog");

Related Terms

Extract Playwright Network Interception data from any website

AlterLab returns clean, structured data from any public URL — no scraper infrastructure needed. Start free, no credit card required.

View API docs

Your first scrape.
Sixty seconds.

$1 free balance. No credit card. No SDK.Just a POST request.

terminal
curl -X POST https://api.alterlab.io/v1/scrape \
-H "X-API-Key: YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com", "formats": ["markdown"]}'

No credit card required · Up to 5,000 free scrapes · Balance never expires

    Playwright Network Interception — Web Scraping Glossary | AlterLab