chore: allow taking pixel screenshots in snapshot mode (#44)
Ref: https://github.com/microsoft/playwright-mcp/issues/39
This commit is contained in:
parent
702fa0bdf3
commit
d4bc2c78d2
8 changed files with 37 additions and 6 deletions
|
|
@ -30,7 +30,7 @@ export const snapshot: Tool = {
|
|||
},
|
||||
|
||||
handle: async context => {
|
||||
return await captureAriaSnapshot(await context.existingPage());
|
||||
return await captureAriaSnapshot(context.existingPage());
|
||||
},
|
||||
};
|
||||
|
||||
|
|
@ -132,6 +132,28 @@ export const selectOption: Tool = {
|
|||
},
|
||||
};
|
||||
|
||||
const screenshotSchema = z.object({
|
||||
raw: z.boolean().optional().describe('Whether to return without compression (in PNG format). Default is false, which returns a JPEG image.'),
|
||||
});
|
||||
|
||||
export const screenshot: Tool = {
|
||||
schema: {
|
||||
name: 'browser_take_screenshot',
|
||||
description: `Take a screenshot of the current page. You can't perform actions based on the screenshot, use browser_snapshot for actions.`,
|
||||
inputSchema: zodToJsonSchema(screenshotSchema),
|
||||
},
|
||||
|
||||
handle: async (context, params) => {
|
||||
const validatedParams = screenshotSchema.parse(params);
|
||||
const page = context.existingPage();
|
||||
const options: playwright.PageScreenshotOptions = validatedParams.raw ? { type: 'png', scale: 'css' } : { type: 'jpeg', quality: 50, scale: 'css' };
|
||||
const screenshot = await page.screenshot(options);
|
||||
return {
|
||||
content: [{ type: 'image', data: screenshot.toString('base64'), mimeType: validatedParams.raw ? 'image/png' : 'image/jpeg' }],
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
function refLocator(page: playwright.Page, ref: string): playwright.Locator {
|
||||
return page.locator(`aria-ref=${ref}`);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue