Skip to content

fix(browse): add --clear-storage flag to cookie-import-browser to prevent stale auth loops#1129

Open
msunda17 wants to merge 2 commits intogarrytan:mainfrom
msunda17:add-clear-storage-flag
Open

fix(browse): add --clear-storage flag to cookie-import-browser to prevent stale auth loops#1129
msunda17 wants to merge 2 commits intogarrytan:mainfrom
msunda17:add-clear-storage-flag

Conversation

@msunda17
Copy link
Copy Markdown

@msunda17 msunda17 commented Apr 21, 2026

Fixes #1128

Title: fix: add --clear-storage flag to cookie-import-browser

Description:

What this PR does: Adds a new --clear-storage opt-in CLI flag to the cookie-import-browser command.

Why it's needed: Fixes #1128. Certain modern auth SDKs (like Clerk, Auth0, Firebase) persist authentication environment meta-data across both cookies and localStorage. In scenarios like major Clerk SDK upgrades (e.g., v5 → v7), refreshing the cookies via /setup-browser-cookies while leaving a stale version payload sitting in localStorage causes the browser session to enter an infinite redirect loop when the client tries to reconcile the mismatched state.

How it works: If the --clear-storage flag is appended to the command, the automation will explicitly inject a Playwright page.evaluate() hook to run localStorage.clear(); sessionStorage.clear(); on the target origin immediately before injecting the fresh session cookies.

Architectural Decision: While the original issue proposed clearing storage as the default behavior with a --keep-storage opt-out, altering the default behavior of an established data-import utility introduces unnecessary breaking-change risks for workflows heavily dependent on localStorage state. Instead, this implements the fix as a highly-explicit opt-in --clear-storage command, guaranteeing backward compatibility.

Testing:

Verified localStorage and sessionStorage are completely wiped when passing --clear-storage.
Verified default execution is totally untouched (storage is preserved).
Internal test suites (browse/test/cookie-import-browser.test.ts) assert successfully.

@msunda17 msunda17 changed the title feat(browse): add --clear-storage flag to cookie-import-browser to prevent stale auth loops fix(browse): add --clear-storage flag to cookie-import-browser to prevent stale auth loops Apr 21, 2026
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.

cookie-import-browser should clear localStorage/sessionStorage before importing

1 participant