playwright_close
Close the browser and release all resources after completing browser automation tasks with the MCP Playwright server.
Instructions
Close the browser and release all resources
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "playwright_close"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/toolHandler.ts:450-480 (handler)Primary inline handler for 'playwright_close': closes the browser instance if connected, handles errors, resets global browser state, and returns appropriate success message.
if (name === "playwright_close") { if (browser) { try { if (browser.isConnected()) { await browser.close().catch((e) => console.error("Error closing browser:", e)); } } catch (error) { console.error("Error during browser close in handler:", error); } finally { resetBrowserState(); } return { content: [ { type: "text", text: "Browser closed successfully", }, ], isError: false, }; } return { content: [ { type: "text", text: "No browser instance to close", }, ], isError: false, }; } - src/tools/browser/navigation.ts:61-89 (handler)CloseBrowserTool class with execute method implementing browser close logic (imported but execution intercepted by inline handler in toolHandler.ts).
export class CloseBrowserTool extends BrowserToolBase { /** * Execute the close browser tool */ async execute(_args: any, context: ToolContext): Promise<ToolResponse> { if (context.browser) { try { // Check if browser is still connected if (context.browser.isConnected()) { await context.browser.close().catch((error) => { console.error("Error while closing browser:", error); }); } else { console.error("Browser already disconnected, cleaning up state"); } } catch (error) { console.error("Error during browser close operation:", error); // Continue with resetting state even if close fails } finally { // Always reset the global browser and page references resetBrowserState(); } return createSuccessResponse("Browser closed successfully"); } return createSuccessResponse("No browser instance to close"); } } - src/tools.ts:264-272 (schema)Tool schema definition: name, description, and empty input schema for 'playwright_close'.
{ name: "playwright_close", description: "Close the browser and release all resources", inputSchema: { type: "object", properties: {}, required: [], }, }, - src/tools.ts:503-504 (registration)Registration of 'playwright_close' in BROWSER_TOOLS array used for conditional browser launch checks.
"playwright_evaluate", "playwright_close", - src/tools/index.ts:16-17 (registration)Listing of 'playwright_close' in exported BROWSER_TOOLS constant.
"playwright_console_logs", "playwright_close",