{"record":{"id":"a259e5933c5065ce","repo":"mastra-ai/mastra","slug":"no-cdp-session-available","errorCode":null,"errorMessage":"No CDP session available","messagePattern":"No CDP session available","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"browser/stagehand/src/stagehand-browser.ts","lineNumber":1333,"sourceCode":"    }\n  }\n\n  // NOTE: Manual tab switching in browser UI is not fully supported.\n  // Stagehand v3 does not track pages opened via browser UI (only pages created through its API).\n  // We've requested this feature from Browserbase - see Notion doc for details.\n\n  // ---------------------------------------------------------------------------\n  // Event Injection (for Studio live view interactivity)\n  // ---------------------------------------------------------------------------\n\n  override async injectMouseEvent(event: MouseEventParams, threadId?: string): Promise<void> {\n    // Use the provided threadId, or fall back to the current thread\n    const effectiveThreadId = threadId ?? this.getCurrentThread();\n    const page = await this.threadManager.getPageForThread(effectiveThreadId);\n    const cdpSession = this.getCdpSessionForPage(page);\n\n    if (!cdpSession) {\n      throw new Error('No CDP session available');\n    }\n\n    // CDP buttons bitmask: left=1, right=2, middle=4\n    const buttonMap: Record<string, number> = {\n      none: 0,\n      left: 1,\n      middle: 4,\n      right: 2,\n    };\n\n    // clickCount should only default to 1 for press/release events; move and wheel use 0\n    const defaultClickCount = event.type === 'mousePressed' || event.type === 'mouseReleased' ? 1 : 0;\n\n    await cdpSession.send('Input.dispatchMouseEvent', {\n      type: event.type,\n      x: event.x,\n      y: event.y,\n      button: event.button ?? 'none',","sourceCodeStart":1315,"sourceCodeEnd":1351,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/browser/stagehand/src/stagehand-browser.ts#L1315-L1351","documentation":"Mouse input via CDP requires an attached CDP session for the target page. The library resolves the page for the (explicit or current) thread and asks for its CDP session; if absent it throws. Without the session, Input.dispatchMouseEvent cannot be sent to the browser.","triggerScenarios":"Calling CDP-based mouse actions (click at coordinates, etc.) when getCdpSessionForPage(page) returns null — no attached DevTools session for that thread's page, wrong threadId, or the page/session was lost after reconnect.","commonSituations":"Sending input to a thread whose page was closed; acting after browser reconnect invalidated sessions; using a threadId that has no page while the real page lives on another thread; page opened without CDP attach.","solutions":["Pass the correct threadId or ensure the current thread has an active page with a CDP session","Relaunch/reconnect the browser and retry to re-establish CDP sessions","Perform the action on a page opened through the library's normal API","Fall back to Stagehand-level actions (act/click) that do not need a raw CDP session"],"exampleFix":"// before\nawait browser.cdpMouseMove({ x: 100, y: 200 }, 'thread-B'); // thread-B has no page\n// after\nawait browser.cdpMouseMove({ x: 100, y: 200 }, 'thread-A'); // thread-A owns the page","handlingStrategy":"try-catch","validationCode":"if (!browser.isBrowserRunning() || !(await browser.getPage({ threadId }))) {\n  throw new Error('Thread has no live page; relaunch before CDP mouse input');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await browser.cdpClick({ x, y }, threadId);\n} catch (e) {\n  if (e instanceof Error && e.message === 'No CDP session available') {\n    await browser.reconnect();\n    await browser.cdpClick({ x, y }, threadId);\n  } else throw e;\n}","preventionTips":["Verify the threadId maps to a live page before CDP input","Re-establish sessions after any browser reconnect","Prefer Stagehand-level act/click APIs when raw CDP is not required","Do not cache thread IDs across browser restarts"],"tags":["browser","cdp","input","session"],"backgroundTag":"cdp-session-unavailable","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}