Skip to main content
Glama

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
NameRequiredDescriptionDefault
urlYesThe URL of the window to switch to

Implementation Reference

  • 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}`, }, ], }; } }
  • Zod input schema defining the required 'url' parameter as a string.
    { url: z.string().describe('The URL of the window to switch to'), },
  • 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}`, }, ], }; } } );

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/pshivapr/selenium-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server