// Repro: accelerated (webgl) canvas content freezes at the FIRST frame in // drawElementImage captures — the canvas's paint record never invalidates // when the canvas re-renders, because presentation happens via compositor // texture swap. A 2d canvas shows the same freeze when no unrelated paint // invalidation occurs nearby. // // The page animates a WebGL clear color through hues every frame. On screen // (and in CDP screenshots, when not wrapped) the canvas cycles colors; // drawElementImage returns the FIRST captured frame's color forever. // // Run: node spikes/de-canvas-freeze-crbug.mjs import puppeteer from "puppeteer"; import { writeFileSync } from "node:fs"; const W = 300, H = 200; const HTML = `
frame 0
`; const b = await puppeteer.launch({ headless: true, args: ["--no-sandbox", "--enable-features=CanvasDrawElement", "--use-gl=angle", `--window-size=${W},${H}`] }); const p = await b.newPage(); await p.setViewport({ width: W, height: H }); await p.setContent(HTML, { waitUntil: "load" }); const colors = []; for (let i = 0; i < 10; i++) { await p.evaluate((n) => window.__renderFrame(n), i); const r = await p.evaluate(() => window.__cap()); if (r.err) { console.log("f" + i, r.err); break; } colors.push(r.px.join(",")); if (i === 0 || i === 9) writeFileSync(`/tmp/canvas-freeze-f${i}.png`, Buffer.from(r.url.split(",")[1], "base64")); } const unique = new Set(colors); console.log("sampled canvas-region pixels per frame:", colors.join(" | ")); console.log(unique.size === 1 ? `BUG: all 10 captures identical (${[...unique][0]}) — canvas frozen at first frame` : `no repro: ${unique.size} distinct colors captured`); console.log(await b.version()); await b.close();