// fallow-ignore-file code-duplication complexity /** * DrawElement Capture Service * * `canvas.drawElementImage(element, x, y)` reads DOM paint records directly into * a canvas, bypassing the full compositor pipeline. Requires the Chrome flag * `--enable-features=CanvasDrawElement` (already added globally) and a * `` wrapper around the composition root. * * Performance: ~46% faster than Page.captureScreenshot on local GPU. * Alpha: pixel-perfect (PSNR=∞) on GPU. Falls back to screenshot in Docker * (SwiftShader) when transparent output is requested — SwiftShader drops promoted * compositor sub-layers on a transparent canvas destination (Chromium bug, filed * Blink>Canvas, 2026-06-08). */ import type { Page } from "puppeteer-core"; /** * Resolve which capture mode to use when `useDrawElement` is true. * * Cases that fall back to screenshot (see docs/fast-capture-limitations.md): * - SwiftShader (software rasterizer, i.e. Docker/CI with no GPU): drawElement * yields NO speedup here and is slightly slower. Its entire advantage is * skipping the GPU→CPU screenshot readback IPC — on SwiftShader there is no * GPU, so both paths block on identical software rasterization (measured * parity: font-variant-numeric baseline 7822ms vs fast 7979ms, page-side * draw/readback/encode all ~0ms). The drawElement path only adds a per-frame * CDP round-trip on top of the same raster cost, and on a transparent * destination additionally drops promoted sub-layers (Chromium bug * 521434899). The speedup is real only on a hardware GPU (macOS 1.6×), so * SwiftShader always routes to the platform baseline. * * The former