Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(trace viewer): render hint for canvas in snapshots #33092

Closed
wants to merge 1 commit into from
Closed
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
27 changes: 27 additions & 0 deletions packages/trace-viewer/src/sw/snapshotRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,35 @@ function snapshotScript(...targetIds: (string | undefined)[]) {
const kPointerWarningTitle = 'Recorded click position in absolute coordinates did not' +
' match the center of the clicked element. This is likely due to a difference between' +
' the test runner and the trace viewer operating systems.';
const kCanvasWarningTitle = 'Canvas contents aren\'t recorded in Snapshot. Enable "Show screenshot instead of snapshot" in Settings to see contents.';

const scrollTops: Element[] = [];
const scrollLefts: Element[] = [];
const targetElements: Element[] = [];

const drawCanvasWarning = (canvas: HTMLCanvasElement) => {
const context = canvas.getContext('2d')!;

context.fillStyle = '#f3f3f3';
context.fillRect(0, 0, canvas.width, canvas.height);

context.beginPath();
context.arc(canvas.width / 2, canvas.height / 2, 40, 0, 2 * Math.PI);
context.fillStyle = '#e51400';
context.fill();

context.lineWidth = 5;
context.strokeStyle = '#e51400';
context.strokeRect(0, 0, canvas.width, canvas.height);
context.font = '50px serif';

context.fillStyle = 'white';
context.textAlign = 'center';
context.fillText('⚠', canvas.width / 2, canvas.height / 2 + 20);

canvas.setAttribute('title', kCanvasWarningTitle);
};

const visit = (root: Document | ShadowRoot) => {
// Collect all scrolled elements for later use.
for (const e of root.querySelectorAll(`[__playwright_scroll_top_]`))
Expand Down Expand Up @@ -299,6 +323,9 @@ function snapshotScript(...targetIds: (string | undefined)[]) {
}
}

for (const canvas of root.querySelectorAll('canvas'))
drawCanvasWarning(canvas);

{
const body = root.querySelector(`body[__playwright_custom_elements__]`);
if (body && window.customElements) {
Expand Down
Loading