Learning center

Reproduce a failed third-party script by blocking its URL

A page that breaks for only some users may depend on a script from another domain that failed to load for them. A content blocker removed it, a corporate proxy refused it, or the vendor's CDN was down. The maintainer's browser loads it fine. Blocking that one URL makes the failure replay on any machine, and the result shows whether the page degrades or breaks.

Find the request that failed#

In the reporter's Network panel, filter by the third-party domain or sort by status. A request that never got a response shows a status such as (blocked:other), (failed) or (canceled). A request with no status code explains each. Copy the request's full URL and the initiator, from the Initiator column, which tells the maintainer which code depended on it.

If the reporter cannot open DevTools, ask whether they use a content blocker, a VPN or a work network, and whether the page works in a window with extensions off. Works in incognito covers that split.

Block it in DevTools#

  1. Right-click the request in the Network panel and choose Block request URL or Block request domain.
  2. Or open the Network request blocking drawer tab, enable it, and add a pattern such as *analytics.example-cdn.test/*.
  3. Reload and reproduce.

Chrome DevTools: Block requests

Block it in a script#

Playwright can fail matching requests from a route handler. It works in all three engines:

await page.route('**/analytics.example-cdn.test/**', route => route.abort());
await page.goto('https://staging.example.test/checkout');

In Chromium, the DevTools Protocol's Network.setBlockedURLs blocks requests the way the DevTools drawer does. We tried both against a fixture. The route's abort failed the request with net::ERR_FAILED. The protocol's blocking reported no error text and a blocked reason of inspector. Neither matches an extension's block exactly, which Chrome reports as net::ERR_BLOCKED_BY_CLIENT, but the page's code sees the same thing in each case: the script or request did not load. Playwright: route.abort()

route.abort() takes an error code, such as route.abort('blockedbyclient') or route.abort('timedout'), if the page's handling differs by error.

Test the failure modes that differ#

A third-party resource can fail in more than one way, and pages often handle only one.

FailureHow to reproduceWhat the page sees
Blocked or refusedroute.abort()An error event on the script, or a rejected fetch
Slow, then times outA route that waits before route.abort('timedout')Nothing for a long time, then an error
Loads, but returns an error pageroute.fulfill({ status: 503, body: '' })The script element loads nothing useful; a global the page expects is missing
Loads an older or different versionroute.fulfill({ path: 'old-vendor.js' })A global with a different API

The slow case matters most for scripts loaded synchronously in <head>, which block parsing until they finish or fail.

Report the dependency#

Say which URL failed, how (blocked, timed out, error status), and what the page did: a missing button, a blank section, a frozen checkout. Add the initiator, so the maintainer knows which code assumed the script was present. A line such as checkout.js:212 window.vendorPay.init() is often the whole bug.

Worked example: a checkout that needed an analytics script#

This example is fictional. A small share of users report that the Pay button does nothing. Support cannot reproduce it.

One user's Network panel shows https://metrics.example-cdn.test/tag.js as (blocked:other), and the Console shows TypeError: window.tagQueue is undefined at checkout.js:88. The developer blocks the same URL with page.route and the Pay button stops working on every run. The checkout code pushed a "payment started" event to the analytics queue before submitting the form, and the push threw when the queue did not exist. The fix guarded the push, and the blocked-URL script became a test that checkout works with every third-party script blocked.

Questions#

Should a site work with all third-party scripts blocked?

Core actions such as signing in and paying usually should, and the test above checks it. Some features, such as an embedded map, legitimately need their script; they should fail visibly rather than break the rest of the page.

Does blocking affect requests from service workers?

Requests made by a service worker can bypass page-level routing. Block service workers in the context, as the service worker guide shows, so every request goes through the route.

Can I reproduce a DNS failure?

route.abort('namenotresolved') gives the page the error a DNS failure produces, without changing your machine's DNS.

Return to reproducing what someone else saw for the other layers a replay needs.

One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. Eligibility and fair-use terms.

Start free with GitHub

Related reading