Skip to main content

Block rules

A Block rule cancels a matching request. It is a redirect with nowhere to go: no payload, no status code, no headers, no hooks, the request simply never leaves the browser.

Like Headers only and Redirect rules, a block is applied by the browser itself rather than by tweak inside the page. That is what lets it block things your JavaScript never asks for: the page navigation itself, <script> tags, stylesheets, images and fonts.

What the page sees​

A blocked request fails the way a request fails when the network is down: the page gets a network error, not a response.

  • fetch rejects with a TypeError.
  • An XMLHttpRequest fires its error event.
  • In the browser's devtools, the request shows up as failed (Chromium browsers label it net::ERR_BLOCKED_BY_CLIENT).

There is no status code to pick, because there is no response at all. If you want the request to come back with a 500 or an empty body instead, use a mock rule.

Fields​

Beyond the url expression and the method, a block rule adds:

  • Scope: active tab or global, see below.
  • Catch: which kind of request to block, see below.

Opened, the rule reminds you what it does: "Matching requests never leave the browser: the page sees a network error." The only tab is Notes, where you can say why the rule exists.

note

A block rule with an empty url expression does nothing. Blocking every request would take every page down with it, so tweak waits until you type what to match.

Using variables​

note

Variables in the url expression are only available on Tweak Max. Compare the plans here. On other plans a {{<name>}} is matched exactly as typed. Generators are not accepted here: a url is a matcher, and a generated one would match nothing twice.

The url expression accepts variables, {{<name>}}, exactly as on a redirect rule.

Catch: which requests to block​

Catch decides which kind of request the rule applies to. It is the same dropdown as on a redirect rule.

CatchRequests
AnythingEvery request type, the page navigation included.
Fetch / XHRAPI calls made by the page.
PageThe top level navigation itself.
IframeDocuments embedded in the page.
ScriptJavaScript the page loads.
StylesheetCSS the page loads.
ImageImages, including favicons.
MediaAudio and video.
FontWeb fonts.

Anything is the default. Every option is free, on every plan.

tip

Narrowing matters even more for a block than for a redirect. A rule catching Anything on example.com also blocks the page navigation, so the page itself will not load. If you only meant to cut off the page's API calls, pick Fetch / XHR.

Scope​

Block rules use the same Scope dropdown as headers only rules, and default to Active tab: they apply only while tweak is running, on that tab.

Global blocks apply on every tab whether or not tweak is running, and survive a browser restart. Pausing tweak switches them off too, and running it again switches them back on, the same way as a global header rule.

caution

A global block on a broad expression can break a whole site on every tab, with no obvious way back other than disabling the rule. Prefer Active tab unless you specifically want the block to stay on.

Block rules alongside other rules​

  • A block beats a redirect. If a block rule and a redirect rule match the same request, the request is blocked, wherever the two rules sit in your list. A request you asked to block never leaves the browser because a redirect also matched it.
  • Between block rules, the one higher up your list wins, the same first-match-wins ordering as every other rule type.
  • Headers only rules have nothing to do on a blocked request: it is never sent, so there are no headers to rewrite.

Common uses​

  • Test how the app copes when an API is down. Catch Fetch / XHR on the endpoint, and watch the error states, retries and fallbacks.
  • Turn off a third party. Block an analytics, chat or ads script to see the page without it, or to check nothing breaks when a visitor's ad blocker does the same.
  • Break an asset on purpose. Block a stylesheet, a font or the images to see how the page degrades.
  • Silence a noisy request. Stop a polling call or a tracking beacon while you debug something else.
tip

If the request should fail with a specific status code or a body, rather than a network error, you want a mock rule. If it should go somewhere else, you want a redirect rule.



Was this page helpful?

Need something else? Request a feature