• Robert Knight's avatar
    Inject client into newly loaded VitalSource book chapters sooner · 9481c420
    Robert Knight authored
    When a new content frame was found in VitalSource the client was only injected
    either if the frame is already loaded, or when the frame next emits a `load`
    event. In the latter case this waits until the document and its subresources
    have fully loaded. This can be slow in EPUB chapters that have a lot of images.
    Improve this by replacing the frame `load` event observer with a call to a new
    `onDocumentReady` function which fires as soon as a document becomes interactive
    (according to its `readyState`).
    
     - Rename existing `onDocumentReady` utility to `onNextDocumentReady` to
       make it clear that it only fires once, and change the implementation to
       be a wrapper around a new `onDocumentReady` function.
    
     - Add new `onDocumentReady` utility which monitors a frame for changes in the
       content document and invokes a callback each time a document becomes _ready_
       (`readyState` is `interactive` or `complete`).
    
     - Redo the tests for utilities in `frame-observer.js` so that they use
       real iframes rather than fake ones. Iframes have a complex interface
       and loading sequence, so we really need to use the real thing for
       tests to give us confidence.
    
     - Use `onDocumentReady` in the VitalSource integration to respond more quickly
       to book content loading in a new content frame.
    
     - Modify several tests for `FrameObserver`, `VitalSourceInjector` and
       `HypothesisInjector` to be less sensitive to exact timings of events,
       as these changed between the previous and new methods for detecting
       when a document is ready.
    
    Fixes https://github.com/hypothesis/client/issues/4270
    9481c420
hypothesis-injector.js 3.33 KB