Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .claude/skills/playwright-dev/dashboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,4 @@ npx playwright cli video-stop
# afterwards, use ffmpeg to turn the video into mp4 for sharing.
```

For more about using Playwright CLI, look at `npx playwright cli --help` and the referenced Skill.
While developing in in this repo, it's important to use `npx playwright cli` instead of `playwright-cli`.

Full CLI reference: `packages/playwright-core/src/tools/cli-client/skill/SKILL.md`. In this repo, invoke as `npx playwright cli` instead of `playwright-cli`.
6 changes: 6 additions & 0 deletions docs/src/api/class-browser.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ await page.GotoAsync("https://www.bing.com");
await browser.CloseAsync();
```

## event: Browser.context
* since: v1.60
- argument: <[BrowserContext]>

Emitted when a new browser context is created.

## event: Browser.disconnected
* since: v1.8
- argument: <[Browser]>
Expand Down
67 changes: 35 additions & 32 deletions packages/dashboard/src/annotations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,43 @@ function viewportRectToScreenStyle(layout: ImageLayout, screenRect: DOMRect, vw:
};
}

export async function saveAnnotationAsDownload(blob: Blob): Promise<void> {
const stamp = new Date().toISOString().replace(/[:.]/g, '-');
const suggestedName = `annotations-${stamp}.png`;
const picker = (window as any).showSaveFilePicker as undefined | ((opts: any) => Promise<any>);
if (picker) {
try {
const handle = await picker({
suggestedName,
startIn: 'downloads',
types: [{ description: 'PNG image', accept: { 'image/png': ['.png'] } }],
});
const writable = await handle.createWritable();
await writable.write(blob);
await writable.close();
} catch (e: any) {
if (e?.name !== 'AbortError')
throw e;
}
return;
}
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = suggestedName;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
URL.revokeObjectURL(url);
}

export const Annotations: React.FC<{
active: boolean;
displayRef: React.RefObject<HTMLImageElement | null>;
screenRef: React.RefObject<HTMLDivElement | null>;
viewportWidth: number;
viewportHeight: number;
onSubmit?: (blob: Blob, annotations: Annotation[]) => Promise<void> | void;
onSubmit: (blob: Blob, annotations: Annotation[]) => Promise<void> | void;
}> = ({ active, displayRef, screenRef, viewportWidth, viewportHeight, onSubmit }) => {
const [annotations, setAnnotations] = React.useState<Annotation[]>([]);
const [draft, setDraft] = React.useState<{ startX: number; startY: number; x: number; y: number } | null>(null);
Expand Down Expand Up @@ -327,37 +357,10 @@ export const Annotations: React.FC<{
const blob = await new Promise<Blob | null>(resolve => canvas.toBlob(resolve, 'image/png'));
if (!blob)
return;
if (onSubmit) {
await onSubmit(blob, annotations);
return;
}
const stamp = new Date().toISOString().replace(/[:.]/g, '-');
const suggestedName = `annotations-${stamp}.png`;
const picker = (window as any).showSaveFilePicker as undefined | ((opts: any) => Promise<any>);
if (picker) {
try {
const handle = await picker({
suggestedName,
startIn: 'downloads',
types: [{ description: 'PNG image', accept: { 'image/png': ['.png'] } }],
});
const writable = await handle.createWritable();
await writable.write(blob);
await writable.close();
} catch (e: any) {
if (e?.name !== 'AbortError')
throw e;
}
return;
}
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = suggestedName;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
URL.revokeObjectURL(url);
await onSubmit(blob, annotations);
setAnnotations([]);
setSelection(null);
setDraft(null);
}

if (!active)
Expand Down
Loading
Loading