Skip to main content
Stagehand adds act, extract and observe on top of a browser it attaches to. With v4, connect it to a Driver session’s cdpUrl through localBrowser.connect.
TypeScript
Stagehand reads no environment variables. Pass the model provider key in model.apiKey.

Notes

  • This is the v4 API (localBrowser.connect, Stagehand.create). On 2.x the equivalent is new Stagehand({ env: "LOCAL", localBrowserLaunchOptions: { cdpUrl } }).
  • Stagehand injects scripts and drives the browser over CDP, which is what protected sites look for. On those sites use plain Patchright with explicit selectors.
  • Pin the Stagehand version you tested with. The connect API changed between 2.x and v4.
  • Reuse the page from browser.context.pages() instead of opening a new one.