fix(screenshot): support refs and improve error messages (#141)

* fix(screenshot): support refs and improve error messages

* fix(cli): support selector argument in screenshot command

* Fix CSS class selectors being treated as file paths

* fix(test): update screenshot test assertions

---------

Co-authored-by: Chris Tate <chris@ctate.dev>
This commit is contained in:
Danila Poyarkov
2026-01-22 10:06:38 -06:00
committed by GitHub
co-authored by Chris Tate
parent c046de2ec7
commit 9f3c3ad933
2 changed files with 83 additions and 13 deletions
+14 -7
View File
@@ -549,15 +549,22 @@ async function handleScreenshot(
let target: Page | ReturnType<Page['locator']> = page;
if (command.selector) {
target = page.locator(command.selector);
target = browser.getLocator(command.selector);
}
if (command.path) {
await target.screenshot({ ...options, path: command.path });
return successResponse(command.id, { path: command.path });
} else {
const buffer = await target.screenshot(options);
return successResponse(command.id, { base64: buffer.toString('base64') });
try {
if (command.path) {
await target.screenshot({ ...options, path: command.path });
return successResponse(command.id, { path: command.path });
} else {
const buffer = await target.screenshot(options);
return successResponse(command.id, { base64: buffer.toString('base64') });
}
} catch (error) {
if (command.selector) {
throw toAIFriendlyError(error, command.selector);
}
throw error;
}
}