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
| Name | Required | Description | Default |
|---|---|---|---|
| pageIdx | Yes | The index of the page to close. Call list_pages to list pages. |
Implementation Reference
- src/tools/pages.ts:49-75 (registration)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); }, });
- src/McpContext.ts:149-156 (handler)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}); }
- src/tools/pages.ts:57-62 (schema)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.', ), },
- src/tools/ToolDefinition.ts:92-93 (helper)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.';