CKTIS / JavaScript
sessionStorage — tab-session storage
sessionStorage stores string key-value pairs for an origin and a tab session. It suits temporary state such as a form draft, but accessing storage or writing to it can fail.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
window.sessionStorage
sessionStorage.setItem(key, value)
sessionStorage.getItem(key)
sessionStorage.removeItem(key)
sessionStorage.clear()window.sessionStorage returns a Storage object associated with an origin and a tab session. Data survives page reloads. Unlike localStorage, it is not intended for state spanning sessions. Separate tabs have separate stores; a new auxiliary window can initially receive a copy of its opener's data, but subsequent changes are independent.
Operations are synchronous. setItem(key, value) stores text, getItem(key) returns text or null, and removeItem(key) deletes an entry. clear() deletes every entry in that store, not just one component's data — use it carefully.
Accessing sessionStorage can throw SecurityError, for example because of browser policy or an opaque origin. Writing can throw QuotaExceededError. Handle exceptions, and do not treat storage as the only copy of important data or as a place for secrets accessible to only one script.
This is a Web API defined in HTML, not a feature of a particular ECMAScript edition. The standard indicates support in all current browser engines; having Node 24 in a repository does not establish support for this browser API.
Examples
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Session storage access and draft values</title>
</head>
<body>
<script>
const frame = document.createElement('iframe');
frame.title = 'Session storage test';
frame.setAttribute('sandbox', 'allow-scripts');
frame.srcdoc = `<!doctype html>
<html lang="en">
<head><meta charset="utf-8"><title>Draft storage</title></head>
<body>
<p role="status"></p>
<script>
let message;
try {
const storage = window.sessionStorage;
const key = 'cktis:sessionStorage:draft';
const previous = storage.getItem(key);
try {
storage.setItem(key, 'draft');
const saved = storage.getItem(key);
storage.removeItem(key);
message = 'Saved: ' + saved + '; removed: ' + (storage.getItem(key) === null);
} finally {
if (previous === null) storage.removeItem(key);
else storage.setItem(key, previous);
}
} catch (error) {
message = 'Session storage unavailable: ' + error.name;
}
document.querySelector('[role="status"]').textContent = message;
console.log(message);
<\/script>
</body>
</html>`;
document.body.append(frame);
</script>
</body>
</html>Result
Session storage unavailable: SecurityError
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.