diff --git a/src/context.ts b/src/context.ts index ecf66b9..2b1e0d8 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(); } @@ -121,13 +121,13 @@ export class Context { const title = await tab.title(); const url = tab.page.url(); const current = tab === this._currentTab ? ' (current)' : ''; - lines.push(`- ${i + 1}:${current} [${title}] (${url})`); + lines.push(`- ${i}:${current} [${title}] (${url})`); } return lines.join('\n'); } 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/tests/tabs.spec.ts b/tests/tabs.spec.ts index 6768d75..0a1545e 100644 --- a/tests/tabs.spec.ts +++ b/tests/tabs.spec.ts @@ -31,7 +31,7 @@ test('list initial tabs', async ({ client }) => { expect(await client.callTool({ name: 'browser_tab_list', })).toHaveTextContent(`### Open tabs -- 1: (current) [] (about:blank)`); +- 0: (current) [] (about:blank)`); }); test('list first tab', async ({ client }) => { @@ -39,8 +39,8 @@ test('list first tab', async ({ client }) => { expect(await client.callTool({ name: 'browser_tab_list', })).toHaveTextContent(`### Open tabs -- 1: [] (about:blank) -- 2: (current) [Tab one] (data:text/html,Tab oneBody one)`); +- 0: [] (about:blank) +- 1: (current) [Tab one] (data:text/html,Tab oneBody one)`); }); test('create new tab', async ({ client }) => { @@ -51,8 +51,8 @@ test('create new tab', async ({ client }) => { \`\`\` ### Open tabs -- 1: [] (about:blank) -- 2: (current) [Tab one] (data:text/html,Tab oneBody one) +- 0: [] (about:blank) +- 1: (current) [Tab one] (data:text/html,Tab oneBody one) ### Current tab - Page URL: data:text/html,Tab oneBody one @@ -69,9 +69,9 @@ test('create new tab', async ({ client }) => { \`\`\` ### Open tabs -- 1: [] (about:blank) -- 2: [Tab one] (data:text/html,Tab oneBody one) -- 3: (current) [Tab two] (data:text/html,Tab twoBody two) +- 0: [] (about:blank) +- 1: [Tab one] (data:text/html,Tab oneBody one) +- 2: (current) [Tab two] (data:text/html,Tab twoBody two) ### Current tab - Page URL: data:text/html,Tab twoBody two @@ -88,18 +88,18 @@ 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 -- 1: [] (about:blank) -- 2: (current) [Tab one] (data:text/html,Tab oneBody one) -- 3: [Tab two] (data:text/html,Tab twoBody two) +- 0: [] (about:blank) +- 1: (current) [Tab one] (data:text/html,Tab oneBody one) +- 2: [Tab two] (data:text/html,Tab twoBody two) ### Current tab - Page URL: data:text/html,Tab oneBody one @@ -116,17 +116,17 @@ 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 -- 1: [] (about:blank) -- 2: (current) [Tab one] (data:text/html,Tab oneBody one) +- 0: [] (about:blank) +- 1: (current) [Tab one] (data:text/html,Tab oneBody one) ### Current tab - Page URL: data:text/html,Tab oneBody one