browser_close
Close the current browser page in the Playwright MCP server, enabling efficient management of web interactions during browser automation tasks.
Instructions
Close the page
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/common.ts:31-38 (handler)The core handler function for the 'browser_close' tool. It invokes context.close() to terminate the browser session and returns a standardized response with a code snippet representing the action.handle: async context => { await context.close(); return { code: [`await page.close()`], captureSnapshot: false, waitForNetwork: false, }; },
- src/tools/common.ts:23-29 (schema)Schema definition for the 'browser_close' tool using Zod, specifying name, title, description, empty input schema, and readOnly type.schema: { name: 'browser_close', title: 'Close browser', description: 'Close the page', inputSchema: z.object({}), type: 'readOnly', },
- src/tools.ts:36-52 (registration)Registers the 'browser_close' tool (imported via common(true)) in the snapshotTools array for use in the tool server.export const snapshotTools: Tool<any>[] = [ ...common(true), ...console, ...dialogs(true), ...files(true), ...install, ...keyboard(true), ...navigate(true), ...network, ...pdf, ...screenshot, ...snapshot, ...tabs(true), ...testing, ...video, ...wait(true), ];
- src/tools.ts:54-69 (registration)Registers the 'browser_close' tool (imported via common(false)) in the visionTools array.export const visionTools: Tool<any>[] = [ ...common(false), ...console, ...dialogs(false), ...files(false), ...install, ...keyboard(false), ...navigate(false), ...network, ...pdf, ...tabs(false), ...testing, ...video, ...vision, ...wait(false), ];
- src/connection.ts:56-77 (registration)MCP server request handler for calling tools. Finds the tool by name (including 'browser_close'), performs checks, and executes context.run(tool, arguments) which invokes the tool's handle function.server.setRequestHandler(CallToolRequestSchema, async request => { const errorResult = (...messages: string[]) => ({ content: [{ type: 'text', text: messages.join('\n') }], isError: true, }); const tool = tools.find(tool => tool.schema.name === request.params.name); if (!tool) return errorResult(`Tool "${request.params.name}" not found`); const modalStates = context.modalStates().map(state => state.type); if (tool.clearsModalState && !modalStates.includes(tool.clearsModalState)) return errorResult(`The tool "${request.params.name}" can only be used when there is related modal state present.`, ...context.modalStatesMarkdown()); if (!tool.clearsModalState && modalStates.length) return errorResult(`Tool "${request.params.name}" does not handle the modal state.`, ...context.modalStatesMarkdown()); try { return await context.run(tool, request.params.arguments); } catch (error) { return errorResult(String(error)); } });