Skip to main content
Glama
BrowserGenie

BrowserGenie MCP Server

by BrowserGenie

snapshot_page_state

Capture a complete snapshot of a webpage's state including HTML, storage, cookies, scroll position, and form values to enable exact restoration later.

Instructions

Capture a complete snapshot of the page state: HTML, localStorage, sessionStorage, cookies, scroll position, and form values. Use with restore_page_state to return to this exact state.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tabIdNoTarget tab ID (defaults to currently active tab)
apiKeyNoAPI key for authentication if enabled

Implementation Reference

  • The tool 'snapshot_page_state' is registered via server.tool() in the registerQaTools function. It defines the tool name, description, schema (optional tabId and apiKey), and the handler logic.
    server.tool(
      'snapshot_page_state',
      'Capture a complete snapshot of the page state: HTML, localStorage, sessionStorage, cookies, scroll position, and form values. Use with restore_page_state to return to this exact state.',
      {
        tabId: z.number().optional().describe('Target tab ID (defaults to currently active tab)'),
        apiKey: z.string().optional().describe('API key for authentication if enabled'),
      },
      async ({ tabId, apiKey }) => {
        const result = await bridge.sendCommand({
          command: 'snapshot_page_state',
          params: {},
          tabId,
          apiKey,
          timeout: LONG_TIMEOUT,
        });
        if (!result.success) {
          return { content: [{ type: 'text', text: `Error: ${result.error?.message}` }], isError: true };
        }
        return { content: [{ type: 'text', text: JSON.stringify(result.data, null, 2) }] };
      }
    );
  • The handler function for 'snapshot_page_state' asyncronously sends a command via bridge.sendCommand with command 'snapshot_page_state', empty params, optional tabId/apiKey, and a long timeout. It returns the result data or an error.
    async ({ tabId, apiKey }) => {
      const result = await bridge.sendCommand({
        command: 'snapshot_page_state',
        params: {},
        tabId,
        apiKey,
        timeout: LONG_TIMEOUT,
      });
      if (!result.success) {
        return { content: [{ type: 'text', text: `Error: ${result.error?.message}` }], isError: true };
      }
      return { content: [{ type: 'text', text: JSON.stringify(result.data, null, 2) }] };
    }
  • Input schema for 'snapshot_page_state': tabId (optional number) and apiKey (optional string), both described via Zod schemas.
    {
      tabId: z.number().optional().describe('Target tab ID (defaults to currently active tab)'),
      apiKey: z.string().optional().describe('API key for authentication if enabled'),
    },
  • BridgeCommand interface defines the structure of commands sent to the WebSocket bridge, including the 'command' field which is set to 'snapshot_page_state'.
    export interface BridgeCommand {
      command: string;
      params: Record<string, unknown>;
      tabId?: number;
      apiKey?: string;
      timeout?: number;
    }
    
    export interface BridgeResponse {
      success: boolean;
      data?: unknown;
      error?: {
        code: string;
        message: string;
      };
    }
  • WebSocketBridge.sendCommand is the messaging method that sends the command to the browser extension over a WebSocket and returns a BridgeResponse promise.
    async sendCommand(cmd: BridgeCommand): Promise<BridgeResponse> {
      if (!this.isConnected()) {
        return {
          success: false,
          error: {
            code: 'NOT_CONNECTED',
            message: 'Chrome extension is not connected. Ensure the extension is installed, enabled, and the browser is running.',
          },
        };
      }
    
      const id = crypto.randomUUID();
      const timeout = cmd.timeout ?? DEFAULT_TIMEOUT;
    
      return new Promise<BridgeResponse>((resolve, reject) => {
        const timer = setTimeout(() => {
          this.pending.delete(id);
          resolve({
            success: false,
            error: {
              code: 'TIMEOUT',
              message: `Command '${cmd.command}' timed out after ${timeout}ms`,
            },
          });
        }, timeout);
    
        this.pending.set(id, { resolve, reject, timer });
    
        const message = {
          id,
          type: 'request',
          command: cmd.command,
          params: cmd.params,
          tabId: cmd.tabId,
          apiKey: cmd.apiKey,
          timestamp: Date.now(),
        };
    
        this.client!.send(JSON.stringify(message));
      });
    }
Behavior3/5

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

With no annotations provided, the description carries the full burden for behavioral disclosure. It implies a read-only capture but does not explicitly state effects, permissions, or side effects. The name and pairing suggest safety, but transparency could be improved with explicit statements about non-destructiveness or required authentication.

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 extremely concise at two sentences, front-loading the purpose and listing the captured components in the first sentence, then providing usage context in the second. No unnecessary words.

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?

Despite good purpose clarity, the description omits what the snapshot returns (e.g., a snapshot ID or data structure) and how it should be used with restore_page_state. Since there is no output schema, this information is critical for correct invocation. Without it, the agent may not know how to pass the result to the restoration tool.

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 coverage is 100%, with both parameters described adequately in the input schema. The description does not add additional meaning beyond what the schema provides, so 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.

Purpose5/5

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

The description clearly states the tool captures a complete page snapshot including HTML, storage, cookies, scroll position, and form values. It names the specific action and resource, and distinguishes from sibling tools by listing the captured components and mentioning its pairing with restore_page_state.

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

Usage Guidelines3/5

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

The description advises using the tool with restore_page_state for state restoration, but does not provide explicit when-not-to-use guidance or compare to alternative individual getter tools (e.g., get_cookies, get_local_storage) that could be used for partial snapshots. Usage context is implied but not comprehensive.

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/BrowserGenie/mcp'

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