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
model.apiKey.
Notes
- This is the v4 API (
localBrowser.connect,Stagehand.create). On 2.x the equivalent isnew 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.