mastra-ai/mastra · error
No CDP session available for page
Error message
No CDP session available for page
What it means
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.
Source
Thrown at browser/stagehand/src/stagehand-browser.ts:1031
// Screencast (for Studio live view)
// Uses Stagehand v3's native CDP access
// ---------------------------------------------------------------------------
override async startScreencast(options?: ScreencastOptions): Promise<ScreencastStream> {
const threadId = options?.threadId;
// Create a CDP session provider that gets a fresh session for the current page
// On reconnect, this will get a fresh CDP session for whatever page is currently active
const provider = {
getCdpSession: async () => {
const page = await this.threadManager.getPageForThread(threadId);
if (!page) {
throw new Error('No page available for screencast');
}
const session = this.getCdpSessionForPage(page);
if (!session) {
throw new Error('No CDP session available for page');
}
return session;
},
isBrowserRunning: () => this.isBrowserRunning(),
};
const stream = new ScreencastStreamImpl(provider, options);
// Store the stream for potential future reconnection - keyed by thread
const streamKey = this.getStreamKey(threadId);
this.activeScreencastStreams.set(streamKey, stream);
await stream.start();
// Set up tab change detection
await this.setupTabChangeDetection(threadId, stream);
View on GitHub (pinned to 75dd419e61)
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
Defensive patterns
Strategy: try-catch
Validate before calling
if (!browser.isBrowserRunning()) {
await browser.reconnect(); // re-attach CDP sessions before screencasting
} Try / catch
try {
await browser.startScreencast({ threadId });
} catch (e) {
if (e instanceof Error && e.message.startsWith('No CDP session')) {
await browser.reconnect();
await browser.startScreencast({ threadId });
} else throw e;
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- No browser context available for screencast
- No page available for screencast
- No CDP session available
- CDP session not available for mouse injection
- CDP session not available for keyboard injection
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/5b85c822ed0cb8c8.
Report an issue: GitHub.