{"record":{"id":"5b85c822ed0cb8c8","repo":"mastra-ai/mastra","slug":"no-cdp-session-available-for-page","errorCode":null,"errorMessage":"No CDP session available for page","messagePattern":"No CDP session available for page","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"browser/stagehand/src/stagehand-browser.ts","lineNumber":1031,"sourceCode":"  // Screencast (for Studio live view)\n  // Uses Stagehand v3's native CDP access\n  // ---------------------------------------------------------------------------\n\n  override async startScreencast(options?: ScreencastOptions): Promise<ScreencastStream> {\n    const threadId = options?.threadId;\n\n    // Create a CDP session provider that gets a fresh session for the current page\n    // On reconnect, this will get a fresh CDP session for whatever page is currently active\n    const provider = {\n      getCdpSession: async () => {\n        const page = await this.threadManager.getPageForThread(threadId);\n        if (!page) {\n          throw new Error('No page available for screencast');\n        }\n\n        const session = this.getCdpSessionForPage(page);\n        if (!session) {\n          throw new Error('No CDP session available for page');\n        }\n\n        return session;\n      },\n      isBrowserRunning: () => this.isBrowserRunning(),\n    };\n\n    const stream = new ScreencastStreamImpl(provider, options);\n\n    // Store the stream for potential future reconnection - keyed by thread\n    const streamKey = this.getStreamKey(threadId);\n    this.activeScreencastStreams.set(streamKey, stream);\n\n    await stream.start();\n\n    // Set up tab change detection\n    await this.setupTabChangeDetection(threadId, stream);\n","sourceCodeStart":1013,"sourceCodeEnd":1049,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/browser/stagehand/src/stagehand-browser.ts#L1013-L1049","documentation":"Same lazy CDP-session provider as the screencast path: after obtaining a page, the library looks up a CDP session via getCdpSessionForPage. If none exists — the page has no attached DevTools session — the provider throws. A CDP session is required to stream screencast frames.","triggerScenarios":"getCdpSession invoked for a page that was never attached via CDP, or whose CDP session was detached (navigation to new target, browser reconnect, session cleanup).","commonSituations":"Screencast surviving a page navigation/target change that invalidated the old session; browser reconnect created a new page without reattaching; page opened outside the library's CDP attach path.","solutions":["Restart the screencast so a fresh CDP session is created for the current page","Reconnect/relaunch the browser if sessions were detached by a reconnect","Ensure the page was opened through the library so it gets a CDP session","Verify getCdpSessionForPage coverage — check browser/CDP attach logs"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (!browser.isBrowserRunning()) {\n  await browser.reconnect(); // re-attach CDP sessions before screencasting\n}","typeGuard":null,"tryCatchPattern":"try {\n  await browser.startScreencast({ threadId });\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('No CDP session')) {\n    await browser.reconnect();\n    await browser.startScreencast({ threadId });\n  } else throw e;\n}","preventionTips":["Restart screencasts after page navigations/target changes invalidate sessions","Open pages through the library API so CDP attach happens automatically","Reconnect the browser after network drops before resuming CDP-dependent features","Monitor for detached-session events if the library exposes them"],"tags":["browser","cdp","screencast","session"],"backgroundTag":"cdp-session-unavailable","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}