{"record":{"id":"1e89707181045b12","repo":"microsoft/playwright","slug":"tab-index-not-found","errorCode":null,"errorMessage":"Tab ${index} not found","messagePattern":"Tab (.+?) not found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/playwright-core/src/tools/backend/context.ts","lineNumber":178,"sourceCode":"  }\n\n  currentTabOrDie(): Tab {\n    if (!this._currentTab)\n      throw new Error('No open pages available.');\n    return this._currentTab;\n  }\n\n  async newTab(): Promise<Tab> {\n    const browserContext = await this.ensureBrowserContext();\n    const page = await browserContext.newPage();\n    this._currentTab = this._tabs.find(t => t.page === page)!;\n    return this._currentTab;\n  }\n\n  async selectTab(index: number) {\n    const tab = this._tabs[index];\n    if (!tab)\n      throw new Error(`Tab ${index} not found`);\n    await tab.page.bringToFront();\n    this._currentTab = tab;\n    return tab;\n  }\n\n  async ensureTab(): Promise<Tab> {\n    await this.ensureBrowserContext();\n    const crashed = this._currentTab?.crashed;\n    if (crashed) {\n      await this._currentTab!.page.close().catch(() => {});\n      this._currentTab = undefined;\n    }\n    if (!this._currentTab)\n      await this.newTab();\n    if (crashed)\n      this._currentTab!.logErrorMessage('Page crashed and was reset to about:blank.');\n    await this._currentTab!.waitForInitialized();\n    return this._currentTab!;","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/microsoft/playwright/blob/c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6/packages/playwright-core/src/tools/backend/context.ts#L160-L196","documentation":"selectTab(index) indexes into _tabs; if there is no tab at that index it throws 'Tab <index> not found'. Used by the MCP select_tab tool. Index is zero-based and must correspond to an existing open tab in the context.","triggerScenarios":"Calling select_tab with an index >= number of open tabs, a negative index (yields undefined), or an index computed from a stale snapshot of the tab list (race with open/close).","commonSituations":"LLM/tool passing an index from an earlier list_tabs that has since changed. Off-by-one (1-based vs 0-based) confusion. Indexing after a tab was closed.","solutions":["List tabs first, then select within bounds; pass 0-based index strictly less than the tab count.","Validate index is a non-negative integer < tab count before calling selectTab.","Refresh the tab list right before selecting to avoid stale indices."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"function inBounds(index, tabs) { return Number.isInteger(index) && index >= 0 && index < tabs.length; }\nif (inBounds(index, await listTabs())) await selectTab(index);","typeGuard":"function isValidTabIndex(i: number, count: number): boolean { return Number.isInteger(i) && i >= 0 && i < count; }","tryCatchPattern":"try { await context.selectTab(index); }\ncatch (e) { if (/not found/.test(e.message)) { /* refresh list, retry with valid index */ } else throw e; }","preventionTips":["List tabs immediately before selecting.","Use 0-based indices strictly less than the tab count."],"tags":["mcp","tools","tabs","index","backend"],"backgroundTag":null,"analyzedSha":"c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6","analyzedAt":"2026-08-12T07:26:36.950Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}