Every Handstage session starts with aDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/l-xiaoshen/handstage/llms.txt
Use this file to discover all available pages before exploring further.
V3 instance — the top-level handle that owns the CDP connection to a running Chrome process. From there, you work through one or more V3Context objects that manage pages, cookies, and storage. Understanding the relationship between these two layers lets you build multi-session automation flows without state leaking between them.
The V3 class
V3 is the entry point for connecting to a browser. It launches or attaches to a local Chrome instance over the Chrome DevTools Protocol (CDP) and exposes a default context through its context property.
V3.connectLocal() accepts an optional HandstagesLocalOptions object that controls viewport size, proxy settings, locale, headless mode, and more.
The V3Context class
AV3Context owns the CDP session and is responsible for:
- Creating and tracking top-level pages (browser tabs)
- Holding cookies and local storage for a browser profile
- Managing init scripts that run on every new document
- Routing CDP target events to the correct page
browserContextId — a string Chrome uses to route targets and storage commands to the right profile. You read it from context.browserContextId.
Default context vs isolated contexts
When you callV3.connectLocal(), Handstage resolves the browser’s default context and wraps it in a V3Context with isDefaultContext: true. All pages in the default context share the same cookie jar and storage.
If you need isolated sessions — for example, to simulate two different logged-in users — create a dedicated context with browser.create(). Dedicated contexts behave like incognito profiles: they share the same CDP connection but have completely separate cookies, local storage, and session state.
Init scripts and extra HTTP headers are not inherited by isolated contexts. Call
context.addInitScript() and context.setExtraHTTPHeaders() on each context that needs them.Creating multiple isolated contexts
You can create as many isolated contexts as you need. Each one callsTarget.createBrowserContext on the CDP connection and returns a fully independent V3Context.
The disposeOnDetach option
When you create an isolated context, disposeOnDetach defaults to true. This instructs Chrome to automatically clean up the context and its storage if the CDP connection drops unexpectedly, which prevents orphaned browser profiles on crash.
false if you want the context to persist across reconnections, but you are then responsible for calling isolated.close() to release the resources.
The keepAlive option
By default, closing the V3 instance kills the Chrome process it launched. Pass keepAlive: true in HandstagesLocalOptions to leave Chrome running after your script exits. This is useful in CI pipelines where a single browser instance is shared across multiple test runs.
Shutdown supervisor
WhenkeepAlive is false (the default), Handstage spawns a lightweight crash-only shutdown supervisor as a separate process. The supervisor monitors the main process PID and cleans up the Chrome process plus any temporary profile directories if the main process exits unexpectedly — for example, due to an unhandled exception or SIGKILL.
On a normal browser.close() call, the supervisor is stopped first, then Chrome is killed gracefully, and temporary profile directories are removed.
Closing resources
Close isolated contexts
Call
context.close() on each dedicated context you created. This disposes the browser context in Chrome and releases all per-page resources like network managers and console handlers.browser.close() will attempt a best-effort close of all tracked children before tearing down the connection.