[Bug]: `window.CSSStyleSheet` is undefined while stopping the recording
navaneethsdk opened this issue · comments
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:
As shown in the image, the error is getting triggered at:
rrweb/packages/rrweb/src/record/observer.ts
Line 862 in b2460a4
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:
rrweb/packages/rrweb/src/record/observer.ts
Lines 861 to 870 in b2460a4
A similar situation can also take place over here:
rrweb/packages/rrweb/src/record/observer.ts
Lines 1021 to 1024 in b2460a4
Error associated with the above case:
![Screenshot 2024-01-17 at 10 15 33 AM](https://private-user-images.githubusercontent.com/56035039/297262623-bc9646b6-3feb-489a-88a7-38eabb498a15.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTk5OTQyMDYsIm5iZiI6MTcxOTk5MzkwNiwicGF0aCI6Ii81NjAzNTAzOS8yOTcyNjI2MjMtYmM5NjQ2YjYtM2ZlYi00ODlhLTg4YTctMzhlYWJiNDk4YTE1LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MDMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzAzVDA4MDUwNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWM5NTU3NDViZGNhZmNjZjY2MDQ0ZjY1OWY4NjZjMjc1ZmEzNWQwYTNjNmIxY2M5OTdiMTY3MDM2MzYyMTYzNjgmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.Y7gvOznE4zFpC1SSKEP7Wnq3xfydlFqMET0NjcYlof4)
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.
- Setup rrweb.
- Trigger error e.g. by adding a line
win.CSSStyleSheet = undefined
above this line:
rrweb/packages/rrweb/src/record/observer.ts
Line 862 in b2460a4
- Get errors in console.
Testcase Gist URL
No response
Additional Information
No response
@eoghanmurray Can you please take a look into this issue when you have some time?
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.