From f64fce63c054c689d7c39bf5080040c9bba2c073 Mon Sep 17 00:00:00 2001 From: clChenLiang Date: Fri, 26 Dec 2025 17:05:54 +0800 Subject: [PATCH] feat: update pages tools with header --- src/tools/pages.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/tools/pages.ts b/src/tools/pages.ts index 96ab2cc01..a110064d1 100644 --- a/src/tools/pages.ts +++ b/src/tools/pages.ts @@ -88,11 +88,19 @@ export const newPage = defineTool({ }, schema: { url: zod.string().describe('URL to load in a new page.'), + headers: zod + .record(zod.string()) + .optional() + .describe('Optional headers to send with the navigation request.'), ...timeoutSchema, }, handler: async (request, response, context) => { const page = await context.newPage(); + if (request.params.headers) { + await page.setExtraHTTPHeaders(request.params.headers); + } + await context.waitForEventsAfterAction(async () => { await page.goto(request.params.url, { timeout: request.params.timeout, @@ -118,6 +126,10 @@ export const navigatePage = defineTool({ 'Navigate the page by URL, back or forward in history, or reload.', ), url: zod.string().optional().describe('Target URL (only type=url)'), + headers: zod + .record(zod.string()) + .optional() + .describe('Optional headers to send with the navigation request.'), ignoreCache: zod .boolean() .optional() @@ -130,6 +142,10 @@ export const navigatePage = defineTool({ timeout: request.params.timeout, }; + if (request.params.headers) { + await page.setExtraHTTPHeaders(request.params.headers); + } + if (!request.params.type && !request.params.url) { throw new Error('Either URL or a type is required.'); }