Overview Open Chrome DevTools What's New in DevTools DevTools tips Simulate mobile devices with Device Mode Performance insights: Get actionable insights on your website's performance Lighthouse: Optimize website speed Animations: Inspect and modify CSS animation effects Changes: Track your HTML, CSS, and JavaScript changes Coverage: Find unused JavaScript and CSS Developer Resources: View and manually load source maps CSS Overview: Identify potential CSS improvements Issues: Find and fix problems Media: View and debug media players information Memory Inspector: Inspect ArrayBuffer, TypedArray, DataView, and Wasm Memory. Network conditions: Override the user agent string Security: Understand security issues Search: Find text across all loaded resources Sensors: Emulate device sensors WebAuthn: Emulate authenticators Customize DevTools Engineering blog
Overview Open Chrome DevTools What's New in DevTools DevTools tips Simulate mobile devices with Device Mode Performance insights: Get actionable insights on your website's performance Lighthouse: Optimize website speed Animations: Inspect and modify CSS animation effects Changes: Track your HTML, CSS, and JavaScript changes Coverage: Find unused JavaScript and CSS Developer Resources: View and manually load source maps CSS Overview: Identify potential CSS improvements Issues: Find and fix problems Media: View and debug media players information Memory Inspector: Inspect ArrayBuffer, TypedArray, DataView, and Wasm Memory. Network conditions: Override the user agent string Security: Understand security issues Search: Find text across all loaded resources Sensors: Emulate device sensors WebAuthn: Emulate authenticators Customize DevTools Engineering blog

Override web content and HTTP response headers locally

Published on Updated on

With local overrides, you can override HTTP response headers and web content, including XHR and fetch requests, to mock remote resources even if you don't have access to them. This lets you prototype changes without waiting for the backend to support them. Local overrides also lets you keep the changes you make in DevTools across page loads.

How it works:

  • When you make changes in DevTools, DevTools saves a copy of the modified file to a folder you specify.
  • When you reload the page, DevTools serves the local, modified file, rather than the network resource.
Important

You can also save your changes directly to source files. See Edit and save files with Workspaces.

Limitations

Local overrides work for network response headers and for most file types, including XHR and fetch requests, with a couple of exceptions:

  • DevTools doesn't save changes made in the DOM tree of the Elements panel.
  • If you edit CSS in the Styles pane, and the source of that CSS is an HTML file, DevTools won't save the change.

Instead, you can edit HTML files in the Sources panel.

Set up local overrides

You can override web content or response headers right away in the Network panel:

  1. Open DevTools, navigate to the Network panel, right-click a request you want to override, choose Override headers or Override content from the drop-down menu. Choosing override content from the right-click menu of a request.

  2. If you haven't set up local overrides yet, in the action bar at the top, DevTools prompts you to:

    1. Select a folder to store the override files in. DevTools prompts you to select a folder.
    2. Click Allow to grant DevTools access rights to it. DevTools requests access.
  3. If you have local overrides set up but disabled, DevTools automatically enables them.

  4. Once local overrides are set up and enabled, depending on what you are about to override, DevTools takes you to:

    • The Sources panel to let you make changes to web content.
    • The editor in Network > Headers > Response Headers to let you make changes to response headers.

To temporarily disable local overrides or delete all the override files, navigate to Sources > Overrides and clear the Empty checkbox. Enable Local Overrides checkbox or click Clear. Clear respectively.

To delete a single override file or all overrides in a folder, right-click the file or folder in Sources > Overrides, select Delete, then click OK in the dialog. This action can't be undone and you will have to manually recreate the deleted overrides.

To quickly see all overrides, in the Network panel, right-click a request and select Show all overrides. DevTools will take you to Sources > Overrides.

Override web content

To override web content:

  1. Set up local overrides.
  2. Make changes to files and save them in DevTools.

You can't override source-mapped files. If you right-click a request in the Network panel and select Override content DevTools shows you a dialog that takes you to the original source files instead.

For example, you can edit files in Sources or CSS in Elements > Styles, unless the CSS lives in HTML files.

DevTools saves the modified files, lists them in Sources > Overrides, and shows you the Saved. icon next to the overridden files in the relevant panels and panes: Elements > Styles, Network, and Sources > Overrides.

The corresponding icons next to overridden files in Sources, Network, and Elements > Styles

Override XHR or fetch requests to mock remote resources

With local overrides, you don't need access to the backend and don't have to wait for it to support your changes. Mock and experiment on the fly:

  1. Set up local overrides.
  2. In Network, filter for XHR/fetch requests, find the one you need, right-click it, and select Override content.
  3. Make your changes to the fetched data and save the file.
  4. Refresh. Refresh the page and observe your changes applied.

To learn this workflow, watch the following video:

Track your local changes

You can keep track of all the changes you make to web content in one place—the Changes drawer tab.

Override HTTP response headers

From the Network panel, you can override HTTP response headers without access to the web server.

With response header overrides, you can locally prototype fixes for various headers, including but not limited to:

To override a response header:

  1. Set up local overrides and inspect, for example, this demo page.

  2. Go to Network, find a request, right-click it, and select Override headers. DevTools takes you to the Headers > Response Headers editor.

  3. Hover over a response header value and place a cursor there.

    The Response Headers editor.

    Alternatively, to enable the Response Headers editor, hover over a response header value and click Edit..

  4. Modify or add a new header.

    This example adds the Access-Control-Allow-Origin: * header to get rid of a CORS error.

    Modifying an existing header value, adding a new one, and removing an override.
    • To edit a header value, click it.
    • To add a new header, click Add. Add header.
    • To remove a header override, click Delete. next to it. This removes the headers you added or reverts modified values back to original values.

    DevTools highlights modified headers in green and removed overrides in red.

  5. Refresh. Refresh the page to apply the changes.

Edit all response header overrides

To edit all header overrides in one place:

  1. Click Saved. Header overrides next to the Response Headers section.

    The Header overrides link next to the Response Headers section.

    DevTools takes you to the corresponding .headers file in Sources > Overrides.

  2. Edit the .headers file:

    Editing the .headers file.
    • To add a new override rule, click Add override rule. A rule here is a set of headers and values and a single or multiple request to apply them to.

      You can use wildcards to specify multiple requests at once. Designate multiple characters with * and a single one with ?.

    • To add a header-value pair to a rule, hover over another pair and click Add..

    • To revert a header value, remove an added header or a rule, hover over it and click Delete..

  3. Save the .headers file with Command / Control + S.

  4. Refresh. Refresh the page to apply the changes.

Updated on Improve article

This site uses cookies to deliver and enhance the quality of its services and to analyze traffic. If you agree, cookies are also used to serve advertising and to personalize the content and advertisements that you see. Learn more about our use of cookies.