Skip to main content
Glama

browser_refresh

Refresh the current web page in a Playwright MCP Server session, with options to wait for specific events like 'networkidle', 'domcontentloaded', or 'load' before proceeding.

Instructions

Refresh the current page, similar to pressing F5 or clicking browser refresh

Input Schema

NameRequiredDescriptionDefault
timeoutNo
waitUntilNoload

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "timeout": { "type": "number" }, "waitUntil": { "default": "load", "enum": [ "networkidle", "domcontentloaded", "load" ], "type": "string" } }, "type": "object" }

Implementation Reference

  • The handler function that parses input, connects to Playwright if needed, reloads the current page with specified waitUntil and timeout options, and returns success or error message including URL changes.
    async (params: any) => { try { const input = z.object({ waitUntil: z.enum(['networkidle', 'domcontentloaded', 'load']).optional().default('load'), timeout: z.number().optional() }).parse(params); await this.playwright.ensureConnected(); const page = this.playwright.getPage(); // Get current URL before refresh const currentUrl = page.url(); // Perform the refresh with specified options const refreshOptions: any = { waitUntil: input.waitUntil }; if (input.timeout !== undefined) { refreshOptions.timeout = input.timeout; } await page.reload(refreshOptions); // Get URL after refresh (should be the same unless redirected) const newUrl = page.url(); return { content: [{ type: 'text', text: `Successfully refreshed page. URL: ${newUrl}${currentUrl !== newUrl ? ` (redirected from ${currentUrl})` : ''}` }] }; } catch (error) { return { content: [{ type: 'text', text: `Page refresh failed: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } }
  • Zod schema defining the input for the browser_refresh tool: optional waitUntil (default 'load') and optional timeout.
    export const BrowserRefreshInputSchema = z.object({ waitUntil: z.enum(['networkidle', 'domcontentloaded', 'load']).optional().default('load'), timeout: z.number().optional() });
  • src/server.ts:559-612 (registration)
    Registers the 'browser_refresh' tool with the MCP server, specifying title, description, input schema, and the handler function.
    this.server.registerTool( 'browser_refresh', { title: 'Refresh Current Page', description: 'Refresh the current page, similar to pressing F5 or clicking browser refresh', inputSchema: { waitUntil: z.enum(['networkidle', 'domcontentloaded', 'load']).optional().default('load'), timeout: z.number().optional() } }, async (params: any) => { try { const input = z.object({ waitUntil: z.enum(['networkidle', 'domcontentloaded', 'load']).optional().default('load'), timeout: z.number().optional() }).parse(params); await this.playwright.ensureConnected(); const page = this.playwright.getPage(); // Get current URL before refresh const currentUrl = page.url(); // Perform the refresh with specified options const refreshOptions: any = { waitUntil: input.waitUntil }; if (input.timeout !== undefined) { refreshOptions.timeout = input.timeout; } await page.reload(refreshOptions); // Get URL after refresh (should be the same unless redirected) const newUrl = page.url(); return { content: [{ type: 'text', text: `Successfully refreshed page. URL: ${newUrl}${currentUrl !== newUrl ? ` (redirected from ${currentUrl})` : ''}` }] }; } catch (error) { return { content: [{ type: 'text', text: `Page refresh failed: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } } );

Other Tools

Related 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/b3nw/playwright-mcp-server'

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