browser_switch_to_window_by_title
Switch to a specific browser window using its title text, enabling navigation between multiple open windows during web automation tasks.
Instructions
Switch to a window by its title
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| title | Yes | The title of the window to switch to |
Implementation Reference
- src/tools/browserTools.ts:291-324 (registration)Registration of the 'browser_switch_to_window_by_title' tool, including inline schema and handler. The handler iterates through all browser window handles, switches to each, checks if its title matches the input 'title', and returns success or not found message.server.tool( 'browser_switch_to_window_by_title', 'Switch to a window by its title', { title: z.string().describe('The title of the window to switch to'), }, async ({ title }) => { try { const driver = stateManager.getDriver(); const windowHandles = await driver.getAllWindowHandles(); for (const handle of windowHandles) { await driver.switchTo().window(handle); const currentTitle = await driver.getTitle(); if (currentTitle === title) { return { content: [{ type: 'text', text: `Switched to window: ${title}` }], }; } } return { content: [{ type: 'text', text: `Window with title '${title}' not found` }], }; } catch (e) { return { content: [ { type: 'text', text: `Error switching to window by title: ${(e as Error).message}`, }, ], }; } } );
- src/tools/browserTools.ts:297-323 (handler)The handler function for the tool. It retrieves the current WebDriver, gets all window handles, loops through them switching to each and checking the title against the input. Switches to matching window or reports not found/error.async ({ title }) => { try { const driver = stateManager.getDriver(); const windowHandles = await driver.getAllWindowHandles(); for (const handle of windowHandles) { await driver.switchTo().window(handle); const currentTitle = await driver.getTitle(); if (currentTitle === title) { return { content: [{ type: 'text', text: `Switched to window: ${title}` }], }; } } return { content: [{ type: 'text', text: `Window with title '${title}' not found` }], }; } catch (e) { return { content: [ { type: 'text', text: `Error switching to window by title: ${(e as Error).message}`, }, ], }; } }
- src/tools/browserTools.ts:294-296 (schema)Input schema for the tool: requires a 'title' string parameter.{ title: z.string().describe('The title of the window to switch to'), },