Skip to main content
Glama

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
NameRequiredDescriptionDefault
windowHandleYesThe handle of the window to switch to

Implementation Reference

  • 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}`,
            },
          ],
        };
      }
    }
  • Zod schema for input validation, requiring a 'windowHandle' string.
    {
      windowHandle: z.string().describe('The handle of the window to switch to'),
    },
  • 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}`,
              },
            ],
          };
        }
      }
    );

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