GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(rrweb): Don't throw when tearing down a locked `adoptedStyleSheets` patch by sentry-junior[bot] · Pull Request #351 · getsentry/rrweb

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Oct 30, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

rrweb patches adoptedStyleSheets on every document so that it can capture dynamically added stylesheets. Setup copied configurable from the current adoptedStyleSheets property, and teardown redefined the property. Teardown throws TypeError: Cannot redefine property: adoptedStyleSheets in two cases:

  • the prototype's adoptedStyleSheets property was already non-configurable, so our own property started out locked (maybe an extension caused this), or
  • another script locked our property during recording (a non-configurable redefine, or Object.seal/Object.freeze on document).

When it throws, the rest of teardown is skipped. In the Replay SDK this happens inside sendBufferedReplayOrFlush → stopRecording(), so the buffered replay never restarts in session mode, and we lose everything after the error.

This PR makes a few changes.

Firstly, the adoptedStyleSheets patch is now marked as configurable: true which means it's always safe for us to remove the patch that we ourselves added. There is also a bit of checking to make sure that we are able to set adoptedStyleSheets back to what it was before we tampered with it. Using Reflect. fails quietly instead of erroring out.

Secondly, the teardown process is now a bit safer to run. If there's an exception thrown during one of the steps, the other steps still run.

I think it might be good for us to add some telemetry around this, but I'm not confident what it would be yet, so I left it out. I also think this might be a worthy upstream into rrweb, but I'm not sure about that either.

Closes REPLAY-1019

--

View Session [Sentry]

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@sentry-junior @gggritso
fix(rrweb): Don't throw when tearing down a locked adoptedStyleSheets…
db2eaf5
… patch

rrweb patches `adoptedStyleSheets` on each document and shadow root it
records, copying `configurable` from the prototype. If the prototype's
property was non-configurable, or another script locked our property
(non-configurable redefine, `Object.seal`/`freeze`) during recording,
cleanup threw `TypeError: Cannot redefine property: adoptedStyleSheets`.
That aborted the rest of teardown and, in the Replay SDK, stopped the
buffer-to-session restart.

- Always install the patch as configurable, and remove it with
  `Reflect.deleteProperty`/`Reflect.defineProperty` instead of
  redefining it.
- If it can't be removed, leave it behind as a pass-through and reuse it
  on the next recording.
- Skip the patch if the host already has a non-configurable own property.
- Run every teardown step in `record()` and `initObservers()` even if one
  throws, then rethrow the first error.

Refs REPLAY-1019

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

linear-code Bot commented Oct 30, 2026

Copy link
Copy Markdown

REPLAY-1019

sentry-junior[bot] reacted with eyes emoji
All reactions
  • 👀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

gggritso
gggritso reviewed Nov 5, 2026
View reviewed changes

@gggritso gggritso left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Overall this makes sense but I have a lot of questions about the behaviour

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread .changeset/adopted-stylesheets-teardown.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/rrweb/src/utils.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/rrweb/src/record/observer.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/rrweb/src/record/observer.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/rrweb/src/record/observer.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/rrweb/src/record/observer.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/rrweb/src/record/observer.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/rrweb/src/record/observer.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/rrweb/test/record/adopted-stylesheets-lock.test.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

@sentry-junior
ref(rrweb): Simplify the adoptedStyleSheets patch after review
0929ae2
Drop the per-host patch registry. Each observer keeps its own setter and
a recording flag, and teardown removes the property only if it is still
ours. If another script locked it meanwhile, it stays as a pass-through
and later recordings skip the patch, as they do for any pre-existing lock.

Also skip the patch when the host is sealed or frozen, explain why
configurable: true is safe, rename callAllHandlers to
runAllEvenIfOneThrows, keep the original hostId code, and drop the
changeset, which this fork does not use for releases.
gggritso
gggritso reviewed Nov 5, 2026
View reviewed changes

@gggritso gggritso left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Starting to look good, a few more questions though

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/rrweb/src/record/index.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/rrweb/src/record/observer.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/rrweb/src/record/observer.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/rrweb/src/record/observer.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/rrweb/test/record/adopted-stylesheets-lock.test.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/rrweb/test/record/adopted-stylesheets-lock.test.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/rrweb/test/record/adopted-stylesheets-lock.test.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

@sentry-junior
ref(rrweb): Clarify adoptedStyleSheets teardown and simplify its tests
9d9c486
Rename runAllEvenIfOneThrows to runAllAndRethrowFirstError and pass record()'s
final cleanup steps to it instead of wrapping it in try/finally. Rename the
saved own descriptor and the patched setter so teardown's ownership check
reads clearly, and write the configurable comment in the present tense.

Replace the lock-parameterised test helper with one test per scenario that
does its own setup and uses plain assertions. Shared recording helpers are
installed in the page in beforeEach.
gggritso
gggritso reviewed Nov 6, 2026
View reviewed changes

@gggritso gggritso left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Looking good, just a few more tweaks needed before we can open this up

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/rrweb/src/record/observer.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/rrweb/src/record/observer.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/rrweb/src/record/observer.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/rrweb/src/record/observer.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/rrweb/src/utils.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

@gggritso gggritso changed the title fix(rrweb): Don't throw when tearing down a locked adoptedStyleSheets patch fix(rrweb): Don't throw when tearing down a locked adoptedStyleSheets patch Nov 6, 2026
sentry-junior Bot added 2 commits November 6, 2026 21:10
@sentry-junior
ref(rrweb): Return teardown errors from runAll and clarify adoptedSty…
8a872b2
…leSheets names

runAll now runs every handler and returns the errors they threw. record()'s
stop function and initObservers()'s cleanup rethrow the first one, so the SDK
still sees the same failure as before.

Rename the adoptedStyleSheets setter and active flag to say what they belong
to, and reword the comments to name where each descriptor comes from and to
say that the ownership check and the Reflect calls are there to be safe.
@sentry-junior
Merge remote-tracking branch 'origin/sentry-v2' into pr
4259a1e
@gggritso

gggritso commented Nov 6, 2026

Copy link
Copy Markdown
Member

@cursor review

cursor[bot] reacted with thumbs up emoji sentry-junior[bot] reacted with eyes emoji
All reactions
  • 👍 1 reaction
  • 👀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

cursor[bot]
cursor Bot reviewed Nov 6, 2026
View reviewed changes

@cursor cursor Bot left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

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 4259a1e. Configure here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@gggritso
gggritso marked this pull request as ready for review November 6, 2026 21:59
logaretm
logaretm approved these changes Nov 9, 2026
View reviewed changes

@logaretm logaretm left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Looked like #352 to me at a glance, but they are actually two separate bugs.

LGTM!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/rrweb/src/record/observer.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

@gggritso
gggritso merged commit 4b75e32 into sentry-v2 Nov 10, 2026
21 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@gggritso
gggritso deleted the fix/adopted-stylesheets-teardown branch November 10, 2026 03:46
@sentry-junior sentry-junior Bot mentioned this pull request Nov 12, 2026
chore(deps): Bump sentry-javascript to 11.12.0 and rrweb to 2.46.0 getsentry/sentry#130930
Merged
gggritso added a commit to getsentry/sentry that referenced this pull request Nov 12, 2026
@sentry-junior @gggritso
chore(deps): Bump sentry-javascript to 11.12.0 and rrweb to 2.46.0 (#…
af1758a
…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/[email protected]` / `@sentry/[email protected]` 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 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@gggritso gggritso gggritso left review comments
@cursor cursor[bot] cursor[bot] left review comments
@logaretm logaretm logaretm approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@gggritso @logaretm
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.