diff --git a/config.d.ts b/config.d.ts index d08af7d..5a0a6d7 100644 --- a/config.d.ts +++ b/config.d.ts @@ -85,4 +85,21 @@ export type Config = { * The directory to save output files. */ outputDir?: string; + + /** + * Configuration for specific tools. + */ + tools?: { + /** + * Configuration for the browser_take_screenshot tool. + */ + browser_take_screenshot?: { + + /** + * Whether to disable base64-encoded image responses to the clients that + * don't support binary data or prefer to save on tokens. + */ + omitBase64?: boolean; + } + } }; diff --git a/src/tools/snapshot.ts b/src/tools/snapshot.ts index 8f87511..9571c2a 100644 --- a/src/tools/snapshot.ts +++ b/src/tools/snapshot.ts @@ -244,14 +244,15 @@ const screenshot = defineTool({ else code.push(`await page.screenshot(${javascript.formatObject(options)});`); + const includeBase64 = !context.config.tools?.browser_take_screenshot?.omitBase64; const action = async () => { const screenshot = locator ? await locator.screenshot(options) : await tab.page.screenshot(options); return { - content: [{ + content: includeBase64 ? [{ type: 'image' as 'image', data: screenshot.toString('base64'), mimeType: fileType === 'png' ? 'image/png' : 'image/jpeg', - }] + }] : [] }; }; diff --git a/tests/screenshot.spec.ts b/tests/screenshot.spec.ts index 5a94249..0e59837 100644 --- a/tests/screenshot.spec.ts +++ b/tests/screenshot.spec.ts @@ -93,3 +93,39 @@ test('browser_take_screenshot (outputDir)', async ({ startClient }, testInfo) => expect(fs.existsSync(outputDir)).toBeTruthy(); expect([...fs.readdirSync(outputDir)]).toHaveLength(1); }); + +test('browser_take_screenshot (omitBase64)', async ({ startClient }) => { + const client = await startClient({ + config: { + tools: { + browser_take_screenshot: { + omitBase64: true, + }, + }, + }, + }); + + expect(await client.callTool({ + name: 'browser_navigate', + arguments: { + url: 'data:text/html,