-
Notifications
You must be signed in to change notification settings - Fork 198
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
Get Hypothesis client working in new VitalSource reader #3590
Comments
Ah - I think the problem here is one that we encountered while looking into a new inter-frame communication system. The client's current logic for the sidebar discovering guests involves the sidebar recursively enumerating frames in the window using |
Using this hack enables the sidebar to discover the host frame even if the host frame is contained within a shadow root: diff --git a/src/shared/discovery.js b/src/shared/discovery.js
index faa1297a8..a5caa2663 100644
--- a/src/shared/discovery.js
+++ b/src/shared/discovery.js
@@ -110,7 +110,7 @@ export default class Discovery {
// Perform a top-down, breadth-first traversal of frames in the current
// window and send messages to them.
- const queue = [this.target.top];
+ const queue = [this.target.parent];
while (queue.length > 0) {
const parent = /** @type {Window} */ (queue.shift());
if (parent !== this.target) { I tested this by unloading the production client from within the frame in VitalSource viewer that contains the book chapter content and Hypothesis client, and then loading in my local development client: var s = document.createElement('script');s.src='http://localhost:5000/embed.js';document.body.appendChild(s); This allows the Hypothesis sidebar to show up, although it looks odd because it is constrained to the iframe where the book content is displayed: |
Looking at the URL that the Hypothesis client gets for the test document I'm looking at, there is something that looks like a junk/test query param ( https://jigsaw.vitalsource.com/books/9781400847402/epub/OEBPS/13.chapterfive.xhtml?favre=brett We need to make sure annotations are not lost if that query param is later lost or changed. We might want to parse the book ID and chapter reference out of the URL and turn that into some custom URN that we can use as an alternative search URI for the document, similar to how the document fingerprint is used for PDFs. |
Initially, I tried to if/else portions of the code to accommodate for `MessagePort`, aiming to avoid duplication of the code (like I did for `shared/frame-rpc.js` #3565). However, I found that, unlike `shared/frame-rpc.js`, this resulted into a spaghetti-type of code, not very understandable. Then, I decided to create two internal methods to support both the current communication using `Window` and the new `MessagePort`. This in my opinion leads to a clearer results, although some code is duplicated in both methods. This PR will result on a reduction in code coverage, which will be fix by #3590.
Initially, I tried to if/else portions of the code to accommodate for `MessagePort`, aiming to avoid duplication of the code (like I did for `shared/frame-rpc.js` #3565). However, I found that, unlike `shared/frame-rpc.js`, this resulted into a spaghetti-type of code, not very understandable. Then, I decided to create two internal methods to support both the current communication using `Window` and the new `MessagePort`. This in my opinion leads to a clearer results, although some code is duplicated in both methods. This PR will result on a reduction in code coverage, which will be fix by #3590.
Initially, I tried to if/else portions of the code to accommodate for `MessagePort`, aiming to avoid duplication of the code (like I did for `shared/frame-rpc.js` #3565). However, I found that, unlike `shared/frame-rpc.js`, this resulted into a spaghetti-type of code, not very understandable. Then, I decided to create two internal methods to support both the current communication using `Window` and the new `MessagePort`. This in my opinion leads to a clearer results, although some code is duplicated in both methods. This PR will result on a reduction in code coverage, which will be fix by #3590.
Initially, I tried to if/else portions of the code to accommodate for `MessagePort`, aiming to avoid duplication of the code (like I did for `shared/frame-rpc.js` #3565). However, I found that, unlike `shared/frame-rpc.js`, this resulted into a spaghetti-type of code, not very understandable. Then, I decided to create two internal methods to support both the current communication using `Window` and the new `MessagePort`. This in my opinion leads to a clearer results, although some code is duplicated in both methods. This PR will result on a reduction in code coverage, which will be fix by #3590.
Following #3599, Hypothesis is now minimally functional with the new VitalSource reader. See test assignment at https://hypothesis.instructure.com/courses/125/assignments/1518. Leaving aside the fact that the current sidebar UI design looks weird floating in mid-air, the main functional issue is that the iframe in which the book content is presented and highlights appear is not contrained to the real viewport but is in fact really tall: As a result, UI elements that should appear at the top and bottom of the viewport in the viewer do not. Instead they are outside the visible area: I'm not sure in this situation if there is a way for the Hypothesis client to determine what proportion of the document is visible in the containing document. Might be worth testing whether this is possible with I suspect having a really tall iframe whose viewport lies outside the bounds of what is actually visible to the user is going to cause problems in browsers as well as for us. I also wonder whether it might affect browser rendering optimizations that make use of knowledge about what content is inside or outside the viewport. I'm going to re-open this issue and update the PR description. |
An additional issue with both the old and new VitalSource readers is that they don't work in Safari, when the VS reader is loaded inside an iframe. Upon loading the assignment the user is greeted with: Additionally the "Support Centre" link doesn't work. Clicking it results the following console error:
I expect this problem relates to Safari's tracking prevention features. The Support Centre link that this form tries to direct Safari users to doesn't clearly help them. The only obviously relevant option is "Block all cookies", which is de-selected by default, and just making sure that is unchecked is not enough in current Safari versions. There is also a "Prevent cross-site tracking" option. Unchecking that does allow the reader to work in Safari, but we really don't want to have ask users to make that global change, even if only temporarily. |
A possible solution for the tall-iframe issue raised in #3590 (comment) is to load the Hypothesis sidebar into the parent frame of the one that actually contains the book chapter content. The structure of the frame tree when looking at a VitalSource + Hypothesis assignment, configured to load in a new tab, is:
The Hypothesis client is currently being loaded into frame (4). We could instead load the client into frame (3) and use the client's support for annotating same-origin iframes to support annotating in frame (4) while displaying the sidebar in frame (3). I tried doing this manually by unloading the client from frame (4), adding an The screenshot above shows that the sidebar now displays correctly when the content is scrolled, unlike before. Having the content in a separate frame from the sidebar causes other problems however:
Fully resolving all issues with multi-frame support in (3) is probably quite a large project. In this case we might be able to simplify the problem by instead still supporting only a single guest, but allow it to be a different frame than the sidebar. In addition to the above issues, some code in the new reader is triggering frequent console errors when the client is loaded into frame (4) and annotation is happening in frame (3): This error is happening in const triggerBrowserEvent = (eventName, data = {}) => {
let event = new CustomEvent(eventName, {
detail: { ...data },
});
// trigger the event in this wrapping window case other inner docs care
dispatchEvent(event);
// also pass the event up the chain (this method could use a better name)
sendEventUp(event, data);
}; The problem of unexpected objects being passed to |
The console errors mentioned in #3590 (comment) should be fixed by #3611 which eliminates most usage of |
Add a test case for tall iframes where the height of the frame is set to match the document height. This mimics how the new VitalSource Bookshelf reader presents book content. See #3590 (comment)
Add a test case for tall iframes where the height of the frame is set to match the document height. This mimics how the new VitalSource Bookshelf reader presents book content. See #3590 (comment)
VitalSource have modified their reader so that it is no longer using a tall iframe. This means that loading the Hypothesis client directly into the frame where the current book content is displayed is now an option again: Loading the client into the parent frame still has an advantage in that it avoids the client being rebooted each time you switch between frames, which can allow us to fetch and display annotations for the new content more quickly. |
The Hypothesis client is now working with the new VS reader for ebooks, in the case where the client is loaded directly into the content frame, as it currently is in the LMS. When the client is loaded into the parent frame, as is the case when using the browser extension for example, things partly work but there is big a list of issues with our multi-frame support that we are working our way through. There is a tracking issue at #3798 which lists all the parts of this. One major element of fixing these multi-frame support issues is the deployment of new infrastructure in the client for setting up the communication between different frames. We have now shipped this, but ran into issues with errors in various cases when a certain frames try to connect. See #3986. It turns out that many of these are longstanding issues which just hadn't come to light before now. In many cases these may be due to issues of the environment beyond our control (eg. a web-based proxy breaks browser APIs in strange ways) and so we want to just ignore them. Nevertheless we're having to work our way through them and make sure we haven't broken anything important. In future we will probably want to make VS in the LMS context work like it does in the browser extension, with the client loaded into the container frame. This will make navigating between chapters / PDF pages quicker, as the client doesn't have to be reloaded each time, and also allow us to preserve state when navigating between chapters. Work to support PDF-based books is ongoing. We deployed initial support and have two major tasks ahead of us:
|
The Hypothesis-enabled version of the VitalSource Bookshelf application has been updated to use a new version of their reader. It can be tested at https://hypothesis.instructure.com/courses/125/assignments/1518. (Caveat: As of 2021-07-19 there is currently an issue that the new reader is not used if the window size is below some threshold (~1200px?))
The Hypothesis client is being loaded and configured in the new reader, but the sidebar is not visible. When a selection is made the Annotate and Highlight buttons appear, but often obscured by the existing VS controls. Clicking on the buttons does not cause the sidebar to appear however.
Update 2021-07-25: The issue with the sidebar not appearing has been resolved, but this now reveals an additional problem where the sidebar controls become inaccessible when the viewport is scrolled. See #3590 (comment). We need to explore some options and talk with the VS team about ways to resolve this.
The text was updated successfully, but these errors were encountered: