-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add support for recording and replaying adoptedStyleSheets API #989
Conversation
…replace & replaceSync
… optimization not used)
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.
What a great addition to rrweb, thanks for that @Mark-Fenng!
I am however concerned about Safari and breaking playback in that browser, we currently aren't using any polyfills to add support for it in the playback. And on record we could also be breaking things there since we're setting properties which would otherwise be empty, preventing people from doing feature detection.
I made this mistake myself once in the past when building the first iteration of the stylesheet manager and I really wanted to add https://github.com/amilajack/eslint-plugin-compat to the project but as we where using tslint back then instead of eslint I wasn't able to. Maybe this is a good moment to add it since we are using eslint at the moment.
Co-authored-by: Justin Halsall <[email protected]>
Co-authored-by: Justin Halsall <[email protected]>
add more browser compatibility checks
1a694cf
to
2d9aa0b
Compare
@Juice10 Geat catches on compatibility issues of these APIs. I also added the eslint-plugin-compat and configured the browser list for each package. |
…n there's no existed node to replace
Early returns aren't supported yet unfortunately, otherwise this code would be cleaner amilajack/eslint-plugin-compat#523
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.
Great work @Mark-Fenng! Thanks for the changes, I think this is a great addition to rrweb
Background
The adoptedStyleSheets property of the Document or shadowRoot is used for setting an array of constructed stylesheets to be used by the host. reference: https://developer.mozilla.org/en-US/docs/Web/API/Document/adoptedStyleSheets
Nowadays, more and more web libraries and pages are using custom web components and this API like Lit, material wc. There’s also a related issue #669.
Implementation
This PR mostly follows @Yuyz0112's proposal: #669 (comment).
I create a StyleMirror which is similar to Node Mirror that we used to manage nodes and their serialized ids. In the recording side, if I get a constructed stylesheet from adoptedStyleSheets API, firstly ask StyleMirror whether it appears before or not. If it’s a new stylesheet, I add it to the StyleMirror, assign a new unique styleId, and serialize it into an event.
Here’s an example event to serialize a new stylesheet object:
If it already has a styleId, I will reference (reuse) it directly like this:
On the replaying side, I deserialize stylesheet objects from events and assign them to the target documents.
Changes
Other things
Because adoptedStypeSheets is a new API, there is a browser compatibility issue for the replaying side. The replayer can replay adoptedStyleSheet events only when the browser supports the API. reference: https://caniuse.com/?search=adoptedStyleSheets
Special thanks to @lele0108 's sponsorship for making this pull request possible.
Effect
Before this PR:
old-version.mp4
After this PR applied:
demo.mp4