playwright_close
Close the browser and release all resources after completing web automation tasks with Playwright.
Instructions
Close the browser and release all resources
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/toolHandler.ts:382-409 (handler)Primary handler execution for the 'playwright_close' tool. This special case handles closing the browser instance, resetting global state, and returning appropriate success/error messages. Executed directly in handleToolCall before other logic.
// Special case for browser close to ensure it always works 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:234-242 (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: [], }, }, - src/tools.ts:450-473 (registration)Registration of 'playwright_close' in BROWSER_TOOLS array, used by toolHandler to determine browser initialization needs.
export const BROWSER_TOOLS = [ "playwright_navigate", "playwright_screenshot", "playwright_click", "playwright_iframe_click", "playwright_iframe_fill", "playwright_fill", "playwright_select", "playwright_hover", "playwright_upload_file", "playwright_evaluate", "playwright_close", "playwright_expect_response", "playwright_assert_response", "playwright_custom_user_agent", "playwright_get_visible_text", "playwright_get_visible_html", "playwright_go_back", "playwright_go_forward", "playwright_drag", "playwright_press_key", "playwright_save_as_pdf", "playwright_click_and_switch_tab" ]; - src/tools/browser/navigation.ts:63-91 (handler)Alternative handler implementation in CloseBrowserTool.execute method. Closely mirrors the primary handler logic. Class is instantiated but not invoked for this tool due to special case handling.
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/index.ts:17-17 (registration)Lists 'playwright_close' among browser tools for export/reference.
"playwright_close",