Skip to main content
Glama

browser_switch_to_window_by_url

Switch browser focus to a specific window by matching its URL, enabling control of multiple tabs during automated web testing.

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 tool logic: retrieves the browser driver, iterates over all window handles, switches to each window, compares the current URL with the target URL, and switches to the matching window or reports not found/error.
    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}`, }, ], }; } }
  • Registers the 'browser_switch_to_window_by_url' tool with the MCP server inside registerBrowserTools function, specifying name, description, input schema {url: z.string()}, and handler.
    server.tool( '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}`, }, ], }; } } );
  • src/tools/index.ts:9-9 (registration)
    Top-level registration call to registerBrowserTools from registerAllTools, which includes the browser_switch_to_window_by_url tool.
    registerBrowserTools(server, stateManager);
  • Zod input schema for the tool: url as a string with description.
    url: z.string().describe('The URL of the window to switch to'), },

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