browser_tabs
Manage browser tabs in Playwright MCP by listing, creating, closing, or selecting tabs for web automation tasks.
Instructions
List, create, close, or select a browser tab.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| action | Yes | Operation to perform | |
| index | No | Tab index, used for close/select. If omitted for close, current tab is closed. |
Implementation Reference
- src/tools/tabs.ts:22-37 (handler)Implementation of the 'browser_tab_list' tool handler, which lists all open browser tabs.
const listTabs: Tool = { capability: 'tabs', schema: { name: 'browser_tab_list', description: 'List browser tabs', inputSchema: zodToJsonSchema(z.object({})), }, handle: async context => { return { content: [{ type: 'text', text: await context.listTabs(), }], }; }, }; - src/tools/tabs.ts:39-61 (handler)Implementation of the 'browser_tab_select' tool handler, which selects a browser tab by index.
const selectTabSchema = z.object({ index: z.number().describe('The index of the tab to select'), }); const selectTab: ToolFactory = captureSnapshot => ({ capability: 'tabs', schema: { name: 'browser_tab_select', description: 'Select a tab by index', inputSchema: zodToJsonSchema(selectTabSchema), }, handle: async (context, params) => { const validatedParams = selectTabSchema.parse(params); await context.selectTab(validatedParams.index); const currentTab = await context.ensureTab(); return await currentTab.run(async () => { const code = [ `// <internal code to select tab ${validatedParams.index}>`, ]; return { code }; }, { captureSnapshot }); }, }); - src/tools/tabs.ts:63-86 (handler)Implementation of the 'browser_tab_new' tool handler, which opens a new browser tab.
const newTabSchema = z.object({ url: z.string().optional().describe('The URL to navigate to in the new tab. If not provided, the new tab will be blank.'), }); const newTab: Tool = { capability: 'tabs', schema: { name: 'browser_tab_new', description: 'Open a new tab', inputSchema: zodToJsonSchema(newTabSchema), }, handle: async (context, params) => { const validatedParams = newTabSchema.parse(params); await context.newTab(); if (validatedParams.url) await context.currentTab().navigate(validatedParams.url); return await context.currentTab().run(async () => { const code = [ `// <internal code to open a new tab>`, ]; return { code }; }, { captureSnapshot: true }); }, }; - src/tools/tabs.ts:88-118 (handler)Implementation of the 'browser_tab_close' tool handler, which closes a browser tab.
const closeTabSchema = z.object({ index: z.number().optional().describe('The index of the tab to close. Closes current tab if not provided.'), }); const closeTab: ToolFactory = captureSnapshot => ({ capability: 'tabs', schema: { name: 'browser_tab_close', description: 'Close a tab', inputSchema: zodToJsonSchema(closeTabSchema), }, handle: async (context, params) => { const validatedParams = closeTabSchema.parse(params); await context.closeTab(validatedParams.index); const currentTab = context.currentTab(); if (currentTab) { return await currentTab.run(async () => { const code = [ `// <internal code to close tab ${validatedParams.index}>`, ]; return { code }; }, { captureSnapshot }); } return { content: [{ type: 'text', text: await context.listTabs(), }], }; }, }); - src/index.ts:37-47 (registration)Registration of the browser tabs tools (from tabs(true)) into the snapshotTools array used by the MCP server.
const snapshotTools: Tool[] = [ ...common(true), ...console, ...files(true), ...install, ...keyboard(true), ...navigate(true), ...pdf, ...snapshot, ...tabs(true), ];