Skip to main content
Glama

close_page

Close a specific browser page by its index to manage open tabs during Chrome automation, debugging, or testing workflows.

Instructions

Closes the page by its index. The last open page cannot be closed.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pageIdxYesThe index of the page to close. Call list_pages to list pages.

Implementation Reference

  • Registration of the 'close_page' tool using defineTool. Includes name, description, annotations, Zod input schema for pageIdx, and the handler function that delegates to context.closePage while handling CLOSE_PAGE_ERROR specifically.
    export const closePage = defineTool({ name: 'close_page', description: `Closes the page by its index. The last open page cannot be closed.`, annotations: { category: ToolCategories.NAVIGATION_AUTOMATION, readOnlyHint: false, }, schema: { pageIdx: z .number() .describe( 'The index of the page to close. Call list_pages to list pages.', ), }, handler: async (request, response, context) => { try { await context.closePage(request.params.pageIdx); } catch (err) { if (err.message === CLOSE_PAGE_ERROR) { response.appendResponseLine(err.message); } else { throw err; } } response.setIncludePages(true); }, });
  • Core handler logic for closing a page in McpContext. Validates not closing the last page, retrieves the page, sets selected index to 0, and closes the page without unload handlers.
    async closePage(pageIdx: number): Promise<void> { if (this.#pages.length === 1) { throw new Error(CLOSE_PAGE_ERROR); } const page = this.getPageByIdx(pageIdx); this.setSelectedPageIdx(0); await page.close({runBeforeUnload: false}); }
  • Zod schema definition for the tool's input parameter 'pageIdx'.
    pageIdx: z .number() .describe( 'The index of the page to close. Call list_pages to list pages.', ), },
  • Constant string for the error thrown when attempting to close the last open page.
    export const CLOSE_PAGE_ERROR = 'The last open page cannot be closed. It is fine to keep it open.';

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/SHAY5555-gif/chrome-devtools-mcp'

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