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

[Bug]: window.CSSStyleSheet is undefined while stopping the recording #1399

Open
1 task done
navaneethsdk opened this issue Jan 17, 2024 · 2 comments
Open
1 task done
Labels
bug Something isn't working

Comments

@navaneethsdk
Copy link

navaneethsdk commented Jan 17, 2024

Preflight Checklist

  • I have searched the issue tracker for a bug report that matches the one I want to file, without success.

What package is this bug report for?

rrweb

Version

2.0.0-alpha.11

Expected Behavior

When stopping a recording with iframes no errors should be ideally thrown. Alternatively, these errors should be prevented with proper guards or properly handled using try-catch statements without sending them to the user's application.

Actual Behavior

Stopping a recording containing iframes, throws the following error:
Screenshot 2024-01-17 at 9 56 26 AM
As shown in the image, the error is getting triggered at:

win.CSSStyleSheet.prototype.insertRule = insertRule;

This issue is a continuation of the previously defined issue: #1057

Actual cause of the issue has not been debugged yet. We don't know why win.CSSStyleSheet becomes undefined.

There were previous attempts to silence these errors:

However, no logic is in place to guard the error from occurring while unsubscribing, specifically, when the return function of the initStylesheetObserver is invoked:

return callbackWrapper(() => {
win.CSSStyleSheet.prototype.insertRule = insertRule;
win.CSSStyleSheet.prototype.deleteRule = deleteRule;
replace && (win.CSSStyleSheet.prototype.replace = replace);
replaceSync && (win.CSSStyleSheet.prototype.replaceSync = replaceSync);
Object.entries(supportedNestedCSSRuleTypes).forEach(([typeKey, type]) => {
type.prototype.insertRule = unmodifiedFunctions[typeKey].insertRule;
type.prototype.deleteRule = unmodifiedFunctions[typeKey].deleteRule;
});
});


A similar situation can also take place over here:

return callbackWrapper(() => {
win.CSSStyleDeclaration.prototype.setProperty = setProperty;
win.CSSStyleDeclaration.prototype.removeProperty = removeProperty;
});

Error associated with the above case: Screenshot 2024-01-17 at 10 15 33 AM

Until the actual error is identified, we can simply add a guard to prevent them from occuring.

Steps to Reproduce

I will present the steps to reproduce the effect. However, I couldn't reproduce the cause.

  1. Setup rrweb.
  2. Trigger error e.g. by adding a line win.CSSStyleSheet = undefined above this line:
    win.CSSStyleSheet.prototype.insertRule = insertRule;
  3. Get errors in console.

Testcase Gist URL

No response

Additional Information

No response

@navaneethsdk navaneethsdk added the bug Something isn't working label Jan 17, 2024
@josephmathew900
Copy link

@eoghanmurray Can you please take a look into this issue when you have some time?

@eoghanmurray
Copy link
Contributor

You could more easily submit a PR than me given the effort required in recreating any given issue (e.g. I don't generally use the regular replayer).
I imagine the win reference is defunct as iframe has been detached from the dom or something, but you'll only know if you check; a debugger breakpoint in the code at the point where the error is thrown or use the 'break on all errors' option in your browser dev tools. You should be able to figure out what bit is not defined; you'll be able to put together a PR with the right type of guard. Even better would be to include a test case in the PR, but that is probably overkill in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants