Allow SDKs to reattach to Stagehand runtimes
Merged
MO
3mo ago+87+87+01234567890123456789-5-5-0123456789
Summary
Allow a new SDK client to initialize an existing Stagehand extension runtime without replacing its browser session.
This lets stateless clients reconnect to a long-lived Browserbase session. Reinitialization updates the client configuration; closed runtimes and concurrent initialization still fail.
Summary by cubic
Allows SDK clients to reattach to an existing Stagehand runtime without replacing the browser session. Previously a second stagehand.init errored; now it succeeds, reuses the session, and updates initialization config. Closed runtimes still reject init; concurrent init still fails.
Review and rollout
- Second
stagehand.initnow returns{ initialized: true, pages: [] }and updates model/systemPrompt/telemetry;prepareForInitializationruns only on first init. - Closed runtimes throw “Stagehand has been closed and cannot be initialized again”; concurrent initialization still throws.
- Tests updated to cover reattach and closed-runtime behavior.
- Patch releases for
@browserbasehq/stagehand,@browserbasehq/stagehand-extension,@browserbasehq/stagehand-python, and@browserbasehq/stagehand-go; Go SDK bundle updated. - Migration: If clients relied on the previous error for repeat init, update them to treat a second
stagehand.initas a successful no-op that refreshes config.