browser_switch_to_window
Switch browser focus to a specific window handle for managing multiple browser windows during web automation tasks.
Instructions
Switch to a different browser window
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| windowHandle | Yes | The handle of the window to switch to |
Implementation Reference
- src/tools/browserTools.ts:240-257 (handler)The handler function executes the tool logic by switching the WebDriver to the specified window handle.async ({ windowHandle }) => { try { const driver = stateManager.getDriver(); await driver.switchTo().window(windowHandle); return { content: [{ type: 'text', text: `Switched to window: ${windowHandle}` }], }; } catch (e) { return { content: [ { type: 'text', text: `Error switching window: ${(e as Error).message}`, }, ], }; } }
- src/tools/browserTools.ts:237-239 (schema)Zod schema for input validation, requiring a 'windowHandle' string.{ windowHandle: z.string().describe('The handle of the window to switch to'), },
- src/tools/browserTools.ts:235-258 (registration)The tool is registered using McpServer.tool() method within the registerBrowserTools function.'browser_switch_to_window', 'Switch to a different browser window', { windowHandle: z.string().describe('The handle of the window to switch to'), }, async ({ windowHandle }) => { try { const driver = stateManager.getDriver(); await driver.switchTo().window(windowHandle); return { content: [{ type: 'text', text: `Switched to window: ${windowHandle}` }], }; } catch (e) { return { content: [ { type: 'text', text: `Error switching window: ${(e as Error).message}`, }, ], }; } } );