Skip to main content
Glama

browser_switch_to_frame

Switch to an iframe element in web automation by specifying a locator strategy and value, enabling interaction with embedded content.

Instructions

Switches to an iframe element

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
byYesLocator strategy to find element
valueYesValue for the locator strategy
timeoutNoMaximum time to wait for element in milliseconds

Implementation Reference

  • Registers the 'browser_switch_to_frame' tool with the MCP server, including input schema from locatorSchema and an async handler that instantiates ElementService and calls switchToFrame on it.
    server.tool(
      'browser_switch_to_frame',
      'Switches to an iframe element',
      { ...locatorSchema },
      async ({ by, value, timeout = 15000 }) => {
        try {
          const driver = stateManager.getDriver();
          const elementService = new ElementService(driver);
          await elementService.switchToFrame({ by, value, timeout });
          return {
            content: [{ type: 'text', text: 'Switched to iframe' }],
          };
        } catch (e) {
          return {
            content: [
              {
                type: 'text',
                text: `Error switching to frame: ${(e as Error).message}`,
              },
            ],
          };
        }
      }
    );
  • Core implementation of frame switching: locates the iframe element using the provided locator and switches the WebDriver context to that frame.
    async switchToFrame(params: LocatorParams): Promise<void> {
      const element = await this.findElement(params);
      await this.driver.switchTo().frame(element);
    }
  • Zod schema definition for the tool's input parameters (locator strategy, value, optional timeout), spread into the tool's input schema.
    export const locatorSchema = {
      by: z
        .enum(['id', 'css', 'xpath', 'name', 'tag', 'class', 'link', 'partialLink'])
        .describe('Locator strategy to find element'),
      value: z.string().describe('Value for the locator strategy'),
      timeout: z.number().optional().describe('Maximum time to wait for element in milliseconds'),
    };
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but offers minimal behavioral insight. It states the action but doesn't disclose what happens after switching (e.g., subsequent interactions target the iframe), error conditions (e.g., if iframe isn't found), or side effects (e.g., needing to switch back later). This leaves significant gaps for a mutation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero wasted words. It's front-loaded with the core action and target, making it immediately understandable without unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a mutation tool with no annotations and no output schema, the description is inadequate. It doesn't explain what 'switches to' means operationally, what the agent can do after switching, or how to return to the original context. Given the complexity of browser automation, more context is needed.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so parameters are fully documented in the schema. The description adds no additional parameter context beyond implying an iframe target. Since the schema handles the heavy lifting, the baseline score of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Switches to an iframe element' clearly states the action (switches) and target (iframe element), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'browser_switch_to_parent_frame' or 'browser_switch_to_default_content', which handle similar frame/window switching operations.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided about when to use this tool versus alternatives. The description doesn't mention prerequisites (e.g., needing to be on a page with iframes), when to switch back, or how it differs from sibling switching tools like 'browser_switch_to_parent_frame' or 'browser_switch_to_default_content'.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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