Local sessions
For local sessions, pointlocalBrowser.launch() at a user data directory. Stagehand creates the directory if it does not exist and leaves it in place after the browser shuts down, so the next run starts from the same cookies and local storage:
- TypeScript
- Python
- Go
When no user data directory is set, Stagehand launches Chrome against a temporary profile and deletes it on shutdown, so cookies and local storage do not carry over between runs. A directory you pass yourself is kept either way, so the setup above needs nothing extra.
- TypeScript
- Python
- Go
preserveUserDataDir keeps the generated temporary directory after shutdown when you turn it on.Browserbase sessions
For Browserbase sessions, use contexts to persist browser data:- TypeScript
- Python
- Go

