playwright_close
Close the browser and release all resources to free up memory and end automation tasks in the Playwright MCP Server environment.
Instructions
Close the browser and release all resources
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/toolHandler.ts:374-400 (handler)Primary execution handler for the 'playwright_close' tool. Closes the Playwright browser instance if it exists and resets the global browser state.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.ts:222-230 (schema)Tool schema definition including 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: [], }, },
- Class-based implementation for closing the browser (CloseBrowserTool), similar to inline handler logic, extends BrowserToolBase.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/toolHandler.ts:56-60 (helper)Helper function to reset global browser, page, and browser type state after closing.export function resetBrowserState() { browser = undefined; page = undefined; currentBrowserType = 'chromium'; }
- src/tools.ts:439-439 (registration)Inclusion in BROWSER_TOOLS array used to identify browser-requiring tools."playwright_close",