{"record":{"id":"f0699b6464691941","repo":"mastra-ai/mastra","slug":"no-page-available-for-screencast","errorCode":null,"errorMessage":"No page available for screencast","messagePattern":"No page available for screencast","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"browser/stagehand/src/stagehand-browser.ts","lineNumber":1026,"sourceCode":"    const state = await this.getBrowserState(threadId);\n    return state?.activeTabIndex ?? 0;\n  }\n\n  // ---------------------------------------------------------------------------\n  // 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","sourceCodeStart":1008,"sourceCodeEnd":1044,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/browser/stagehand/src/stagehand-browser.ts#L1008-L1044","documentation":"When setting up a screencast, the provider resolves the CDP session lazily by fetching the page for the given thread on each call. If no page exists for that thread at that moment, there is nothing to screencast and the library throws. This can also happen on reconnect when the active page was lost.","triggerScenarios":"Starting a screencast (via the provider's getCdpSession) when threadManager.getPageForThread(threadId) returns null — no page open for the thread, page was closed, or the browser reconnected and dropped its pages.","commonSituations":"Screencast started before any navigation created a page; user closed the tab mid-screencast; thread scoping means another thread owns the only page; browser crash/reconnect cleared page registry.","solutions":["Ensure a page exists (navigate/open a page) for the thread before starting the screencast","Pass the correct threadId — the page may belong to a different thread","Recreate the page/session after a browser reconnect and restart the screencast","Check that the browser is running and pages were not closed"],"exampleFix":"// before\nawait browser.startScreencast({ threadId }); // no page yet\n// after\nawait browser.navigateTo('https://example.com', { threadId });\nawait browser.startScreencast({ threadId });","handlingStrategy":"try-catch","validationCode":"const page = await browser.getPage({ threadId });\nif (!page) {\n  await browser.navigateTo('about:blank', { threadId }); // ensure a page exists\n}","typeGuard":null,"tryCatchPattern":"try {\n  await browser.startScreencast({ threadId });\n} catch (e) {\n  if (e instanceof Error && e.message === 'No page available for screencast') {\n    await browser.navigateTo('https://example.com', { threadId });\n    await browser.startScreencast({ threadId });\n  } else throw e;\n}","preventionTips":["Always open/navigate a page for the thread before screencasting","Pass the threadId that actually owns the page","Re-create pages after browser reconnects; restart screencast then","Listen for page-close events and stop screencasts proactively"],"tags":["browser","screencast","cdp","page"],"backgroundTag":"browser-page-not-available","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}