For AI agents and LLMs: a machine-readable index is available at llms.txt. A plain-Markdown version of any documentation page is available by appending .md to its URL.
Skip to main content

localStorage Assertions

localStorage assertions let you verify data stored in the browser's window.localStorage — check key existence, values, and item counts.

How Capture Works

localStorage is captured as a point-in-time snapshot when the checkpoint triggers:

  • On-demand capture: localStorage is read from the current page at the moment the assertion runs
  • Current state only: You see exactly what's in localStorage right now
  • Domain-scoped: localStorage is per-origin (protocol + domain + port). You only see data for the current page's origin
  • String values: All localStorage values are strings. If the application stores JSON objects, they're stored as JSON strings

Planning for Multi-Step Tests

Because localStorage is captured at assertion time:

  • Assert on localStorage while you're on the page that set the values — navigating to a different domain means a different localStorage
  • If values are needed later, extract and store them before navigating away
  • localStorage persists across steps (unlike network/console) as long as you stay on the same origin

JSON Values

Applications often store structured data in localStorage as JSON strings:

// Application code
localStorage.setItem("user_prefs", JSON.stringify({theme: "dark", lang: "en"}));

In assertions, the value is the raw JSON string. You can parse it to check individual fields:

Assert: the "theme" field in the user_prefs localStorage item is "dark"

KaneAI will parse the JSON and drill into the value automatically.

What You Can Query

MethodReturnsDescription
storage.all()dictAll key-value pairs
storage.get(key)string or NoneValue for a specific key
storage.keys()list of stringsAll key names
storage.has(key)boolWhether a key exists

Example Assertions

Assert: auth_token exists in localStorage
Assert: the theme preference in localStorage is "dark"
Assert: localStorage has fewer than 10 items
Assert: the user_id value in localStorage is not empty

Example Extractions

Store all localStorage items
Extract the auth_token from localStorage
Store the user preferences from localStorage
Get all localStorage keys

Example If/Else

If localStorage has "onboarding_complete" then show dashboard, else start onboarding

Test across 3000+ combinations of browsers, real devices & OS.

Book Demo

Help and Support

Related Articles