mirror of
https://github.com/modelcontextprotocol/servers.git
synced 2026-04-20 12:55:21 +02:00
add optional encoded param to puppeteer_screenshot for base64 output
This commit is contained in:
@@ -22,14 +22,7 @@ A Model Context Protocol server that provides browser automation capabilities us
|
|||||||
- `selector` (string, optional): CSS selector for element to screenshot
|
- `selector` (string, optional): CSS selector for element to screenshot
|
||||||
- `width` (number, optional, default: 800): Screenshot width
|
- `width` (number, optional, default: 800): Screenshot width
|
||||||
- `height` (number, optional, default: 600): Screenshot height
|
- `height` (number, optional, default: 600): Screenshot height
|
||||||
|
- `encoded` (boolean, optional): If true, capture the screenshot as a base64-encoded data URI (as text) instead of binary image content. Default false.
|
||||||
- **puppeteer_screenshot_encoded**
|
|
||||||
- Captures a screenshot of the entire page or a specific element and return it as a base64-encoded data URI.
|
|
||||||
- Inputs:
|
|
||||||
- `name` (string, required): Name for the screenshot
|
|
||||||
- `selector` (string, optional): CSS selector for element to screenshot
|
|
||||||
- `width` (number, optional, default: 800): Screenshot width
|
|
||||||
- `height` (number, optional, default: 600): Screenshot height
|
|
||||||
|
|
||||||
- **puppeteer_click**
|
- **puppeteer_click**
|
||||||
|
|
||||||
|
|||||||
@@ -242,6 +242,7 @@ async function handleToolCall(name: string, args: any): Promise<CallToolResult>
|
|||||||
case "puppeteer_screenshot": {
|
case "puppeteer_screenshot": {
|
||||||
const width = args.width ?? 800;
|
const width = args.width ?? 800;
|
||||||
const height = args.height ?? 600;
|
const height = args.height ?? 600;
|
||||||
|
const encoded = args.encoded ?? false;
|
||||||
await page.setViewport({ width, height });
|
await page.setViewport({ width, height });
|
||||||
|
|
||||||
const screenshot = await (args.selector ?
|
const screenshot = await (args.selector ?
|
||||||
@@ -269,52 +270,14 @@ async function handleToolCall(name: string, args: any): Promise<CallToolResult>
|
|||||||
type: "text",
|
type: "text",
|
||||||
text: `Screenshot '${args.name}' taken at ${width}x${height}`,
|
text: `Screenshot '${args.name}' taken at ${width}x${height}`,
|
||||||
} as TextContent,
|
} as TextContent,
|
||||||
{
|
encoded ? ({
|
||||||
|
type: "text",
|
||||||
|
text: `data:image/png;base64,${screenshot}`,
|
||||||
|
} as TextContent) : ({
|
||||||
type: "image",
|
type: "image",
|
||||||
data: screenshot,
|
data: screenshot,
|
||||||
mimeType: "image/png",
|
mimeType: "image/png",
|
||||||
} as ImageContent,
|
} as ImageContent),
|
||||||
],
|
|
||||||
isError: false,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
case "puppeteer_screenshot_encoded": {
|
|
||||||
const width = args.width ?? 800;
|
|
||||||
const height = args.height ?? 600;
|
|
||||||
await page.setViewport({ width, height });
|
|
||||||
|
|
||||||
const screenshot = await (args.selector
|
|
||||||
? (await page.$(args.selector))?.screenshot({ encoding: "base64" })
|
|
||||||
: page.screenshot({ encoding: "base64", fullPage: false }));
|
|
||||||
|
|
||||||
if (!screenshot) {
|
|
||||||
return {
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: "text",
|
|
||||||
text: args.selector ? `Element not found: ${args.selector}` : "Screenshot failed",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
isError: true,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
screenshots.set(args.name, screenshot as string);
|
|
||||||
server.notification({
|
|
||||||
method: "notifications/resources/list_changed",
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: "text",
|
|
||||||
text: `Screenshot '${args.name}' taken at ${width}x${height}`,
|
|
||||||
} as TextContent,
|
|
||||||
{
|
|
||||||
type: "text",
|
|
||||||
text: `data:image/png;base64,${screenshot}`,
|
|
||||||
} as TextContent,
|
|
||||||
],
|
],
|
||||||
isError: false,
|
isError: false,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user