Skip to content

No escape hatch when drawElementImage mis-renders content: subtree capture or region fallback needed #139

Closed

Description

@vanceingalls

Context

We capture HTML compositions to video using drawElementImage for frame capture
(~1.5× faster than CDP screenshots on real production content). At today's
implementation maturity, several content classes capture incorrectly in Chromium —
CSS 3D rendering contexts (crbug.com/522872457),
stacked containers with animated partial opacity (crbug.com/521861819), and
accelerated canvases whose paint records freeze at the first frame.

Implementation bugs get fixed over time. The structural problem we want to raise
here is an API-design one: when drawElementImage mis-renders a region, the
application has no escape path at all
, because two restrictions compose badly:

  1. drawElementImage only accepts immediate children of its canvas.
    When a deep subtree (a 3D flip card, a fading scene wrapper) captures
    incorrectly, we cannot capture that subtree separately and composite it
    manually — hoisting it to be an immediate canvas child breaks descendant CSS
    selectors and layout context.

  2. Children of a layoutsubtree canvas never paint to the screen.
    So the traditional fallback — screenshot the affected region and paste it
    over the capture — is also impossible: the page is visually blank while the
    canvas wraps the content.

Together these mean any rendering gap in drawElementImage is a hard wall.
Our current production posture is to statically detect affected content and
route the entire render back to screenshot capture, losing the API's benefit
for ~70% of real compositions (10 of 14 in our sample use CSS 3D scene
entrances).

What we tried (all dead ends)

  • Capture the problem subtree with its own drawElementImage call → rejected:
    "Only immediate children of the element can be passed".
  • CDP Page.captureScreenshot for the affected region → blank page under
    layoutsubtree.
  • Re-express the problematic styles (e.g. fades as filter: opacity(),
    3D as flat single-element perspective() transforms) → same failures.
  • Rasterize the subtree to a texture (SVG foreignObject) and re-project via
    WebGL, compositing under/over the DOM paint → works, but only for subtrees
    with static content; animated descendants freeze at the rasterization
    snapshot.

Ask

Either of the following would unblock applications generically:

  1. Subtree capture: allow drawElementImage(element) for any descendant of
    the layoutsubtree canvas (perhaps with an explicit opt-in attribute on the
    element), so applications can compose captures and substitute their own
    rendering for regions the implementation doesn't yet handle.

  2. A spec'd region-fallback story: e.g. a way to ask the engine to rasterize
    a given descendant via the full compositor path into an ImageBitmap
    (element.captureToImageBitmap()-style), usable alongside drawElementImage.

A third, softer option is spec text enumerating which CSS features
drawElementImage is required to honor (3D rendering contexts, backface
visibility, filters, animated opacity on promoted layers), so implementations
fail loudly (throw) rather than silently emitting wrong pixels — silent
divergence from on-screen rendering is the most expensive failure mode for
capture pipelines.

Happy to provide the deterministic repros referenced above; they're ~50-line
Puppeteer scripts.

Activity

  1. progers commented on Jun 26, 2026

    @progers
    Collaborator

    Thanks for taking the time to file this. I've triaged the two chromium bugs you filed. Please keep the bugs coming!

    I think the meta issue you are reporting here will be fixed with a solution to either #134 or #120, both of which we are pursuing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions