mirror of
https://github.com/microsoft/playwright-mcp.git
synced 2025-07-27 00:52:27 +08:00
chore: allow configuring screenshot tool (#286)
Fixes: https://github.com/microsoft/playwright-mcp/issues/277
This commit is contained in:
parent
697a69a8c2
commit
12e72a96c4
17
config.d.ts
vendored
17
config.d.ts
vendored
@ -85,4 +85,21 @@ export type Config = {
|
|||||||
* The directory to save output files.
|
* The directory to save output files.
|
||||||
*/
|
*/
|
||||||
outputDir?: string;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
@ -244,14 +244,15 @@ const screenshot = defineTool({
|
|||||||
else
|
else
|
||||||
code.push(`await page.screenshot(${javascript.formatObject(options)});`);
|
code.push(`await page.screenshot(${javascript.formatObject(options)});`);
|
||||||
|
|
||||||
|
const includeBase64 = !context.config.tools?.browser_take_screenshot?.omitBase64;
|
||||||
const action = async () => {
|
const action = async () => {
|
||||||
const screenshot = locator ? await locator.screenshot(options) : await tab.page.screenshot(options);
|
const screenshot = locator ? await locator.screenshot(options) : await tab.page.screenshot(options);
|
||||||
return {
|
return {
|
||||||
content: [{
|
content: includeBase64 ? [{
|
||||||
type: 'image' as 'image',
|
type: 'image' as 'image',
|
||||||
data: screenshot.toString('base64'),
|
data: screenshot.toString('base64'),
|
||||||
mimeType: fileType === 'png' ? 'image/png' : 'image/jpeg',
|
mimeType: fileType === 'png' ? 'image/png' : 'image/jpeg',
|
||||||
}]
|
}] : []
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -93,3 +93,39 @@ test('browser_take_screenshot (outputDir)', async ({ startClient }, testInfo) =>
|
|||||||
expect(fs.existsSync(outputDir)).toBeTruthy();
|
expect(fs.existsSync(outputDir)).toBeTruthy();
|
||||||
expect([...fs.readdirSync(outputDir)]).toHaveLength(1);
|
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,<html><title>Title</title><body>Hello, world!</body></html>',
|
||||||
|
},
|
||||||
|
})).toContainTextContent(`Navigate to data:text/html`);
|
||||||
|
|
||||||
|
await client.callTool({
|
||||||
|
name: 'browser_take_screenshot',
|
||||||
|
arguments: {},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(await client.callTool({
|
||||||
|
name: 'browser_take_screenshot',
|
||||||
|
arguments: {},
|
||||||
|
})).toEqual({
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
text: expect.stringContaining(`Screenshot viewport and save it as`),
|
||||||
|
type: 'text',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user