microsoft/playwright · error · Error

No open pages available.

Error message

No open pages available.

What it means

currentTabOrDie() throws 'No open pages available' when the tools backend's _currentTab is unset. It is the fail-fast accessor used by MCP tool backends (video, wait, snapshot) that require an active tab. There is no current tab if the context has no open pages or the active one was closed/crashed and not yet recreated.

Source

Thrown at packages/playwright-core/src/tools/backend/context.ts:164

    this._unhandledRejectionListeners.add(listener);
    return () => this._unhandledRejectionListeners.delete(listener);
  }

  debugger() {
    return this._rawBrowserContext.debugger;
  }

  tabs(): Tab[] {
    return this._tabs;
  }

  currentTab(): Tab | undefined {
    return this._currentTab;
  }

  currentTabOrDie(): Tab {
    if (!this._currentTab)
      throw new Error('No open pages available.');
    return this._currentTab;
  }

  async newTab(): Promise<Tab> {
    const browserContext = await this.ensureBrowserContext();
    const page = await browserContext.newPage();
    this._currentTab = this._tabs.find(t => t.page === page)!;
    return this._currentTab;
  }

  async selectTab(index: number) {
    const tab = this._tabs[index];
    if (!tab)
      throw new Error(`Tab ${index} not found`);
    await tab.page.bringToFront();
    this._currentTab = tab;
    return tab;
  }

View on GitHub (pinned to c8fc3bf8d3)

Solutions

  1. Call the tool that opens/ensures a tab first (newTab / ensureTab), then snapshot/action tools.
  2. Check for open pages via a list tool before calling action tools; surface 'open a page' to the user/LLM.
  3. Have the backend auto-call ensureTab() so currentTab is never null when an action runs.
Defensive patterns

Strategy: validation

Validate before calling

// Call ensureTab/newTab before action tools.
async function ensureTabOrThrow(ctx) {
  if (!ctx.currentTab()) await ctx.newTab();
  return ctx.currentTabOrDie();
}

Type guard

null

Try / catch

try { return await context.currentTabOrDie(); }
catch (e) {
  if (/No open pages/.test(e.message)) { await context.newTab(); return context.currentTabOrDie(); }
  throw e;
}

Prevention

When it happens

Trigger: Calling any MCP tool that goes through currentTabOrDie() (snapshot, video, wait, etc.) before a page exists, after the only page was closed, or after a crash before ensureTab() runs. Happens at the start of a session or right after closeTab removed the last page.

Common situations: First tool call in a fresh MCP session with no page yet. Calling an action tool after the user/script closed the only tab. Post-crash state where ensureTab hasn't recreated the page.

Related errors


AI-assisted analysis of microsoft/playwright@c8fc3bf8d3 (2026-08-12). Data as JSON: /api/errors/5ca96852c8b32215. Report an issue: GitHub.