Repository navigation
fix(snapshot): Clear leftover nodes when document.open() is skipped - #350
Merged
Merged
Conversation
…d doctype Full snapshots whose doctype comes after <html>, or that carry a second doctype (including the one written for BackCompat documents), made rebuild() throw a HierarchyRequestError and crash the replayer. Insert the doctype before the root element, or replace the existing one, instead. Co-Authored-By: George Gritsouk <george.gritsouk@sentry.io>
gggritso
marked this pull request as draft
October 28, 2026 18:57
The previous doctype-placement change assumed a snapshot with the doctype after <html>, but a crashing replay has a normal [doctype, html] snapshot. Both production HierarchyRequestError messages reproduce instead when document.open() is a no-op because the iframe document's parser was aborted: the previous rebuild stays in place and the new doctype can't be appended. Remove any leftover children after open() and revert the doctype-placement change. Co-Authored-By: George Gritsouk <george.gritsouk@sentry.io>
The existing unit test stubs document.open(). This adds puppeteer tests that abort the iframe document's parser the way browsers do, with window.stop() and with a link click that never commits a new document (a 204), check that open() is now a no-op, and then rebuild. Both fail with "Can't insert a doctype after the root element" without the fix. Also drop the changeset, since sentry-v2 no longer uses changesets. Co-Authored-By: George Gritsouk <george.gritsouk@sentry.io>
document.open() is skipped
gggritso
reviewed
Nov 6, 2026
Address review feedback: replace the parameterized abort triggers with two explicit test cases that share setup helpers, drop the leftover headless comment, and say in rebuild.ts that open() doesn't throw when it skips clearing the document.
Member
|
@cursor review |
There was a problem hiding this comment.
✅ 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 21ee16c. Configure here.
gggritso
marked this pull request as ready for review
November 6, 2026 21:59
logaretm
approved these changes
Nov 9, 2026
logaretm
left a comment
Member
There was a problem hiding this comment.
LGTM, I will handle the compat mode leftover in a separate PR
| // once the document's parser was aborted (e.g. by window.stop()), open() | ||
| // returns without throwing and without clearing the previous rebuild, | ||
| // which would make the appends below throw a HierarchyRequestError | ||
| while (doc.firstChild) { |
Member
There was a problem hiding this comment.
nit: This fixes the crash, but leaves out some stale state like compatMode.
It's a very rare case, I had an agent try it in Chromium, after window.stop() a quirks snapshot stays CSS1Compat, and a standards one stays BackCompat if the previous rebuild was quirks.
I can PR that separately once this one merges, probably will try to replace the entire iframe.
gggritso
added a commit
to getsentry/sentry
that referenced
this pull request
Nov 12, 2026
…130930) Bumps the Sentry JavaScript SDK from 11.7.0 to [11.12.0](https://github.com/getsentry/sentry-javascript/releases/tag/11.12.0), mainly to pick up rrweb [2.46.0](https://github.com/getsentry/rrweb/releases/tag/2.46.0) (getsentry/sentry-javascript#26241). rrweb 2.46.0 fixes: - Clear leftover nodes when `document.open()` is skipped (getsentry/rrweb#350) - Don't record the default value of cleared inputs (getsentry/rrweb#349) - Keep adopted stylesheets on seek when their first host was removed (getsentry/rrweb#352) - Don't throw when tearing down a locked `adoptedStyleSheets` patch (getsentry/rrweb#351) Changes: - `@sentry/browser`, `@sentry/core`, `@sentry/node`, `@sentry/react`: 11.7.0 → 11.12.0 across `static/app`, `static/gsApp`, `static/gsAdmin`, `static/packages/scraps`, and `tests/js`. - `@sentry/rrweb`, `@sentry/rrweb-player`, `@sentry/rrweb-snapshot`: 2.45.0 → 2.46.0, so the replay player uses the same rrweb as the SDK. - `@sentry/rrweb-types`: 2.44.0 → 2.46.0. This drops the duplicate `@sentry/rrweb-snapshot@2.44.0` / `@sentry/rrweb-types@2.44.0` entries from the lockfile. <!-- junior-request-attribution:start --> via **George Gritsouk**. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:slack%3AD0AR76A9F5G%3A1794502210.473359 --> Closes REPLAY-1029 Closes REPLAY-1019 -- [View Session](https://junior-prod.sentry.dev/conversations/slack%3AD0AR76A9F5G%3A1794502210.473359) [[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AD0AR76A9F5G%3A1794502210.473359/?project=4510944073809921) <!-- junior-session-footer:end --> Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: George Gritsouk <george.gritsouk@sentry.io>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The replay player crashes with a
HierarchyRequestErrorwhile it appends the full snapshot's doctype. The error seems to be from trying to jam multipleDOCTYPEdeclarations into the sameiframe.Before building a document,
buildNodeWithSNcallsdoc.close(); doc.open()and expectsdoc.open()to clear the iframe. Browsers skipopen()once the document's parser has been aborted (for example bywindow.stop()). In that case the previous rebuild stays in the iframe, and appending the new doctype runs into the old<doctype>+<html>.The fix removes any children left over after
open(), so the rebuild always starts from an empty document.Fixes REPLAY-1031.
via George Gritsouk.
--
View Junior Session [Sentry]