From 708aa6d6a5075d0ea62168eeab8d6a6ecf76200d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 19 Jun 2025 09:38:10 +0000 Subject: [PATCH] Change tab selection to use 0-based indexing instead of 1-based Co-authored-by: Skn0tt <14912729+Skn0tt@users.noreply.github.com> --- README.md | 6 +++--- src/context.ts | 4 ++-- src/tools/tabs.ts | 6 +++--- tests/tabs.spec.ts | 8 ++++---- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 504e0c6..d5ddf06 100644 --- a/README.md +++ b/README.md @@ -662,9 +662,9 @@ X Y coordinate space, based on the provided screenshot. - **browser_tab_select** - Title: Select a tab - - Description: Select a tab by index (1-based indexing) + - Description: Select a tab by index (0-based indexing) - Parameters: - - `index` (number): The index of the tab to select (1-based: first tab is 1, second tab is 2, etc.) + - `index` (number): The index of the tab to select (0-based: first tab is 0, second tab is 1, etc.) - Read-only: **true** @@ -673,7 +673,7 @@ X Y coordinate space, based on the provided screenshot. - Title: Close a tab - Description: Close a tab - Parameters: - - `index` (number, optional): The index of the tab to close (1-based: first tab is 1, second tab is 2, etc.). Closes current tab if not provided. + - `index` (number, optional): The index of the tab to close (0-based: first tab is 0, second tab is 1, etc.). Closes current tab if not provided. - Read-only: **false** diff --git a/src/context.ts b/src/context.ts index ecf66b9..d2f4238 100644 --- a/src/context.ts +++ b/src/context.ts @@ -101,7 +101,7 @@ export class Context { } async selectTab(index: number) { - this._currentTab = this._tabs[index - 1]; + this._currentTab = this._tabs[index]; await this._currentTab.page.bringToFront(); } @@ -127,7 +127,7 @@ export class Context { } async closeTab(index: number | undefined) { - const tab = index === undefined ? this._currentTab : this._tabs[index - 1]; + const tab = index === undefined ? this._currentTab : this._tabs[index]; await tab?.page.close(); return await this.listTabsMarkdown(); } diff --git a/src/tools/tabs.ts b/src/tools/tabs.ts index 4484c9d..52b1673 100644 --- a/src/tools/tabs.ts +++ b/src/tools/tabs.ts @@ -50,9 +50,9 @@ const selectTab: ToolFactory = captureSnapshot => defineTool({ schema: { name: 'browser_tab_select', title: 'Select a tab', - description: 'Select a tab by index (1-based indexing)', + description: 'Select a tab by index (0-based indexing)', inputSchema: z.object({ - index: z.number().describe('The index of the tab to select (1-based: first tab is 1, second tab is 2, etc.)'), + index: z.number().describe('The index of the tab to select (0-based: first tab is 0, second tab is 1, etc.)'), }), type: 'readOnly', }, @@ -108,7 +108,7 @@ const closeTab: ToolFactory = captureSnapshot => defineTool({ title: 'Close a tab', description: 'Close a tab', inputSchema: z.object({ - index: z.number().optional().describe('The index of the tab to close (1-based: first tab is 1, second tab is 2, etc.). Closes current tab if not provided.'), + index: z.number().optional().describe('The index of the tab to close (0-based: first tab is 0, second tab is 1, etc.). Closes current tab if not provided.'), }), type: 'destructive', }, diff --git a/tests/tabs.spec.ts b/tests/tabs.spec.ts index 061e58c..a0f7735 100644 --- a/tests/tabs.spec.ts +++ b/tests/tabs.spec.ts @@ -90,12 +90,12 @@ test('select tab', async ({ client }) => { expect(await client.callTool({ name: 'browser_tab_select', arguments: { - index: 2, + index: 1, }, })).toHaveTextContent(` - Ran Playwright code: \`\`\`js -// +// \`\`\` ### Open tabs @@ -118,12 +118,12 @@ test('close tab', async ({ client }) => { expect(await client.callTool({ name: 'browser_tab_close', arguments: { - index: 3, + index: 2, }, })).toHaveTextContent(` - Ran Playwright code: \`\`\`js -// +// \`\`\` ### Open tabs