fix: load storage state at launch when --state / AGENT_BROWSER_STATE is set#1241
Merged
fix: load storage state at launch when --state / AGENT_BROWSER_STATE is set#1241
Conversation
…is set The `--state` flag and `AGENT_BROWSER_STATE` env var were documented as restoring saved browser state (cookies + localStorage) at launch, but `load_state()` was never called after the browser started. The feature has been broken since it was introduced. Adds `try_load_storage_state()` and calls it from every early-return path in `auto_launch()` (lazy launch triggered by commands like `navigate`) and from `handle_launch()` (explicit `launch` command). Also adds 4 e2e tests covering all state-persistence paths: - Explicit launch with `storageState` field - Auto-launch via `AGENT_BROWSER_STATE` env var - Session-name auto-restore via `try_auto_restore_state` - Explicit `state_load` command (baseline sanity check) Fixes #1164.
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Reformats a single long format\! call to satisfy CI's rustfmt check. No behavior change.
The CDP URL, CDP port, auto-connect, and provider early-return branches were skipping storage state loading because try_load_storage_state was only called in the normal BrowserManager::launch() path at the bottom of handle_launch(). Also compute storage_state_owned once and reuse it across all branches rather than borrowing storage_state (a &str tied to cmd) in a helper that needs an owned Option<String>.
Collaborator
|
Thanks @tomdale! |
Merged
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 #1164
The
--state <path>flag andAGENT_BROWSER_STATEenv var are documented as loading saved browser state (cookies + localStorage) at launch, butload_state()was never called after the browser started. The flag was fully plumbed through parsing, env propagation, and validation but the actual loading step was never wired up. This has been the case since the flag was introduced in the native Rust rewrite.Reproduction
Before (v0.25.4):
{"success": true, "data": {"cookies": []}, "error": null}After (this PR):
{"success": true, "data": {"cookies": [{"name": "test_cookie", "value": "hello_world", ...}]}, "error": null}Changes
handle_launch(): Callstate::load_state()with thestorageStatepath after browser launchauto_launch(): Extractstorage_statefromLaunchOptionsbefore the struct is moved, then calltry_load_storage_state()aftertry_auto_restore_state()in all four branches (CDP, auto-connect, provider, local Chrome)try_load_storage_state(): Encapsulates the load pattern to avoid duplication across branchesTest plan
e2e_state_flag_restores_cookies—storageStatein explicit launch command (was broken, now passes)e2e_state_env_restores_cookies_on_auto_launch—AGENT_BROWSER_STATEenv via auto-launch (was broken, now passes)e2e_session_name_auto_restores_cookies—--session-nameauto-save/restore (regression guard)e2e_explicit_state_load_restores_cookies— explicitstate loadcommand (baseline)