All articles3 min read
Implementation guides

Reduce proxy bandwidth in Playwright without losing required data

Lower avoidable transfer costs in a verified browser workload.

An analyst reviews image-heavy page content beside a laptop and network cable.

To reduce proxy bandwidth in Playwright, measure which requests your page makes and decide which ones the dataset needs. A browser can fetch fonts, media, scripts, images and application data. Removing the wrong request can reduce transferred bytes while breaking the record you wanted.

Measure one representative baseline

Use a permitted page and a defined record contract. Save the selected variant, market, observation time and accepted fields. Record request classes and the traffic evidence available from your own instrumentation and account.

Keep transfer measurements separate from the size of exported text. Also keep browser observations separate from provider billing units. Compression, cached resources and the service's accounting rules can affect how the figures relate.

Identify required resources

Inspect the page's network activity before setting broad filters. A script or data request may populate the prices or availability fields. An image can also be part of the dataset. A visual category is not automatically safe to remove.

Start with a narrow hypothesis and one change. For example, a particular collection task may not need downloadable fonts or media. That hypothesis still needs a correctness check on the page you actually collect.

Apply a small, testable filter

This JavaScript example uses a controlled page whose completed state and product selectors are explicit. It blocks font and media request classes. It is not a universal filter for arbitrary sites.

async function filtered_records(page, url) {
  await page.route('**/*', route => {
    const type = route.request().resourceType();
    return ['font', 'media'].includes(type)
      ? route.abort() : route.continue();
  });
  await page.goto(url, {waitUntil: 'domcontentloaded', timeout: 15000});
  await page.locator('[data-results-state="ready"]').waitFor({
    state: 'attached', timeout: 10000
  });
  return page.locator('[data-product-id]').evaluateAll(nodes =>
    nodes.map(node => ({id: node.dataset.productId, name: node.textContent.trim()}))
  );
}

The caller must validate records and enforce the overall job deadline. Use a fresh, controlled browser context for the test. Check actual requests as well as the filter configuration; a rule's presence is not a complete traffic audit.

Compare records before comparing bytes

Run the same page contract with and without the filter. Confirm product identity, required fields and the meaning of an empty result. If the record changes or readiness never arrives, classify the filtered run as a failure.

Include a fixture where a required data request is mistakenly blocked. The test should detect the lost data, not celebrate the smaller transfer. That case is useful protection when someone later broadens a resource rule.

A local request counter can demonstrate that a fixture request did not reach your server. It does not establish a universal percentage reduction or the exact provider bill. Publish only the measurement and scope you actually verified.

Look at repeated work

Repeated navigations and unnecessary retries can cost more than an optional resource. Check why a page was fetched again before adding more filtering. Keep a failed validation distinct from a network failure so that retries address the right cause.

Revisit whether a browser is needed for that page at all. The browser decision guide describes how to compare the initial response with the rendered result. Preserve the same acceptance rules when changing the collection method.

Keep the optimization reviewable

Version the rules and retain before/after record checks. Review the filter when the target layout or your required fields change. A rule that was appropriate for one dataset can become incorrect when the task expands.

Use the current residential proxy billing contract to evaluate the effect on your workload. The bandwidth calculator can help model declared inputs. Test the collection path before increasing its traffic allowance.

Contact us

Tell us what you want to collect.

See our Privacy Notice for how we handle your message.

Your message is sent to hello@crawlhub.ai. Please do not include passwords or API keys.