Sub topic 7
Inspecting storage, cookies and service workers
This chapter covers the Application panel in Chromium-based browsers. It assumes you can read basic JavaScript, understand HTTP requests and responses, and know how the Network panel lists requests from the previous chapter. Firefox calls the equivalent tool the Storage Inspector, and Safari calls it the Storage tab. The ideas below carry over, but the layout differs.
What the Application panel shows
The Network panel shows data in motion. The Application panel shows data a page has left behind in the browser: cookies, key-value storage, databases, cached responses, and the background scripts that control caching. When a bug looks like "it works in a private window but not in my normal one," or "I changed the code but still see the old version," this panel is usually where you look.
The left sidebar groups its tools into sections.
| Section | What it contains | Typical question it answers |
|---|---|---|
| Manifest | Web app manifest, icons, install criteria | Why is my app not installable? |
| Service workers | Registered workers and their state | Why is the old version still served? |
| Storage | Usage and quota, and a button to clear everything | How much space is this origin using? |
| Local storage, Session storage | Key-value pairs of strings | What did my code save? |
| IndexedDB | Object stores and records | What is in my client-side database? |
| Cookies | Cookies per origin, with attributes | Is the session cookie sent? |
| Cache storage | Responses stored by the Cache API | What did my service worker cache? |
Storage is partitioned by origin. An origin is the combination of scheme, host and port, so https://example.com and http://example.com:8080 have separate local storage and separate cookie scoping rules. The panel shows data for the origin of the page you inspect, and it lists frames' origins separately when a page embeds other sites.
Local storage and session storage
Both are string-only key-value stores exposed through the Web Storage API. They differ in lifetime.
localStoragepersists until your code or the user clears it. It is shared by all tabs on the same origin.sessionStoragelasts for one tab. It is cleared when that tab closes, and a new tab on the same site gets its own copy.
Open Application > Local storage, then choose the origin. You see a table of keys and values. You can double-click a value to edit it, add a row, delete a row with the Delete key, or use the filter box to search. Edits take effect immediately, so you can test how your code behaves with a missing key or a corrupted value without writing code.
A useful check is to read the same data from the Console and compare it with the table.
localStorage.setItem('theme', 'dark');
localStorage.setItem('cart', JSON.stringify([{ id: 7, qty: 2 }]));
console.log(localStorage.getItem('theme')); // "dark"
console.table(JSON.parse(localStorage.getItem('cart'))); // parsed array
console.log(localStorage.length); // number of keysAfter running this, refresh the Local storage view. The two keys appear. The cart value displays as a JSON string, because Web Storage cannot hold objects directly.
Common errors with Web Storage
- Forgetting that values are strings.
localStorage.setItem('count', 5)stores"5". Reading it back and adding 1 gives"51". Convert withNumber()orJSON.parse. - Storing an object without serializing.
localStorage.setItem('user', {name: 'Ada'})stores the text[object Object]. The table makes this mistake obvious. - Parsing a missing key.
JSON.parse(localStorage.getItem('x'))returnsnullfor a missing key, butJSON.parse(undefined)throws. Edit or delete a key in the panel to test this path. - Hitting the quota. Browsers allow roughly 5 MB per origin for Web Storage, and writing past that throws a
QuotaExceededError. Wrap large writes intry/catch. - Assuming it is private or secure. Any script running on the page can read it, including injected scripts. Do not keep authentication tokens there if you can use an
HttpOnlycookie instead.
Cookies
A cookie is a small piece of data the server sets with a Set-Cookie response header (or that script sets with document.cookie). The browser then attaches matching cookies to later requests in a Cookie header. Open Application > Cookies and choose an origin to see a table with these columns.
| Column | Meaning |
|---|---|
| Name, Value | The cookie's contents |
| Domain, Path | Which requests the cookie is sent with |
| Expires / Max-Age | When it is deleted. A value of "Session" means when the browser closes |
| Size | Bytes used by name and value |
| HttpOnly | If checked, scripts cannot read it through `document.cookie` |
| Secure | If checked, it is sent only over HTTPS |
| SameSite | `Strict`, `Lax` or `None`. Controls whether it is sent on cross-site requests |
| Partition Key | Set for partitioned cookies (CHIPS), which are isolated per top-level site |
| Priority | Eviction priority when the browser has too many cookies |
Select a row to see its decoded value in the preview pane below the table. You can edit most columns by double-clicking, delete a cookie, or clear all cookies for the origin with the clear button in the toolbar.
Diagnosing a cookie that is not being sent
A frequent problem is a login that appears to succeed and then fails on the next request. Work through these checks in order.
- In the Network panel, select the response that should set the cookie. In the Headers tab, look at
Set-Cookie. A yellow warning icon next to it explains why the browser rejected it. - In Application > Cookies, confirm the cookie exists. If it does not, the browser rejected it.
- Compare the cookie's
DomainandPathwith the failing request's URL. A cookie withPath=/apiis not sent to/images. - Check
Secure. ASecurecookie is not sent tohttp://pages (exceptlocalhostin most browsers). - Check
SameSite. A request triggered from another site, such as an embedded iframe or a form posted from elsewhere, does not carryLaxorStrictcookies. ASameSite=Nonecookie must also beSecure. - Select the failing request in the Network panel and open its Cookies tab. It lists which cookies were sent and which were blocked, with a reason for each blocked one.
You can also set a cookie from the Console to reproduce a state quickly.
document.cookie = 'debug=1; path=/; max-age=3600; SameSite=Lax';
console.log(document.cookie); // includes "debug=1" (HttpOnly cookies are omitted)IndexedDB and Cache storage
IndexedDB is a transactional database in the browser. It holds structured objects, supports indexes, and has a much larger quota than Web Storage. In the panel, expand a database to see its object stores. Selecting a store shows its records, and you can refresh, delete a record, or clear the store. Expand a store to see its indexes. Use this view to confirm that a write actually committed, and to check the schema version after a migration. If a version upgrade is blocked because another tab holds the old connection open, closing other tabs of the site usually resolves it.
Cache storage shows caches created through the Cache API, which service workers commonly use. Each cache lists request URLs. Select an entry to preview the stored response, including its headers. A stale entry here explains why a changed file does not update.
Service workers
A service worker is a script that the browser runs in the background, separate from the page. It sits between the page and the network and can intercept fetch requests. This lets it serve cached responses, which enables offline use and fast loads.
A worker has a lifecycle with distinct states.
The important rule is that a new version waits while an older version still controls open pages. The page keeps using the old worker until every tab using it closes, or until the new worker calls skipWaiting(). This is the most common reason developers see old code after deploying.
A minimal example
Register the worker from the page:
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js')
.then(reg => console.log('registered, scope:', reg.scope))
.catch(err => console.error('registration failed', err));
}Then write /sw.js, which caches a few files and answers requests from the cache first:
const CACHE = 'app-v1';
const ASSETS = ['/', '/styles.css', '/app.js'];
self.addEventListener('install', event => {
event.waitUntil(caches.open(CACHE).then(cache => cache.addAll(ASSETS)));
});
self.addEventListener('activate', event => {
event.waitUntil(
caches.keys().then(keys =>
Promise.all(keys.filter(k => k !== CACHE).map(k => caches.delete(k)))
)
);
});
self.addEventList {
event.respondWith(
caches.match(event.request).then(hit => hit || fetch(event.request))
);
});Service workers require HTTPS, an exception for localhost during development.
Using the Service workers pane
Open Application > Service workers. For each registration you see the script URL, its status, and the source (the time it was received). The controls are:
- Update on reload. Fetches the worker script on every reload and activates it immediately. Turn this on during development so you do not need to close tabs between edits.
- Bypass for network. Makes page requests skip the worker and go straight to the network. Use it to tell whether a bug comes from your page or from your caching logic.
- Offline. Simulates having no network, so you can test your offline path.
- Update, Push, Sync. Trigger an update check, or dispatch a test
pushorsyncevent to the worker. - skipWaiting. Appears when a new worker is waiting. Clicking it activates that worker.
- Unregister. Removes the registration.
- Inspect / source link. Opens the worker's own DevTools context, where you can set breakpoints in
sw.jsand see its Console output. Worker logs do not appear in the page's Console.
In the Network panel, requests answered by the worker show "(ServiceWorker)" in the Size column and a gear icon in the Name column. If you see these during a bug hunt, the response did not come from the server.
Common service worker errors
- Old code after a deploy. A new worker is waiting. Check for a waiting entry in the pane and use skipWaiting, or close all tabs.
- Caching the worker script itself or serving it with a long
Cache-Control. The browser bypasses the HTTP cache for the worker script in most cases, but treat the script as uncacheable anyway. - Scope too narrow. A worker at
/js/sw.jscontrols only/js/by default. Serve it from the root, or send aService-Worker-Allowedheader. - Cache growth. Without the
activatecleanup shown above, old caches stay forever. Cache storage shows them. - Cache-first for HTML. If the HTML itself is cache-first, users keep an old page and its old script references.
Clearing state
Many bugs come from leftover state, so a clean slate is a useful test. Under Application > Storage, the Clear site data button removes cookies, local and session storage, IndexedDB, Cache storage and service worker registrations for the origin. Its checkboxes let you keep some. Tick "Including third-party cookies" to also remove cookies set by embedded sites.
You can also right-click a reload button with DevTools open and choose Empty cache and hard reload, which clears the HTTP cache for that load but does not remove storage or unregister workers.
A repeatable workflow
- Reproduce the problem and note whether it depends on state (works in Incognito, fails normally).
- Open Application and inspect the relevant store: cookies for sessions, Local storage for preferences, Service workers and Cache storage for stale content.
- Change one value in the panel and repeat the action to confirm the cause.
- Fix the code, then use Clear site data to confirm the fix works from a clean start.
Exercise
After you deploy a new version of your site, a colleague reports that they still see the old design. The Network panel shows the stylesheet request marked "(ServiceWorker)". Which panes in the Application panel would you check, and what would you do to confirm the cause and fix it for your own browser?
Show answer
Open Service workers. A new worker is probably listed as waiting while the old one still controls the page. Click skipWaiting (or enable Update on reload) to activate it. Then open Cache storage and check whether the old cache still holds the previous stylesheet. To confirm the cause, enable Bypass for network and reload: if the new design appears, the service worker's cache is serving stale files. For a permanent fix, version the cache name and delete old caches in the activate handler.
Exercise
A user logs in, but the next API request to /api/profile returns 401. In Application > Cookies you see a session cookie with Path /auth. What is wrong, and where else in DevTools can you confirm which cookies were sent?
Show answer
The cookie's Path is /auth, so the browser does not send it to /api/profile. Set the cookie's Path to / (or /api) on the server. To confirm, select the failing request in the Network panel and open its Cookies tab, which lists the cookies sent and any that were blocked, with reasons.