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
Open
fix(browse): add --clear-storage flag to cookie-import-browser to prevent stale auth loops#1129msunda17 wants to merge 2 commits intogarrytan:mainfrom
msunda17 wants to merge 2 commits intogarrytan:mainfrom
Conversation
…event stale auth loops Fixes garrytan#1128
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.