-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Explicitly specify guest/sidebar frames to ping in
startDiscovery
The logic used by guest/host and sidebar frames to find each other in `Discovery#startDiscovery` relied on traversing the frame tree starting from `window.top` using `window.frames`. Since `window.frames` doesn't include frames in shadow roots, this did not work if _both_ the guest and sidebar are contained within a shadow root. The sidebar is always contained in a shadow root created by the `<hypothesis-sidebar>` element, so this simplifies to only working if the guest/host is not contained in a shadow root. For current use cases it is possible for guest frames to get a direct reference to the sidebar frame they should be communicating with and for the sidebar to get direct a reference to the host frame (its parent). This avoids the need for `window.frames` traversal. This commit leverages that by changing `startDiscovery` to take an explicit array of frames to ping. Guest frames invoke `startDiscovery` passing a reference to the sidebar frame and sidebar frames invoke `startDiscovery` passing a reference to the parent (host) frame. This fixes the following scenarios: - Hypothesis not completing loading if host frame is contained within a shadow root. eg. In the VitalSource book reader. - Same-origin guest frames loading Hypothesis after the sidebar has already loaded. See http://localhost:3000/document/parent-frame test case in client dev server. - Multiple sidebars attempting to connect to the same guest frame, if Hypothesis is loaded multiple times in different parts of the frame tree. See http://localhost:3000/document/multi-frames test case in client dev server. This approach has some limitations: - Child guest frames which are not same-origin with the parent host frame are not supported. - Child guest frames which attempt to connect to the sidebar before it has loaded will fail to connect. This could be remedied by making the guest wait for confirmation of the sidebar having loaded before calling `connectToSidebar`. This doesn't affect the host frame since the sidebar pings that frame directly. These limitations are acceptable in the short term but will be remedied by a larger overhaul of inter-frame communication that is currently being worked on.
- Loading branch information
1 parent
86bcb87
commit e27c39b
Showing
9 changed files
with
74 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters