Skip to content
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

[Observer] Observer doesn't watch for CSSStyleSheet.insertRule #104

Closed
VladimirMilenko opened this issue Aug 1, 2019 · 3 comments · Fixed by #178
Closed

[Observer] Observer doesn't watch for CSSStyleSheet.insertRule #104

VladimirMilenko opened this issue Aug 1, 2019 · 3 comments · Fixed by #178

Comments

@VladimirMilenko
Copy link
Contributor

VladimirMilenko commented Aug 1, 2019

Currently, it is impossible to track calls to insertRule(which is used in CSS-in-JS libraries).
With this, it's impossible to get the styles, which are added dynamically during render phase.

I believe this can be solved by proxying calls to styleElement.sheet.addRule/insertRule

@VladimirMilenko
Copy link
Contributor Author

I was able to do this in following way:

  handleStyleRoot = styleRoot => {
    const handler = {
      apply: function apply(target, thisArg, argumentsList) {
        const result = target.apply(thisArg, argumentsList);
        styleRoot.innerHTML = Array.from(thisArg.rules, x => x.cssText).join('\n');

        styleRoot.sheet.insertRule = new Proxy(styleRoot.sheet.insertRule, handler);

        return result;
      }
    };
    const proxy = new Proxy(styleRoot.sheet.insertRule, handler);
    styleRoot.sheet.insertRule = proxy;
    styleRoot.sheet.insertRule('.rr_track_on {}');
  };

@jperl
Copy link
Contributor

jperl commented Aug 25, 2019

@Yuyz0112 @VladimirMilenko I applied this fix in a hacky way https://github.com/rrweb-io/rrweb/pull/124/files.

It works but if you can provide guidance on how you would like it implemented properly, I would be happy to clean it up into something mergeable.

@dacort
Copy link

dacort commented Dec 13, 2019

Is this the same as #58 ?

benjackwhite pushed a commit to PostHog/rrweb that referenced this issue Jul 25, 2023
Hopefully fixes the build errors in
highlight/highlight#5239

Somehow these were getting resolved to the root workspace level
typescript version 5 in that PR.
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 a pull request may close this issue.

3 participants