error with observe "Node with given id does not belong to the document"
Thank you for this great project. I get this error on different web sites when using observe() on the last versions of stagehand. (v1.11 works fine) I 'm on MACOS
Here is the catched error :
error observing
cdpSession.send: Protocol error (DOM.resolveNode): Node with given id does not belong to the document
cdpSession.send: Protocol error (DOM.resolveNode): Node with given id does not belong to the document
at _StagehandPage.
cdpSession.send: Protocol error (DOM.resolveNode): Node with given id does not belong to the document
at _StagehandPage.
Thanks so much for taking the time to try Stagehand! Looking into this -- do you have a script we can use to repro?
Here is an example using stagehand 1.14 with ollama. I tested with several models and obtained the same error.
export async function main({ page, context, stagehand, }: { page: Page; // Playwright Page with act, extract, and observe methods context: BrowserContext; // Playwright BrowserContext stagehand: Stagehand; // Stagehand instance }) { globalThis.stagehand = new Stagehand({ ...StagehandConfig, llmClient: new OllamaClient({ modelName: "qwen2.5:7b", clientOptions: { }, }), }); await globalThis.stagehand.init(); await stagehand.page.goto("https://iut.uca.fr/"); const observations = await globalThis.stagehand.page.observe({ instruction: "Find all the button on this page", returnAction: false }); console.log(observations); }
Many thanks
same here with this input prompt:
input prompt
Accessibility Tree: [ 1 ] RootWebArea: Stagehand SDK Reference - 🤘 Stagehand\n [ 2 ] scrollable\n [ 3 ] body\n [ 6 ] main\n [ 11 ] div\n [ 12 ] div\n [ 15 ] scrollable\n [ 20 ] div\n [ 49 ] link: 🤘 Stagehand home page light logo\n [ 84 ] span\n [ 149 ] StaticText: 🤘 Stagehand\n [ 150 ] StaticText: home page\n [ 85 ] image: light logo\n [ 33 ] button: Toggle dark mode\n [ 50 ] image\n [ 21 ] button: Search or ask... Ctrl K\n [ 34 ] div\n [ 52 ] image\n [ 94 ] StaticText: Search or ask...\n [ 35 ] span\n [ 54 ] StaticText: Ctrl \n [ 55 ] StaticText: K\n [ 22 ] div\n [ 36 ] div\n [ 56 ] listitem\n [ 95 ] link: Changelog\n [ 57 ] listitem\n [ 96 ] link: Reference\n [ 37 ] div\n [ 58 ] heading: Get Started\n [ 59 ] list\n [ 98 ] listitem\n [ 164 ] link: What is Stagehand?\n [ 99 ] listitem\n [ 165 ] link: Quickstart\n [ 100 ] listitem\n [ 166 ] link: Install Stagehand\n [ 38 ] div\n [ 60 ] heading: Concepts\n [ 61 ] list\n [ 102 ] listitem\n [ 167 ] link: Interact with a website\n [ 103 ] listitem\n [ 168 ] link: Build a web browsing agent\n [ 39 ] div\n [ 62 ] heading: Playbooks\n [ 63 ] list\n [ 105 ] listitem\n [ 169 ] link: Best Practices\n [ 106 ] listitem\n [ 170 ] link: Caching Actions\n [ 107 ] listitem\n [ 171 ] link: Telemetry and Evaluations\n [ 108 ] listitem\n [ 172 ] link: Stagehand in Next.js\n [ 109 ] listitem\n [ 173 ] link: LLM Customization\n [ 110 ] listitem\n [ 174 ] link: Browser Customization\n [ 111 ] listitem\n [ 175 ] link: Computer Use Agents\n [ 112 ] listitem\n [ 176 ] link: Contribute to Stagehand\n [ 40 ] div\n [ 64 ] heading: Integrations\n [ 65 ] list\n [ 114 ] listitem\n [ 177 ] link: Langchain JS\n [ 115 ] listitem\n [ 178 ] link: Windsurf Integration\n [ 116 ] listitem\n [ 179 ] link: MCP Server\n [ 117 ] listitem\n [ 180 ] link: Cursor Integration\n [ 118 ] listitem\n [ 181 ] link: Cline Integration\n [ 119 ] listitem\n [ 182 ] link: Claude Code\n [ 41 ] div\n [ 66 ] heading: Reference\n [ 67 ] list\n [ 121 ] listitem\n [ 183 ] link: Configuration\n [ 122 ] listitem\n [ 184 ] link: Agent\n [ 123 ] listitem\n [ 185 ] link: Act\n [ 124 ] listitem\n [ 186 ] link: Extract\n [ 125 ] listitem\n [ 187 ] link: Observe\n [ 126 ] listitem\n [ 188 ] link: Playwright Interoperability\n [ 16 ] list\n [ 23 ] listitem\n [ 42 ] link: Support\n [ 69 ] image\n [ 18 ] div\n [ 26 ] HeaderAsNonLandmark\n [ 132 ] heading: Stagehand SDK Reference\n [ 72 ] paragraph\n [ 133 ] StaticText: View each method in the Stagehand SDK and learn how to use them.\n [ 46 ] div\n [ 73 ] link: Configuration Configure Stagehand the way you want.\n [ 196 ] div\n [ 270 ] heading: Configuration\n [ 331 ] paragraph\n [ 389 ] StaticText: Configure Stagehand the way you want.\n [ 74 ] link: Agent Web AI agents for any task\n [ 199 ] div\n [ 274 ] heading: Agent\n [ 335 ] paragraph\n [ 390 ] StaticText: Web AI agents for any task\n [ 75 ] link: Act Perform actions on the current page.\n [ 202 ] div\n [ 278 ] heading: Act\n [ 339 ] paragraph\n [ 391 ] StaticText: Perform actions on the current page.\n [ 76 ] link: Extract Extract structured data from the page.\n [ 205 ] div\n [ 282 ] heading: Extract\n [ 343 ] paragraph\n [ 392 ] StaticText: Extract structured data from the page.\n [ 77 ] link: Observe Get candidate DOM elements for actions.\n [ 208 ] div\n [ 286 ] heading: Observe\n [ 347 ] paragraph\n [ 393 ] StaticText: Get candidate DOM elements for actions.\n [ 78 ] link: Playwright Interoperability Combine Stagehand with Playwright.\n [ 211 ] div\n [ 290 ] heading: Playwright Interoperability\n [ 351 ] paragraph\n [ 394 ] StaticText: Combine Stagehand with Playwright.\n [ 30 ] FooterAsNonLandmark\n [ 47 ] div\n [ 79 ] link: x\n [ 80 ] link: github\n [ 81 ] link: linkedin\n [ 82 ] link: slack\n [ 148 ] link: Powered by Mintlify\n [ 7 ] alert\n"
LLM response:
"message": {
"role": "assistant",
"content": "{\"elements\": [{\"elementId\": 21, \"description\": \"Search or ask... Ctrl K\", \"method\": \"click\", \"arguments\": []}]}"
}
stagehand report error: Node with given id does not belong to the document
but as you can see, elementId 21 is present
same here with this input prompt:
input prompt LLM response:
"message": { "role": "assistant", "content": "{\"elements\": [{\"elementId\": 21, \"description\": \"Search or ask... Ctrl K\", \"method\": \"click\", \"arguments\": []}]}" }stagehand report error:
Node with given id does not belong to the documentbut as you can see, elementId 21 is present
Only happens when I use my own browser. When I use a brand new chromium browser (under ms-playwright), it works fine.