• Robert Knight's avatar
    Fix port discovery after a guest iframe is navigated · 03099a20
    Robert Knight authored
    PortProvider previously used a `WeakMap<Window, Set<Channel>>` to keep
    track of which ports had been requested from a particular source frame,
    where the map keys came from `MessageEvent.source`. A problem with this
    approach is that for messages from an iframe, `MessageEvent.source` refers to a
    `WindowProxy` which retains the same identity across page navigations.
    As a result if a guest iframe was navigated to a new page which also
    embedded the client as a guest (or into which the client was
    subsequently injected as a guest), the guest in the new document would
    not be able to retrieve any ports.
    
    Implement a fix whereby each call to `PortFinder.discover` generates a
    random request ID which is sent with the initial port request plus any
    re-sent requests. PortProvider then keeps track of the request IDs it
    has seen and ignores messages with a previously seen request ID.
    
    This change would also fix port discovery if the guest in a frame was
    unloaded and later re-loaded.
    03099a20
port-finder-test.js 3.76 KB