Sharajdev

Mock API Responses in Chrome Without a Proxy: 4 Methods Compared

You want to see how the page behaves when the API returns a 500, an empty list, or a field that doesn't exist yet. You don't want to install a root certificate, configure a proxy, or ask the backend team for a special build. Here are four ways to do it from inside Chrome, what each is good at, and where each falls short.

By Sharaj Rewoo · Updated 25 September 2026

Why mock in the browser at all?

Traditional mocking means a proxy such as Charles, Fiddler or mitmproxy sitting between the browser and the network. Proxies are powerful, but for HTTPS they need a trusted root certificate on your machine, which corporate laptops often block, and they intercept everything rather than the one tab you care about.

Mocking inside the browser avoids both problems. It's the fastest way to:

Method 1: Chrome DevTools Local Overrides

Built into Chrome, no install needed. Local Overrides lets you replace a network response (or its headers) with a file saved on your machine, and Chrome serves that file every time the page requests the URL.

How to set it up

  1. Open DevTools and go to the Network panel. Reload so the request you want appears.
  2. Right-click the request and choose Override content. The first time, Chrome asks you to pick a folder to store overrides in and to allow access to it.
  3. Chrome opens the response in the Sources → Overrides tab. Edit the JSON, save with Ctrl/Cmd+S.
  4. Reload the page. The request now shows a purple dot in the Network panel, meaning it was served from your override.

To change response headers instead — for example to test a missing Cache-Control or a CORS header — right-click the request and choose Override headers, or open the request's Headers tab and edit a response header there. Chrome stores these in a .headers file in the same overrides folder.

Strengths and limits

Method 2: A mocking extension (Mockingbird)

Extensions sit between DevTools and a full proxy: they intercept traffic for a tab, but give you rules, status codes and delays that DevTools can't. Mockingbird is the one I built for this; the same approach applies to other mocking extensions.

How it works

Strengths and limits

Method 3: Mock Service Worker (MSW) in the app

Mock Service Worker is a JavaScript library that registers a service worker in your app and answers matching requests with handlers you write in code. Because it intercepts at the network level, your app's fetch or axios calls don't know they're being mocked.

// src/mocks/handlers.js
import { http, HttpResponse } from 'msw'

export const handlers = [
  http.get('/api/orders', () =>
    HttpResponse.json([], { status: 200 })),        // empty state

  http.post('/api/checkout', () =>
    new HttpResponse(null, { status: 503 })),       // outage
]

// src/mocks/browser.js
import { setupWorker } from 'msw/browser'
import { handlers } from './handlers'
export const worker = setupWorker(...handlers)

// in your app entry, dev only:
// if (import.meta.env.DEV) await worker.start()

You also run npx msw init public/ once to copy the worker script into your public folder.

Strengths and limits

Method 4: Patching fetch or XHR from the console

The quick-and-dirty option. Paste a snippet into the DevTools console (or save it under Sources → Snippets) that wraps window.fetch and returns a fake response for matching URLs:

const realFetch = window.fetch;
window.fetch = async (input, init) => {
  const url = typeof input === 'string' ? input : input.url;
  if (url.includes('/api/profile')) {
    return new Response(JSON.stringify({ name: null }), {
      status: 200,
      headers: { 'Content-Type': 'application/json' },
    });
  }
  return realFetch(input, init);
};

Strengths and limits

Comparison

DevTools OverridesMocking extensionMSWConsole patch
Setup effortLowLow (install once)Medium (code + build)Very low
Works on any siteYesYesNo — your app onlyYes
Survives reloadYesYesYesNo
Needs code accessNoNoYesNo
Change status codeNoYesYesYes
Change headersYesYesYesYes
Simulate latencyGlobal throttling onlyPer requestPer requestYes, manually
URL pattern matchingExact URLGlob / regex / substringPaths and paramsWhatever you code
Share with the teamCopy the folderExport rules as JSONIn the repoShare the snippet
Runs in CINoNoYesNo

Which one should you pick?

Many teams end up using two: an extension or DevTools for exploratory testing, and MSW for the mocks that should run on every build.

Where the real responses come in

Mocks are only useful if they look like the real API. Two habits help. First, start mocks from captured traffic rather than typing JSON from memory — export a HAR, or use XHRScribe, which records a tab's real XHR and fetch calls and turns them into runnable API tests. Second, watch for the real API drifting away from your mocks. Telltale learns each endpoint's schema from live traffic and alerts you when a response gains, loses or changes a field — exactly the moment your mocks go stale.

If you're deciding which failure responses to mock, the network section of 50 negative and edge-case test cases is a good starting list.

Related