Skip to main content
Glama

close-browser

Close a specific browser instance by its ID and remove it from the active browsers list, ensuring clean resource management in MCP Fetch's browser automation tasks.

Instructions

Close a browser instance and remove it from the active browsers list

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
browserIdYesThe ID of the browser instance to close

Implementation Reference

  • Core handler function that closes the specified browser instance, handles cleanup of associated pages, and returns success/error JSON.
    export async function closeBrowser(browserId: string) { // Check if browser exists const browsers = getBrowsers() const browserInstance = browsers[browserId] if (!browserInstance) { return JSON.stringify({ success: false, error: `Browser with ID '${browserId}' not found`, }, null, 2) } const { browser } = browserInstance // Close the browser try { if (browser.connected) { await browser.close() } } catch { // do nothing } // Clean up any pages associated with this browser const pages = getPages() const pageIds = Object.keys(pages) let cleanedPagesCount = 0 for (const pageId of pageIds) { if (pages[pageId].browserId === browserId) { delete pages[pageId] cleanedPagesCount++ } } // Remove from global object delete browsers[browserId] return JSON.stringify({ success: true, message: `Browser ${browserId} closed successfully`, cleanedPagesCount, }, null, 2) }
  • Zod schema defining the input parameters for the 'close-browser' action within the puppeteer tool.
    z.object({ type: z.literal("close-browser"), browserId: z.string().describe("The ID of the browser instance to close"), }),
  • Dispatch handler in the main puppeteer tool function that routes 'close-browser' actions to the closeBrowser implementation.
    case "close-browser": return await closeBrowser(action.browserId)

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/matiasngf/mcp-fetch'

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