microsoft/playwright · error · Error

Tab index is required

Error message

Tab index is required

What it means

Thrown by the browser_tabs tool's 'select' action when params.index is undefined. The select action semantically requires a target tab index (unlike list/navigate which can operate on the current tab).

Source

Thrown at packages/playwright-core/src/tools/backend/tabs.ts:57

        await context.ensureTab();
        break;
      }
      case 'new': {
        const tab = await context.newTab();
        if (params.url) {
          const url = await tab.checkUrlAndNavigate(params.url);
          response.setIncludeSnapshot();
          response.addAction({ name: 'navigate', url });
        }
        break;
      }
      case 'close': {
        await context.closeTab(params.index);
        break;
      }
      case 'select': {
        if (params.index === undefined)
          throw new Error('Tab index is required');
        await context.selectTab(params.index);
        break;
      }
    }
    const tabHeaders = await Promise.all(context.tabs().map(tab => tab.headerSnapshot()));
    const result = renderTabsMarkdown(tabHeaders);
    response.addTextResult(result.join('\n'));
  },
});

export default [
  browserTabs,
];

View on GitHub (pinned to c8fc3bf8d3)

Solutions

  1. Provide params.index as a non-negative integer that exists in context.tabs().
  2. If you meant the current tab, you do not need 'select' — omit the action or use 'list'.
  3. Resolve the desired index from a prior browser_tabs list call.

Example fix

// before
await client.callTool('browser_tabs', { action: 'select' }); // throws

// after
await client.callTool('browser_tabs', { action: 'select', index: 2 });
Defensive patterns

Strategy: validation

Validate before calling

function validateTabsSelect(params: { action: string; index?: number }) {
  if (params.action === 'select' && (params.index === undefined || !Number.isInteger(params.index) || params.index < 0))
    throw new Error('browser_tabs select requires a non-negative integer index');
}

Type guard

function hasTabIndex(p: { action?: string; index?: unknown }): p is { action: 'select'; index: number } {
  return p.action === 'select' && typeof p.index === 'number' && Number.isInteger(p.index) && p.index >= 0;
}

Try / catch

try {
  await client.callTool('browser_tabs', params);
} catch (e) {
  if (e instanceof Error && e.message === 'Tab index is required') {
    // list tabs first, choose an index, retry
    await client.callTool('browser_tabs', { action: 'list' });
  } else throw e;
}

Prevention

When it happens

Trigger: Calling browser_tabs with action:'select' and omitting index, or passing index: undefined explicitly.

Common situations: Agent assumes 'select' defaults to current tab; index field dropped during JSON construction; confusing 'select' with 'list'.

Related errors


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