Skip to content

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

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

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

@hugs

hugs commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Thanks for this! The fix landed in #273, and your test is now in tests/cli/storage.test.js via #285. Appreciate it.

@hugs hugs closed this Aug 3, 2026
hugs added a commit that referenced this pull request Aug 3, 2026
vibium storage / storage restore had no test coverage at all, which is
how the double-encoding bug in #217 shipped and stayed unnoticed.

Covers the export shape, the restore round trip, and the unwrap that
keeps state files written in the old shape loading. All three fail
against the pre-#217 code.

Adapted from a test contributed by @Jhoan0714 in #218.
hugs added a commit that referenced this pull request Aug 3, 2026
vibium storage / storage restore had no test coverage at all, which is
how the double-encoding bug in #217 shipped and stayed unnoticed.

Covers the export shape, the restore round trip, and the unwrap that
keeps state files written in the old shape loading. All three fail
against the pre-#217 code.

Adapted from a test contributed by @Jhoan0714 in #218.
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

2 participants