Skip to main content
Glama

switch_page

Navigate between browser pages in Playwright automation by specifying a page ID to switch context for testing or scraping tasks.

Instructions

Switch to a different browser page

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
page_idYes

Implementation Reference

  • Registration of the 'switch_page' tool in the list_tools handler, including its schema definition.
    types.Tool(
        name="switch_page",
        description="Switch to a different browser page",
        inputSchema={
            "type": "object",
            "properties": {
                "page_id": {"type": "string"},
            },
            "required": ["page_id"],
        },
    ),
  • Handler logic for the 'switch_page' tool: retrieves page_id from arguments, validates existence, updates global current_page_id, and returns confirmation.
    elif name == "switch_page":
        page_id = arguments.get("page_id")
        if not page_id:
            raise ValueError("Page ID is required")
            
        if page_id not in pages:
            raise ValueError(f"Page ID '{page_id}' not found")
            
        current_page_id = page_id
        
        return [types.TextContent(type="text", text=f"Switched to page: {page_id}")]
  • Helper function get_active_page used by switch_page and other tools to retrieve the active Page object based on page_id or current_page_id.
    def get_active_page(page_id: Optional[str] = None) -> Page:
        """Get the active page based on page_id or current default."""
        global current_page_id
        
        if page_id is None:
            page_id = current_page_id
        
        if page_id not in pages:
            raise ValueError(f"Page not found: {page_id}")
        
        return pages[page_id]

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/misanthropic-ai/playwrite-mcp'

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