What is the intended approach to having multiple, concurrent Stagehand sessions running from within one (async) app? #206
Unanswered
mikenerone
asked this question in
Q&A
Replies: 1 comment 1 reply
-
Hey Mike, Running multiple Stagehand/Browserbase sessions concurrently TL;DR
Why Browserbase supports many sessions (via bb.sessions.create + CDP). Docs emphasize using the default context/page (don’t create new ones). Signal handlers in Stagehand.init() make a single Stagehand-per-process awkward; avoid global, prefer one Stagehand client per session. Minimal example (ts)
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I want to run multiple Stagehand sessions from one (async) application. This is easy to do with Playwright (from a singleton
AsyncPlaywright
instance, you can create as manyBrowser
instances as you like vialaunch()
orconnect_over_cdp()
). Everything in Playwright (evenAsyncPlaywright
itself) is designed to be ephemeral. But there are conflicting signals about how to accomplish this with Stagehand:Aspects that suggest you're supposed to have a singleton
Stagehand
instance:AsyncPlaywright
is normally a singleton, so the fact thatinit()
creates and manages that instance gives the expectation that it's also a singleton.browserbase
client, you can, indeed, easily create as many sessions as you like This suggests the intent to support many sessions, so one would expect your ownStagehand
client to be able to use them.Stagehand.__init__()
installs its own signal handlers for the application. Setting aside the fact that libraries should not do this at all (because app developers may set their own signal handlers for a variety of reasons and you should not overwrite them; of course doing it for the separate browser process when running locally would be understandable, but that's not what happens here), it's certainly something you wouldn't do repeatedly. This one seems completely at odds with having multiple instances.Aspects that suggest you're meant to make a separate
Stagehand
instance for each browser session:current page
via theLivePageProxy
. This is completely at odds with having only a single instance when using multiple sessions.I guess the example I'd ask for is:
browserbase
client.stagehand
client for each of them, visiting three different URLs, however that's intended to look. I'd really like to see this with pre-created sessions similar to how one would normally use Browserbase with Playwright, rather than let theStagehand
wrapper abstract away the session creation.Beta Was this translation helpful? Give feedback.
All reactions