Skip to content
Tutorials Center
My learning

Topics

Lesson 14 of 36 ยท Console and Sources

Snippets, Overrides, Workspaces and Source Maps

Save reusable snippets, keep edits with local overrides and workspaces, and debug original code with source maps, including a runnable Base64 VLQ source-map decoder.

By default, edits you make in DevTools disappear on reload, and the code you debug may be minified beyond recognition. Four features fix this: snippets keep useful scripts, local overrides persist edits to files from any site, workspaces connect DevTools to your project folder, and source maps show your original code instead of the bundle.

Snippets

A snippet is a small JavaScript file stored in your browser profile, runnable on any page. In Sources, open the Snippets tab in the left sidebar, choose New snippet, write code, and press Ctrl+Enter to run it. You can also run one from the Command Menu by typing ! and its name.

Good uses for snippets:

  • A script that lists all images without alt text.
  • A helper that highlights elements wider than the viewport.
  • A bookmarklet-like script that logs the page's meta tags.
  • A routine you run before every Lighthouse test.
JavaScript
// Snippet: list images missing alt text
const bad = [...document.images].filter(img => !img.hasAttribute("alt"));
console.log(`${bad.length} image(s) without alt`);
bad.forEach(img => console.log(img.currentSrc));

Snippets run in the page's context (not in the DevTools context), so they can read page globals but have no special utilities beyond those in the Console.

Local Overrides

Sometimes you want a change to survive reloads on a live site, for example to test a fix against production data, or to change a response you cannot edit. Local overrides do this:

  1. In Sources, open the Overrides tab.
  2. Click Select folder for overrides and choose an empty folder on your computer. Allow access when Chrome asks.
  3. Edit a file in Sources (for example a CSS or JS file), then press Ctrl+S. The edited file is saved in your override folder.
  4. On the next reload, Chrome serves your local copy instead of fetching the file. A purple dot next to a file marks it as overridden.

In the Network panel you can right-click a request and choose Override content, which saves the response into the folder for editing. Override headers lets you edit HTTP response headers for that URL (for example to add a CORS header to test a fix). Overrides apply only while DevTools is open and the Enable Local Overrides box is ticked.

An override stays active until you remove it. If a site looks different on your machine than for colleagues, check for forgotten overrides: untick Enable Local Overrides, or delete the files in your override folder.

Workspaces

A workspace links a folder on disk (your project) to what DevTools loaded from a dev server. After adding the folder in Sources, Chrome can map each served URL to a file in the folder, based on name and content. When mapped, editing a file in Sources or changing CSS through the Styles pane and saving writes real files, and your build tool or dev server reloads the page.

Typical setup:

  1. In Sources, Workspace tab, click Add folder to workspace, select your project root, allow access.
  2. Open a file from the folder; green dots mean Chrome matched it to a network file.
  3. Edit CSS in the Styles pane and press Ctrl+S (or use autosave) to write changes back.

Many frameworks serve bundled code, so mapping works best with source maps, or with plain CSS and HTML projects. Some dev servers (for instance Vite and webpack) also provide automatic workspace configuration through a /.well-known/appspecific/com.chrome.devtools.json file; check your tool's documentation, and note the details change between versions.

Source maps

Production JavaScript is usually minified and bundled into a few files with names like main.a1b2c3.js. Errors point at main.a1b2c3.js:1:48372, which tells you nothing. A source map (.map file) records how each position in the generated file corresponds to a position in your original sources.

If the generated file ends with a comment such as //# sourceMappingURL=main.a1b2c3.js.map (or the server sends a SourceMap header), DevTools downloads the map when it is open and:

  • shows your original files (TypeScript, JSX, SCSS) in the Sources tree under a folder for the bundle,
  • lets you set breakpoints in the originals,
  • translates stack traces and Console messages into original file names and lines,
  • shows original variable names in Scope when the map includes names.

Settings let you turn JavaScript and CSS source maps on or off. If a source map is missing, DevTools says "Source map failed to load" in the Console; check that the .map file is deployed and reachable, since many sites choose not to publish them in production.

How a source map encodes positions

The mappings field of a version-3 source map is a string of Base64 VLQ numbers. Each segment (separated by commas) holds up to five values: the column in the generated line, the source file index, the source line, the source column and an optional name index. Lines are separated by semicolons. Every number except the first on a line is stored as a delta from the previous one, and negative numbers are encoded with a sign bit.

Here is a decoder you can run. It is a real implementation of the VLQ format, applied to a tiny hand-written map, so it is a stand-in only in the sense that it is not DevTools' code.

JS Decode source-map mappings (Base64 VLQ)

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Notice that gB decodes to 16: a two-character value, because the first character carries a continuation flag. D decodes to -1: the low bit is the sign. These small ideas are the whole format.

Stand-in: looking up an original position

Given decoded mappings, DevTools needs to answer: "this error is at generated line 1, column 20; where is that in my sources?" This stand-in does the lookup by choosing the mapping at or just before the column.

JS Stand-in: map a generated position to the source

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Putting it together

  • Use snippets for scripts you run again and again.
  • Use overrides to test a fix on a live site without access to its source.
  • Use a workspace with your local dev server so Styles-pane edits save to disk.
  • Keep source maps enabled while developing; decide deliberately whether to publish them to production.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is the purpose of Local Overrides?

    Overrides save your edited copy of a file locally and serve it on reload.
  2. 2. What does a source map do?

    Source maps let DevTools show original files and translate stack traces.
  3. 3. How do you run a snippet?

    Ctrl+Enter runs the open snippet; the ! prefix in the Command Menu runs one by name.
  4. 4. In VLQ source-map segments, what does the lowest bit of the decoded value represent?

    VLQ stores the sign in the lowest bit; the continuation flag is a separate bit in each Base64 digit.

Summary

  • Snippets store reusable scripts; run them with Ctrl+Enter or !name.
  • Local overrides persist edited files and headers; remove them when finished.
  • Workspaces connect DevTools to your project folder so edits save to disk.
  • Source maps show original code, with positions encoded as Base64 VLQ deltas.

Next: The Network Panel: Requests and the Waterfall