Mocks

Mock Rules intercept fetch/XHR calls on your permitted domains and return a response you define instead of hitting the real network — useful for simulating an API response, an error state, or a backend that doesn't exist yet.

Before you start: turn on "Allow User Scripts". Mock Rules rely on Chrome's chrome.userScripts API (Chrome 138+) to reliably win the race against a page's very first fetch() call. Without it, mocks don't intercept anything. Go to chrome://extensions, open DevHeader's Details page, and turn on Allow User Scripts. The popup's Mocks tab has a status badge (top right) — green when mocks are running, or a lightbulb guide with an "Open extension settings" link if the toggle is still off; the same clickable guide is available in DevTools' Mock Management header too, next to a compact status badge.

Try it yourself

The demo below fetches from a small live sample API right on this page — no project of your own required.

  1. Open Chrome DevTools and switch to the DevHeader panel.
  2. Reload this page — the panel only captures requests made while it's open, so you'll see a fresh GET request to /api/playground/users appear in the list.
  3. Select it and click Add to Mocks.
  4. In the detail pane, edit the response — rename a user, remove one, or set the status code to 500 to see what an error response looks like. Click Save, then enable the rule.
  5. Reload this page again. It now renders your edited response instead of the real one.
GET /api/playground/users

Loading…

This demo also has its own page, if you'd rather link straight to it: Playground.

Two surfaces, two jobs

Mocks are split across the popup and DevTools on purpose:

  • Popup → Mocks tab — a quick, read-only list. Enable, disable, or delete a rule. Every change here applies immediately, no Save step.
  • DevTools → DevHeader panel → Mock Management — the full editor. Pick a rule from the list to edit its match type, URL, method, status code, response body, and headers in the detail pane on the right, then click Save.

If you need to change what a mock actually returns, do it from the DevTools panel — the popup can only turn rules on/off or remove them.

Creating a mock

There are two ways to start a new rule:

  1. Capture a real request. Open the DevHeader panel in DevTools, browse to trigger the request you want to mock, select it in the list, and click Add to Mocks. This creates a new rule pre-filled with the real response, so you can tweak it from there.
  2. Start from scratch. Click New Mock in the DevTools panel to open a blank rule and fill in everything yourself.

Either way, a newly created rule starts disabled — nothing gets intercepted until you've reviewed it and switched it on.

What a rule matches

  • REST rules match the request URL. Simple mode matches any URL that contains your pattern, such as /api/users (so /api/users/42 matches too); Regex mode takes a regular expression, tested against the full absolute URL.
  • Query params (Simple mode) are checked one by one against the request's real query string, in any order. Add page = 2 to mock only /api/users?page=2. Untick a param to ignore it without deleting it.
  • GraphQL rules match the endpoint URL plus the operationName in the request body, so you can mock GetUser and leave every other query on the same /graphql endpoint alone.

A rule returns the status code, response headers, and body you set. Edit them field by field in the Form view, or switch to JSON to edit the whole rule at once. The body editor has Copy and Expand buttons for long responses.

Give a rule an optional Name to show in the list instead of its URL or operation. Duplicate copies a rule (the copy starts disabled), from either the popup or DevTools.

Live Status

The lower half of the DevHeader panel, Live Status, lists the page's fetch/XHR requests with a filter box (the count shows N of M requests while filtering), Type and Time columns, and a detail pane for headers and the formatted response. Selecting a request shows its method, URL, status and time above three tabs: Response (shown first), Headers (what the server sent back) and Request headers (what the browser sent, including headers your header rules added). Hover the i next to the count for how capture works. When DevTools is docked to the side, each list stacks above its detail pane.

A mocked request never reaches the network, so it never appears in Live Status or in Chrome's Network panel. A request that does appear went to the real server. When an enabled rule matches a row's URL, the row says why it wasn't mocked:

  • Mock after reload: your mocks changed after this page loaded. Live Status also shows Reload needed next to Reload page.
  • Not mocked: the page loaded after your last mock change, and the request still reached the network. Check the status badge next to New Mock, and whether the request comes from an iframe or worker (see Limits).

To see what your mocks did return, use Mocked N× (below).

If a mock rule already covers a request's URL (same path and query parameters), Add to Mocks reads Open mock and opens that rule instead of adding a second one, which would never fire. To keep two responses for the same URL, open the rule and use Duplicate, then turn on the one you want.

Replay in a GET request's detail pane runs it again from the page, so it goes through your mocks and header rules: a quick way to check a new mock without clicking through the app. It sends a plain GET, without the original request's own headers. Only GET requests can be replayed, so a POST is never sent twice by accident.

If Live Status shows other traffic but no fetch/XHR rows, another extension that also intercepts fetch/XHR (such as Requestly) is probably hiding them. The panel shows a warning when it sees this pattern.

Is my mock running?

The status badge in the popup's Mocks tab and in DevTools' Mock Management header says why a mock isn't firing:

Badge Fix
Active mocks (N) Running. Reload the target tab after changing a rule.
No mocks Enable at least one rule.
Scripts disabled Turn on Allow User Scripts for DevHeader in chrome://extensions (Chrome 138+).
No domain access Grant DevHeader's one-time access permission.
Paused Turn DevHeader back on.

Mocks only take effect when a page loads. After you add, edit or turn off a mock, the popup footer shows Reload needed with a Reload Page button for the tab you opened DevHeader on, and the Debug panel says the mocks changed after the page loaded.

Did my mock fire?

  • Mocked N× on a rule's row, in the popup's Mocks tab and in DevTools' Mock Management, counts the mocked responses that rule returned on the open page since it loaded. Hover it to see the last URL. It resets when the page reloads. The popup counts up to when you opened it; DevTools updates as the page runs.
  • No badge on an enabled rule after the page made the request means the mock didn't fire: check the status badge above, the rule's URL pattern, and whether the page reloaded since you saved. The Mocks guide (lightbulb) says the same.
  • Every mocked response has an x-devheader-mock header set to the rule's name (or rule <id> if the name has non-ASCII characters), so your own code or the console can check response.headers.get('x-devheader-mock'). If your rule sets that header itself, your value is kept. DevHeader never changes the response body.

Mocks don't delay or throttle responses: they return immediately.

Scope

Mock Rules need the same one-time host-permission grant every other rule type needs (see Domains) — but unlike Headers and Redirects, they are not narrowed by the Domains list. Once permission is granted, a mock rule runs on any site whose request matches its own URL pattern, regardless of which domains are enabled for the active profile.

See also

Limits

Mocks replace the page's own fetch and XMLHttpRequest, so they don't catch requests made from iframes, Web Workers, or service workers. Those requests still reach the real server (header and redirect rules do apply to them).