Sub topic 7
Inspecting storage, cookies and service workers
This chapter assumes you know basic HTML, CSS and JavaScript, how a browser loads a page, and how HTTP requests and responses work. You should also have used the Network panel from the previous chapter. Panel names follow Chromium-based browsers. Firefox calls this panel Storage, and Safari calls it Storage as well.
What the Application panel shows
The Application panel shows data that a page keeps in the browser between visits, and the background code that runs for the page. Open it from the panel tabs, or from the >> overflow menu if the tab is hidden. The left sidebar groups its contents into three areas:
- Application: the web app manifest, service workers and the Storage summary.
- Storage: local storage, session storage, IndexedDB, and cookies.
- Cache: Cache Storage, which service workers use, and the back/forward cache.
Many bugs that look like script errors come from stale stored data. The panel lets you see that data and change it directly.
Local storage and session storage
Local storage keeps string key-value pairs with no expiry. Session storage keeps the same kind of data, but only for one tab and only until that tab closes. Select either one in the sidebar to see a table of keys and values.
You can double-click a value to edit it, add a row, or delete a row. Edits take effect immediately, but the page does not know about them. It will only see the new value the next time its code reads the key.
The same data is available from the Console, which is useful for scripted changes:
localStorage.setItem('theme', 'dark');
console.log(localStorage.getItem('theme'));
console.table(Object.entries(localStorage));
localStorage.removeItem('theme');A common error is storing an object without converting it. localStorage.setItem('user', {id: 1}) saves the text [object Object]. Use JSON.stringify when saving and JSON.parse when reading.
Cookies
A cookie is a small piece of data the server sets with a Set-Cookie header. The browser sends it back on later requests to the same site. Select Cookies under Storage to see one row per cookie. The columns that matter most when debugging are:
| Column | What it tells you |
|---|---|
| Domain and Path | Which requests will carry the cookie. |
| Expires / Max-Age | When it is removed. `Session` means when the browser closes. |
| HttpOnly | If checked, page scripts cannot read it through `document.cookie`. |
| Secure | If checked, it is sent only over HTTPS. |
| SameSite | Whether it is sent on cross-site requests (`Strict`, `Lax` or `None`). |
Three problems account for most cookie bugs:
- The cookie never appears. Open the Network panel, select the response, and check the Cookies tab. Chrome marks rejected cookies with a warning and a reason, such as
SameSite=NonewithoutSecure. - The cookie exists but is not sent. Compare its Domain, Path and SameSite values against the request URL and context.
- The script cannot read it. If HttpOnly is checked, this is expected, and
document.cookiewill not list it.
To test a logged-out state, right-click the cookie table and choose Clear, or select a single row and press Delete.
IndexedDB and Cache Storage
IndexedDB is a larger browser database for structured data. Expand it in the sidebar to see each database, its object stores and their records. Cache Storage holds request and response pairs, mostly written by service workers. Selecting a cache lists the cached URLs, and selecting an entry shows its headers and body preview. Both views are read-mostly. Use them to confirm that your code wrote what you expected.
Service workers
A service worker is a script that runs in the background and sits between the page and the network. It can intercept requests, answer them from a cache, and make a page work offline. Select Service workers in the sidebar to see the registration for the current origin.
The panel shows the script URL, its status, and the ID of the page it controls. Useful controls:
- Update on reload: installs the newest script on every reload, so you do not wait in the Waiting state.
- Bypass for network: sends requests to the network and skips the worker. Use it to tell whether a bug comes from the worker or from the server.
- Offline: simulates no connection to test your offline behavior.
- Unregister: removes the worker so the next load starts clean.
The most common service worker bug is a stale page. The old worker keeps serving cached files after you deploy a fix. The new worker sits in the Waiting state until every tab using the old one is closed. Turn on Update on reload, or click skipWaiting in the panel, while developing.
Clearing everything at once
Open Storage under Application. It shows how much space the origin uses and lets you clear it. Tick the data types, such as cookies, local storage, IndexedDB, Cache Storage and service workers, then click Clear site data. This gives a clean first-visit state, which is the one most users see once.
Exercise
A page reads a cookie named session with document.cookie, but the value never appears, even though the cookie is listed in the Application panel and is sent with each request. Which column should you check, and what is the likely cause?
Show answer
Check the HttpOnly column. If it is checked, the browser hides the cookie from page scripts, so document.cookie does not include it. The cookie is still sent to the server, which is its intended purpose.
Exercise
You deployed a fix, but reloading still shows the old version of the page. The Service workers section shows a second worker with the status "waiting". What is happening, and how do you get the new version during development?
Show answer
The old worker still controls the page and serves cached files. The new worker cannot activate until the old one is released. Turn on "Update on reload", or click skipWaiting, or close all tabs that use the old worker. Use "Bypass for network" to confirm the cache is the cause.