Merge pull request #1201 from yomandawg/jun/puppeteer
Add optional parameter to Puppeteer tool to capture screenshot as base64 TextContent
This commit is contained in:
commit
239e18f880
2 changed files with 8 additions and 2 deletions
|
|
@ -22,6 +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_click**
|
- **puppeteer_click**
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ const TOOLS: Tool[] = [
|
||||||
selector: { type: "string", description: "CSS selector for element to screenshot" },
|
selector: { type: "string", description: "CSS selector for element to screenshot" },
|
||||||
width: { type: "number", description: "Width in pixels (default: 800)" },
|
width: { type: "number", description: "Width in pixels (default: 800)" },
|
||||||
height: { type: "number", description: "Height in pixels (default: 600)" },
|
height: { type: "number", description: "Height in pixels (default: 600)" },
|
||||||
|
encoded: { type: "boolean", description: "If true, capture the screenshot as a base64-encoded data URI (as text) instead of binary image content. Default false." },
|
||||||
},
|
},
|
||||||
required: ["name"],
|
required: ["name"],
|
||||||
},
|
},
|
||||||
|
|
@ -228,6 +229,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 ?
|
||||||
|
|
@ -255,11 +257,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,
|
isError: false,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue