Skip to content

Fix - vibium storage restore fails to restore localStorage/sessionStorage#218

Open
Jhoan0714 wants to merge 4 commits into
VibiumDev:mainfrom
Jhoan0714:fix/storage-restore-double-encoding
Open

Fix - vibium storage restore fails to restore localStorage/sessionStorage#218
Jhoan0714 wants to merge 4 commits into
VibiumDev:mainfrom
Jhoan0714:fix/storage-restore-double-encoding

Conversation

@Jhoan0714

@Jhoan0714 Jhoan0714 commented Jul 8, 2026

Copy link
Copy Markdown

Summary

This PR fixes #217browserStorageState double-encoded the exported storage state, so vibium storage restore silently failed to restore localStorage/sessionStorage even though it reported success.

Root Cause

browserStorageState in clicker/internal/agent/handlers.go ran a script that already calls JSON.stringify(...) in the browser, and then embedded that resulting string directly into the exported state map before a second json.MarshalIndent pass — so the "storage" field ended up as an escaped JSON string instead of a nested JSON object. browserRestoreStorage interpolates that field directly into var state = %s; when restoring, so the escaped string became a JS string literal instead of an object, and state.localStorage/state.sessionStorage were undefined — nothing was restored, with no error reported.

Why this matters

  • vibium storage / vibium storage restore are the only CLI/MCP commands for saving and reusing browser session state (e.g. login sessions) across runs — this bug made that workflow completely non-functional
  • The failure is silent: the CLI prints "Storage state restored" with no indication anything went wrong
  • No impact on Python/JS/Java clients — context.storage()/context.setStorage() use a separate, unaffected wire-API code path (vibium:context.storage/setStoragehandleContextStorage in clicker/internal/api/handlers_storage.go)

Validation

Executed:

vibium go "https://sahitest.com/demo/training/books.htm"
vibium eval "localStorage.setItem('user', 'alice')"
vibium eval "sessionStorage.setItem('session_id', 'abc123')"
vibium storage -o state.json
cat state.json
vibium eval "localStorage.clear(); sessionStorage.clear();"
vibium storage restore state.json
vibium eval "localStorage.getItem('user')"
vibium eval "sessionStorage.getItem('session_id')"

Before fix — state.json had "storage" as an escaped string, and restore silently failed:

{
  "cookies": [],
  "storage": "{\"origin\":\"https://sahitest.com\",\"localStorage\":{\"user\":\"alice\"},\"sessionStorage\":{\"session_id\":\"abc123\"}}"
}
localStorage.getItem('user')          = null
sessionStorage.getItem('session_id')  = null

After fix — state.json has "storage" as a real nested object, and restore works:

{
  "cookies": [],
  "storage": {
    "localStorage": {
      "user": "alice"
    },
    "origin": "https://sahitest.com",
    "sessionStorage": {
      "session_id": "abc123"
    }
  }
}
localStorage.getItem('user')          = alice
sessionStorage.getItem('session_id')  = abc123

Test added:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vibium storage restore silently fails to restore localStorage/sessionStorage

1 participant