Skip to main content
Glama

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
NameRequiredDescriptionDefault
titleYesThe title of the window to switch to

Implementation Reference

  • 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}`, }, ], }; } } );
  • 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}`, }, ], }; } }
  • Input schema for the tool: requires a 'title' string parameter.
    { title: z.string().describe('The title 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