Skip to content

fix(replay): Keep the full snapshot when a canvas is tainted - #365

Merged
gggritso merged 3 commits into
sentry-v2from
fix/snapshot-tainted-canvas
Nov 19, 2026
Merged

gggritso merged 3 commits into
sentry-v2from
fix/snapshot-tainted-canvas

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

When recordCanvas is on, serializeElementNode reads pixel data from each canvas. On a canvas that has cross-origin data (i.e., images), this throws a SecurityError. Nothing catches that error, so it aborts the whole snapshot. The resulting replay is not playable since there's no snapshot to render from.

The upstream rrweb repo has a few reports of this, and some agreement that just try catching the error is probably fine, so that's what we're doing here. The canvas ends up blank, but the rest of the snapshot is kept.

I expect that as a follow-up we'll somehow "decorate" these blocked canvases so users can see them in the UI. We also might add a bit of error handling to the product so if someone has one of these busted replays they get a notice.

Refs REPLAY-1049

via George Gritsouk.

--

View Session [Sentry]

A canvas tainted by cross-origin data throws a SecurityError from
getImageData and toDataURL. With recordCanvas on, that error escaped
serializeElementNode and aborted the whole document snapshot. In
record(), the Meta event was already emitted, so the recording got a
Meta event with no FullSnapshot, observe(document) never ran, and
players could not render the replay.

Catch the error for that canvas and skip its pixel data instead.

Co-Authored-By: George Gritsouk <[email protected]>
@linear-code

linear-code Bot commented Nov 17, 2026

Copy link
Copy Markdown

REPLAY-1049

@gggritso gggritso changed the title fix(snapshot): Keep the full snapshot when a canvas is tainted fix(replay): Keep the full snapshot when a canvas is tainted Nov 18, 2026

@gggritso gggritso left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks quite decent, just a few questions

Comment thread packages/rrweb-snapshot/src/snapshot.ts Resolved
Comment thread packages/rrweb-snapshot/src/snapshot.ts Resolved

Copy link
Copy Markdown
Member

@cursor review

Copy link
Copy Markdown
Member

Is it possible to add some kind of custom attribute to the "tainted" <canvas> element so we can render it in a special way in the Replay? Is there any precedent for that kind of thing?

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit db4438b. Configure here.

@sentry-junior

sentry-junior Bot commented Nov 18, 2026

Copy link
Copy Markdown
Author

Yes, it's possible, and rrweb already has the pattern for it: internal rr_* attributes that the serializer writes and the rebuilder consumes.

Precedent

  • Blocked elements are the closest match. For a blocked element, serializeElementNode keeps only class plus rr_width / rr_height (snapshot.ts ~L1111). rebuild.ts turns those into inline width/height styles (~L318). The replayer then injects .${blockClass} { background: currentColor } (replay/styles/inject-style.ts) so the element shows up as a solid box. The Sentry player passes blockClass: 'sentry-block'. So "serialize a marker, then render it specially on replay" is exactly what blocking does today.
  • Other rr_* attributes: rr_dataURL, rr_mediaState, rr_mediaCurrentTime, rr_scrollTop/rr_scrollLeft, and rr_src.
  • It's backward compatible. rebuild.ts sends every attribute starting with rr_ into specialAttributes and never puts it on the DOM node (~L209). Unknown ones are just ignored, so older players would keep rendering a blank canvas.

What it would take

  1. Recorder: in this PR's catch, set something like attributes.rr_canvasTainted = true.
  2. Rebuild: handle it in rebuild.ts, and in rrdom's diff path for seeking, by adding a class or data- attribute to the rebuilt canvas. Special attributes aren't set on the node, so without this step the Sentry UI has nothing to target.
  3. Styling: add a rule next to the block rule in inject-style.ts, or in the Sentry player's own styles. Note that <canvas> is a replaced element, so ::before/::after labels don't render on it. A background pattern (visible because the canvas stays transparent) or an outline works. A text label like "Canvas not captured" would need a Sentry-side overlay found through the mirror.

I'd keep that out of this PR. This PR only restores the snapshot. The marker changes the recorder/player contract and touches rebuild, rrdom, and the Sentry player, so it deserves its own review. I can open it as a stacked follow-up if you want it.

Copy link
Copy Markdown
Member

Oh, so there's already mechanisms present for blocked elements! Can we treat a "tainted" canvas as blocked and get this for free?

@sentry-junior

sentry-junior Bot commented Nov 18, 2026

Copy link
Copy Markdown
Author

Re: treating a tainted canvas as blocked. Mostly no. The blocked path wouldn't change what a tainted canvas looks like in Sentry today.

For a blocked element, serializeElementNode throws away every attribute except class and adds rr_width/rr_height (snapshot.ts ~L1111). On replay that's an empty box at the original size. The solid fill comes only from the replayer's .${blockClass} { background: currentColor } rule, so it shows only when the element's own class already contains the player's block class. In Sentry those two don't line up:

  • Class mismatch: the SDK blocks with blockSelector (.sentry-block, [data-sentry-block], media selectors, …) and leaves the recorder's blockClass at the default rr-block. The Sentry player sets blockClass: 'sentry-block'. A tainted canvas has neither class, so marking it blocked gives a transparent box of the same size.
  • That's what we already get: with this PR the canvas keeps all its attributes and just has no rr_dataURL, so it also replays as a transparent canvas of the same size. Blocking it would also drop its style/width/height attributes in favor of rr_width/rr_height, which could shift layout for no visible gain.
  • Forcing the fill: we could append a class in the catch, but rrweb-snapshot doesn't know the player's class. Hardcoding sentry-block in the serializer would couple recorder output to one player's config.

So if we want a tainted canvas to look different on replay, the dedicated rr_ marker from my last comment is the clean way to do it: the recorder flags the canvas, rebuild/rrdom put a class on it, and the player (or inject-style.ts) styles it. Blocking doesn't get us that for free. I can open that as a stacked follow-up PR if you want it.

@gggritso
gggritso marked this pull request as ready for review November 18, 2026 04:30
@gggritso
gggritso requested a review from logaretm November 18, 2026 14:51

@logaretm logaretm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of comments, other than that looks good.

Comment thread packages/rrweb-snapshot/src/snapshot.ts Resolved

Copy link
Copy Markdown
Member

@logaretm thanks for taking a look! The WeakSet approach that Junior added … seems, fine to me? Your call if you want any more changes

@logaretm logaretm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, the WeakSet works here ✅

@gggritso
gggritso merged commit b6b393a into sentry-v2 Nov 19, 2026
22 of 23 checks passed
@gggritso
gggritso deleted the fix/snapshot-tainted-canvas branch November 19, 2026 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants