mastra-ai/mastra · error

No page available for screencast

Error message

No page available for screencast

What it means

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.

Source

Thrown at browser/stagehand/src/stagehand-browser.ts:1026

    const state = await this.getBrowserState(threadId);
    return state?.activeTabIndex ?? 0;
  }

  // ---------------------------------------------------------------------------
  // 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);

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Ensure a page exists (navigate/open a page) for the thread before starting the screencast
  2. Pass the correct threadId — the page may belong to a different thread
  3. Recreate the page/session after a browser reconnect and restart the screencast
  4. Check that the browser is running and pages were not closed

Example fix

// before
await browser.startScreencast({ threadId }); // no page yet
// after
await browser.navigateTo('https://example.com', { threadId });
await browser.startScreencast({ threadId });
Defensive patterns

Strategy: try-catch

Validate before calling

const page = await browser.getPage({ threadId });
if (!page) {
  await browser.navigateTo('about:blank', { threadId }); // ensure a page exists
}

Try / catch

try {
  await browser.startScreencast({ threadId });
} catch (e) {
  if (e instanceof Error && e.message === 'No page available for screencast') {
    await browser.navigateTo('https://example.com', { threadId });
    await browser.startScreencast({ threadId });
  } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/f0699b6464691941. Report an issue: GitHub.