-
-
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
[Bug]: Cross-origin iframe message listener messages can be duplicated #1577
Comments
I have tried to reproduce the issue with following steps.
It looks like following screenshot. I am switching navigation of iframe same origin. I am not able to reproduce the issue. Can you explain, what I am doing wrong? |
Hi @chetan-187, This is my fault. I attempted to simplify the conditions under which the bug occurs, but I just made it harder to reproduce. Here are clearer steps:
rrweb/packages/rrweb-snapshot/src/snapshot.ts Lines 341 to 353 in 53b83bb
The first call to What's important here is that the rrweb/packages/rrweb/src/record/iframe-manager.ts Lines 78 to 83 in 5c27b76
I have a fix I am using in testing that creates a map of known content windows to prevent the event handler from being installed more than once. That seems to work, but this is obviously a very complex project, so I thought I would seek the input of the maintainers and contributors to ensure there aren't unintended consequences to that fix. [0] Minimal Reproduction Example. Note that you need to replace the cross-origin iframe's src with a real cross-origin iframe that also has rrweb.
|
hey @timabdulla, I can think of simple approach here, to remove the message listener before adding another. Can be done by making iframe-manager a singleton class to main the instance of function Will it work? |
I believe that iframe-manager is already only instantiated once during a
particular recording context. Removing it before adding it would work,
though right now the handler is dynamically constructed, so you'd have to
make it consistent.
El El sáb, 26 oct 2024 a las 10:55, Chetan Lohkare ***@***.***>
escribió:
… hey @timabdulla <https://github.com/timabdulla>, I can think of simple
approach here, to remove the message listener before adding another.
Can be done by making iframe-manager a singleton class to main the
instance of function
or
we can push the removeEventListener function to handlers here every other
observer is pushed to stop the recording.
Will it work?
—
Reply to this email directly, view it on GitHub
<#1577 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAHWJR3BE55VTYRETNN5GKDZ5NKG3AVCNFSM6AAAAABPBXBN6CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMZZGQZTONZWGM>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@timabdulla Is there any way, how can I make it consistent? |
@chetan-187 I think it would be sufficient to simply turn 5c27b76#diff-01af2d33dc0d57c42970a0ab06328c71ea48c696077c60d96023427f27410829R79-R83 could just become:
|
But then, we are trying to access the context of the class in this handleMessage function. Won't it cause any problem? @timabdulla |
Preflight Checklist
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 theIframeManager
, the event listener is added, without regard to whether or not it has already been added. This means that ifattachIframe
is called multiple times (e.g. if navigation occurs within the iframe, causing theload
event to fire), multiple listeners will be installed.This bug was introduced here: 5c27b76#diff-01af2d33dc0d57c42970a0ab06328c71ea48c696077c60d96023427f27410829R80
Steps to Reproduce
Testcase Gist URL
No response
Additional Information
No response
The text was updated successfully, but these errors were encountered: