browser_switch_to_window_by_url
Switches browser focus to a specific window or tab by matching its URL, enabling automated navigation between multiple open web pages during testing or automation workflows.
Instructions
Switch to a window by its URL
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | The URL of the window to switch to |
Implementation Reference
- src/tools/browserTools.ts:370-396 (handler)Executes the logic to switch to the browser window whose current URL matches the provided 'url' parameter by iterating over all window handles.async ({ url }) => { try { const driver = stateManager.getDriver(); const windowHandles = await driver.getAllWindowHandles(); for (const handle of windowHandles) { await driver.switchTo().window(handle); const currentUrl = await driver.getCurrentUrl(); if (currentUrl === url) { return { content: [{ type: 'text', text: `Switched to window: ${url}` }], }; } } return { content: [{ type: 'text', text: `Window with URL '${url}' not found` }], }; } catch (e) { return { content: [ { type: 'text', text: `Error switching to window by URL: ${(e as Error).message}`, }, ], }; } }
- src/tools/browserTools.ts:367-369 (schema)Zod input schema defining the required 'url' parameter as a string.{ url: z.string().describe('The URL of the window to switch to'), },
- src/tools/browserTools.ts:365-397 (registration)Direct registration of the 'browser_switch_to_window_by_url' tool on the MCP server, specifying name, description, input schema, and handler function.'browser_switch_to_window_by_url', 'Switch to a window by its URL', { url: z.string().describe('The URL of the window to switch to'), }, async ({ url }) => { try { const driver = stateManager.getDriver(); const windowHandles = await driver.getAllWindowHandles(); for (const handle of windowHandles) { await driver.switchTo().window(handle); const currentUrl = await driver.getCurrentUrl(); if (currentUrl === url) { return { content: [{ type: 'text', text: `Switched to window: ${url}` }], }; } } return { content: [{ type: 'text', text: `Window with URL '${url}' not found` }], }; } catch (e) { return { content: [ { type: 'text', text: `Error switching to window by URL: ${(e as Error).message}`, }, ], }; } } );