interceptor_chrome_devtools_get_storage_value
Retrieve specific localStorage or sessionStorage values from Chrome DevTools sessions to inspect web application data during network traffic analysis.
Instructions
Get one localStorage/sessionStorage value by item_id.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| devtools_session_id | Yes | Session ID from interceptor_chrome_devtools_attach | |
| storage_type | Yes | Storage type | |
| item_id | Yes | item_id from interceptor_chrome_devtools_list_storage_keys | |
| origin | No | Optional origin override (must match current page origin) | |
| value_max_chars | No | Max characters for returned value (default: 20000) |
Implementation Reference
- src/tools/devtools.ts:1057-1160 (handler)The handler function for 'interceptor_chrome_devtools_get_storage_value' which retrieves a localStorage/sessionStorage value by item_id using Chrome DevTools Protocol.
"interceptor_chrome_devtools_get_storage_value", "Get one localStorage/sessionStorage value by item_id.", { devtools_session_id: z.string().describe("Session ID from interceptor_chrome_devtools_attach"), storage_type: z.enum(["local", "session"]).describe("Storage type"), item_id: z.string().describe("item_id from interceptor_chrome_devtools_list_storage_keys"), origin: z.string().optional().describe("Optional origin override (must match current page origin)"), value_max_chars: z.number().optional().default(HARD_VALUE_CAP_CHARS) .describe(`Max characters for returned value (default: ${HARD_VALUE_CAP_CHARS})`), }, async ({ devtools_session_id, storage_type, item_id, origin, value_max_chars }) => { try { const session = devToolsBridge.getSession(devtools_session_id); if (!session) { return { content: [{ type: "text", text: JSON.stringify({ status: "error", error: `DevTools session '${devtools_session_id}' not found.` }) }] }; } const parts = item_id.split("."); if (parts.length !== 4 || parts[0] !== "st") { return { content: [{ type: "text", text: JSON.stringify({ status: "error", error: `Invalid item_id '${item_id}'` }) }] }; } const itemType = parts[1]; const itemOrigin = fromBase64UrlUtf8(parts[2]); const itemKey = fromBase64UrlUtf8(parts[3]); if (itemType !== storage_type) { return { content: [{ type: "text", text: JSON.stringify({ status: "error", error: `item_id storage_type '${itemType}' does not match requested '${storage_type}'` }) }] }; } const { targetId } = await ensureSessionTargetIsAlive(devtools_session_id); const { pageUrl, wsUrl } = await getCdpPageEndpoint(targetId); const currentOrigin = getOriginFromUrl(pageUrl); if (!currentOrigin) { return { content: [{ type: "text", text: JSON.stringify({ status: "error", error: `No http(s) origin available for current page URL: '${pageUrl}'` }) }] }; } if (origin && origin !== currentOrigin) { return { content: [{ type: "text", text: JSON.stringify({ status: "error", error: `origin '${origin}' does not match current origin '${currentOrigin}'. Navigate first.` }), }], }; } if (itemOrigin !== currentOrigin) { return { content: [{ type: "text", text: JSON.stringify({ status: "error", error: `item_id origin '${itemOrigin}' does not match current origin '${currentOrigin}'. Navigate first.` }), }], }; } const maxChars = Math.max(0, Math.min(HARD_VALUE_CAP_CHARS, Math.trunc(value_max_chars ?? HARD_VALUE_CAP_CHARS))); const stType = storage_type; const expr = `(() => { try { const storageType = ${JSON.stringify(stType)}; const key = ${JSON.stringify(itemKey)}; const maxChars = ${maxChars}; const storage = storageType === "local" ? localStorage : sessionStorage; const raw = storage.getItem(key); const v = typeof raw === "string" ? raw : ""; const valueLength = v.length; const truncated = maxChars > 0 && valueLength > maxChars; const value = maxChars > 0 ? (truncated ? v.slice(0, maxChars) : v) : v; return { key, value, valueLength, truncated }; } catch (e) { return { error: String(e && e.message ? e.message : e) }; } })()`; const result = await cdpEvaluateValue(wsUrl, expr) as unknown; if (!result || typeof result !== "object") { throw new Error("Unexpected storage evaluation result."); } const obj = result as Record<string, unknown>; if (obj.error) { throw new Error(`Storage evaluation error: ${typeof obj.error === "string" ? obj.error : JSON.stringify(obj.error)}`); } return { content: [{ type: "text", text: truncateResult({ status: "success", devtools_session_id, target_id: targetId, origin: currentOrigin, storage_type: stType, item_id, key: obj.key ?? itemKey, value: typeof obj.value === "string" ? obj.value : "", value_length: typeof obj.valueLength === "number" ? obj.valueLength : null, value_truncated: typeof obj.truncated === "boolean" ? obj.truncated : null, value_max_chars: maxChars, }), }], }; } catch (e) { return { content: [{ type: "text", text: JSON.stringify({ status: "error", error: errorToString(e) }) }] }; } }, ); - src/tools/devtools.ts:1057-1160 (registration)Registration of the 'interceptor_chrome_devtools_get_storage_value' tool within the registerDevToolsTools function.
"interceptor_chrome_devtools_get_storage_value", "Get one localStorage/sessionStorage value by item_id.", { devtools_session_id: z.string().describe("Session ID from interceptor_chrome_devtools_attach"), storage_type: z.enum(["local", "session"]).describe("Storage type"), item_id: z.string().describe("item_id from interceptor_chrome_devtools_list_storage_keys"), origin: z.string().optional().describe("Optional origin override (must match current page origin)"), value_max_chars: z.number().optional().default(HARD_VALUE_CAP_CHARS) .describe(`Max characters for returned value (default: ${HARD_VALUE_CAP_CHARS})`), }, async ({ devtools_session_id, storage_type, item_id, origin, value_max_chars }) => { try { const session = devToolsBridge.getSession(devtools_session_id); if (!session) { return { content: [{ type: "text", text: JSON.stringify({ status: "error", error: `DevTools session '${devtools_session_id}' not found.` }) }] }; } const parts = item_id.split("."); if (parts.length !== 4 || parts[0] !== "st") { return { content: [{ type: "text", text: JSON.stringify({ status: "error", error: `Invalid item_id '${item_id}'` }) }] }; } const itemType = parts[1]; const itemOrigin = fromBase64UrlUtf8(parts[2]); const itemKey = fromBase64UrlUtf8(parts[3]); if (itemType !== storage_type) { return { content: [{ type: "text", text: JSON.stringify({ status: "error", error: `item_id storage_type '${itemType}' does not match requested '${storage_type}'` }) }] }; } const { targetId } = await ensureSessionTargetIsAlive(devtools_session_id); const { pageUrl, wsUrl } = await getCdpPageEndpoint(targetId); const currentOrigin = getOriginFromUrl(pageUrl); if (!currentOrigin) { return { content: [{ type: "text", text: JSON.stringify({ status: "error", error: `No http(s) origin available for current page URL: '${pageUrl}'` }) }] }; } if (origin && origin !== currentOrigin) { return { content: [{ type: "text", text: JSON.stringify({ status: "error", error: `origin '${origin}' does not match current origin '${currentOrigin}'. Navigate first.` }), }], }; } if (itemOrigin !== currentOrigin) { return { content: [{ type: "text", text: JSON.stringify({ status: "error", error: `item_id origin '${itemOrigin}' does not match current origin '${currentOrigin}'. Navigate first.` }), }], }; } const maxChars = Math.max(0, Math.min(HARD_VALUE_CAP_CHARS, Math.trunc(value_max_chars ?? HARD_VALUE_CAP_CHARS))); const stType = storage_type; const expr = `(() => { try { const storageType = ${JSON.stringify(stType)}; const key = ${JSON.stringify(itemKey)}; const maxChars = ${maxChars}; const storage = storageType === "local" ? localStorage : sessionStorage; const raw = storage.getItem(key); const v = typeof raw === "string" ? raw : ""; const valueLength = v.length; const truncated = maxChars > 0 && valueLength > maxChars; const value = maxChars > 0 ? (truncated ? v.slice(0, maxChars) : v) : v; return { key, value, valueLength, truncated }; } catch (e) { return { error: String(e && e.message ? e.message : e) }; } })()`; const result = await cdpEvaluateValue(wsUrl, expr) as unknown; if (!result || typeof result !== "object") { throw new Error("Unexpected storage evaluation result."); } const obj = result as Record<string, unknown>; if (obj.error) { throw new Error(`Storage evaluation error: ${typeof obj.error === "string" ? obj.error : JSON.stringify(obj.error)}`); } return { content: [{ type: "text", text: truncateResult({ status: "success", devtools_session_id, target_id: targetId, origin: currentOrigin, storage_type: stType, item_id, key: obj.key ?? itemKey, value: typeof obj.value === "string" ? obj.value : "", value_length: typeof obj.valueLength === "number" ? obj.valueLength : null, value_truncated: typeof obj.truncated === "boolean" ? obj.truncated : null, value_max_chars: maxChars, }), }], }; } catch (e) { return { content: [{ type: "text", text: JSON.stringify({ status: "error", error: errorToString(e) }) }] }; } }, );