rrweb
rrweb copied to clipboard
[Bug]: Cross-origin iframe message listener messages can be duplicated
Preflight Checklist
- [X] 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.17
Expected Behavior
The event listener for cross-origin iframe events should only ever be added once to prevent duplicate message-handling.
Actual Behavior
Every time attachIframe is called in the IframeManager, the event listener is added, without regard to whether or not it has already been added. This means that if attachIframe is called multiple times (e.g. if navigation occurs within the iframe, causing the load event to fire), multiple listeners will be installed.
This bug was introduced here: https://github.com/rrweb-io/rrweb/commit/5c27b763192bda9dd91806f95df7c1cd0ab083a6#diff-01af2d33dc0d57c42970a0ab06328c71ea48c696077c60d96023427f27410829R80
Steps to Reproduce
- Create an HTML document that contains a same-origin iframe that itself contains a cross-origin iframe.
- Cause navigation event to occur within the same-origin iframe while still having the iframe's document contain a cross-origin iframe.
- Now, all messages from the cross-origin iframe will be handled twice, causing duplicate events.
Testcase Gist URL
No response
Additional Information
No response