Skip to main content

How to Block a Request URL in Chrome

ยท 9 min read
Daniel Caldas
Co-founder

You want to know what your app does when one request never arrives. The recommendations API is down: does the product page still render? The analytics script is blocked by a visitor's ad blocker: does checkout still work? The font CDN times out: does the text show at all?

The quickest way to find out is to block that request URL in the browser and look. This guide shows three ways to do it in Chrome, what the page receives when you do, and which one to pick.

Why block a requestโ€‹

  • Test error handling. A failed request is a different code path from a 500: fetch rejects instead of resolving, so the handling lives in a catch, and that branch is the one most often missing.
  • Test resilience. Retries, fallbacks, cached data, an offline banner. Block the endpoint and watch whether they kick in.
  • See the page without a third party. Analytics, chat widgets, A/B testing and ads scripts. Visitors with ad blockers already see your site this way.
  • Measure what a request costs. Toggle a script or an API call off and see what changes in load time and layout.
  • Silence noise. A polling call or a tracking beacon that floods the Network panel while you debug something else.

Option 1: DevTools request blockingโ€‹

Chrome DevTools can block a request in two clicks. Edge has the same feature, and Firefox has its own version.

  1. Open DevTools (F12, or โŒ˜ + Option + I on a Mac) and go to the Network panel.
  2. Reload the page so the request shows up in the list.
  3. Right-click the request and pick Block request URL, or Block request domain to block everything from that host.
  4. Reload. The request now shows in red with the status (blocked:devtools).

example using request blocking in chrome

The drawer at the bottom of DevTools opens on the Network request blocking tab, which lists every pattern you blocked. From there you can:

  • Edit a pattern and widen it with the * wildcard: */api/recommendations* blocks the endpoint whatever its query string.
  • Add a pattern by hand with the + button, without finding the request first.
  • Switch one pattern off, or untick Enable network request blocking to pause all of them.

You can also open the tab from the Command Menu (โŒ˜ + Shift + P or Ctrl + Shift + P, type "blocking").

In Firefox, right-click the request in the Network panel and pick Block URL. The blocked urls are listed in the request blocking side panel, opened from the Network panel's toolbar.

Where it stops. DevTools blocking only works while DevTools is open on that tab. Close it, or open the page in a new tab, and the request goes through again. The patterns live in your DevTools, so a teammate cannot reuse them. And it is all or nothing: you cannot block a request only when its body matches, or only the third time it is sent.

Our guide to the Network tab covers request blocking alongside throttling, overrides and the rest of the panel.

Option 2: a Block rule in tweakโ€‹

A Block rule does the same job without DevTools, and stays on until you switch it off. It is free on every plan.

  1. Install tweak and open it on the page.
  2. Create a rule and pick Block request as its type.
  3. Type part of the url to block, for example api.example.com/recommendations. Turn on regular expressions if you need a pattern.
  4. Pick what to Catch: Fetch / XHR for API calls, Script, Stylesheet, Image, Font, Media, Iframe, the Page itself, or Anything.
  5. Start tweak on the tab and reload.

The browser itself cancels the request, before it leaves the machine. That is why a block rule can stop things your JavaScript never asks for: a <script> tag, a stylesheet, an image, or the page navigation. DevTools shows it as failed, with net::ERR_BLOCKED_BY_CLIENT.

Two settings matter:

  • Catch. Narrow it. A rule catching Anything on example.com also blocks the page itself, so nothing loads. If you only meant the API calls, pick Fetch / XHR.
  • Scope. Active tab (the default) applies only on the tab where tweak runs. Global applies on every tab and survives a browser restart. Prefer Active tab unless you want the block to stay on everywhere.

The rule keeps working after a reload, in a new tab with tweak started on it, and with DevTools closed. You can export it and send it to a teammate, write in its Notes tab why it exists, and switch it on and off in one click from the rule list.

Option 3: in automated testsโ€‹

When the check belongs in CI, block the request in the test itself.

Playwright:

await page.route('**/api/recommendations*', (route) => route.abort())
await page.goto('https://shop.example.com/product/42')

Puppeteer:

await page.setRequestInterception(true)
page.on('request', (request) => {
if (request.url().includes('/api/recommendations')) request.abort()
else request.continue()
})
await page.goto('https://shop.example.com/product/42')

Both make the request fail with a network error, like the browser options above. The test then asserts on what should be on the screen: the fallback, the retry button, the rest of the page.

What the page seesโ€‹

A blocked request gets no response at all. The page sees what it would see if the network dropped:

ClientWhat happens
fetchThe promise rejects with a TypeError
XMLHttpRequestThe error event fires, status is 0
AxiosRejects with a network error, and error.response is undefined
<script>The error event fires on the element, the code never runs
<img>The error event fires, the image shows as broken

That is the difference with a server error. A 500 is a response: fetch resolves, response.ok is false, and your code reads the body. A blocked request never reaches that branch.

When blocking is not what you needโ€‹

Which one to pickโ€‹

OptionBest forLimits
DevTools blockingA quick look, onceOnly while DevTools is open on that tab, not shareable
tweak Block ruleBlocking that stays on, across reloads and tabsA browser extension to install
Playwright / PuppeteerA check that runs in CI on every changeCode to write and maintain

FAQโ€‹

How do I block a request URL in Chrome DevTools?

Open DevTools, go to the Network panel, reload the page, right-click the request and pick "Block request URL" (or "Block request domain"). Reload again and the request fails. The blocked patterns are listed in the Network request blocking tab of the drawer, where you can edit them with * wildcards or switch them off. The block only lasts while DevTools is open on that tab.

How do I block a request without keeping DevTools open?

Use a browser extension. In tweak, create a rule, pick Block request as its type and type part of the url to match. The browser cancels every matching request while tweak runs on the tab, after reloads too, or on every tab if you set the rule's scope to Global.

What does the page see when a request is blocked?

A network error, not a response. fetch rejects with a TypeError and an XMLHttpRequest fires its error event, the same as on a dropped connection. DevTools shows the request as failed, with (blocked:devtools) for its own blocking and net::ERR_BLOCKED_BY_CLIENT when an extension blocked it.

Can I make a blocked request return an error status like 500 instead?

Blocking cannot, because no response exists. To get a 500, a 404 or a specific error body, mock the request instead: a tweak Mock rule answers with the status and body you choose.

Is blocking requests with tweak free?

Yes. Block rules are free on every plan, with every Catch option and both scopes, and need no account.

Summaryโ€‹

To block a request URL in Chrome, right-click it in the Network panel for a one-off look, or create a free Block rule in tweak when you want the block to persist without DevTools. Either way, the page gets a network error, so you test the catch branch of your code, the one a 500 never reaches. When you need a status code instead, mock the request.

Working across the stack? See tweak for full-stack developers.

If you liked this article, consider sharing (tweeting) it to your followers.



Did you like this article?

Need something else? Request a feature