1. 15 Oct, 2021 3 commits
    • Robert Knight's avatar
    • Robert Knight's avatar
    • Robert Knight's avatar
      Replace Browserify with Rollup · bcf7ef0a
      Robert Knight authored
      Replace Browserify with Rollup as a module bundler. This brings several
      advantages:
      
      - It is a more modern bundler that has better support in the ecosystem,
        more active maintenence, fewer dependencies and is easier to write plugins for.
        The core team also maintain most of the plugins that we need.
      
      - It has native support for modern platform features like ES modules,
        including dynamic import for lazy-loading of functionality.
      
      - It generates smaller bundles due to its ability to do tree shaking and scope hoisting.
      
      The new bundles are generated as ES modules rather than UMD / IIFE bundles.
      Our target browsers now all support ES modules and this will enable us to use
      native static/dynamic imports for code splitting or lazy-loading of
      functionality in future.
      
      The initial Rollup build generates one bundle per application (boot script,
      annotator, sidebar). This simplifies the build process and minimizes production
      bundle size, at the cost of making incremental updates during development
      slightly slower.
      
      Build performance is currently similar to or a little slower than Browserify.
      We can optimize this by adding caching of transforms (mainly Babel) and
      pre-building of a vendor bundle containing large dependencies.
      
      As part of changing the bundler this also changes how the code is packaged
      for tests.  We now do the bundling ourselves rather than using a Karma
      integration. This makes it much easier to inspect the processed code and fix
      problems. It also makes it easier to optimize the bundle building in future.
      bcf7ef0a
  2. 11 Oct, 2021 14 commits
  3. 08 Oct, 2021 2 commits
    • Eduardo Sanz García's avatar
      Add documentation to test cases · 0356d203
      Eduardo Sanz García authored
      * add information about why to use `window.load` instead of
        `document.DOMContentLoaded` to check when a document is ready
      
      * use an invalid local URL (http://localhost:1) to speed DNS lookup in
        the test
      
      * include some comments about the use of `waitForFrameObserver` in the
        tests
      0356d203
    • Eduardo Sanz García's avatar
      Provide `externalContainerSelector` config in a different way · ba206357
      Eduardo Sanz García authored
      Instead of override the window.hypothesisConfig, I provide the
      `externalContainerSelector` through a JSON script tag. This allows a
      more incremental way to add configuration options.
      ba206357
  4. 07 Oct, 2021 12 commits
    • Robert Knight's avatar
    • Robert Knight's avatar
      Proxy client asset locations from host frame · fc314751
      Robert Knight authored
      When injecting the client into a guest frame, proxy any custom asset locations
      specified via `.js-hypothesis-config` script tags in the host frame.
      These are used by the browser extension and needed for the VitalSource
      integration to work in that context.
      
      We could probably avoid copying the `sidebarAppUrl` and `notebookAppUrl`
      settings for guest-only frames. This will require changes to the boot
      script and possibly the annotator entry point.
      fc314751
    • Robert Knight's avatar
      Revise HypothesisInjector class docs · 576b7355
      Robert Knight authored
      576b7355
    • Robert Knight's avatar
    • Robert Knight's avatar
      Implement `Guest.injectClient` · a8b50cf3
      Robert Knight authored
      Implement the `injectClient` method of Guest that is used by
      integrations (eg. VitalSource) to inject the client into a chosen frame.
      
      In the process the `HypothesisInjector` class has been extracted out of
      the `CrossFrame` class, since it is unrelated to the rest of the
      functionality in that class and only lived their because of its
      dependence on the `Bridge` instance, which will soon be removed (see
      https://github.com/hypothesis/client/pull/3812). It is now constructed
      and used directly by the `Guest` class instead.
      a8b50cf3
    • Robert Knight's avatar
      Add `injectClient` method to HypothesisInjector · 3cb14c36
      Robert Knight authored
      Expose the existing logic for injecting the client into a target frame
      in HypothesisInjector as a public `injectClient` method and modify it to
      wait for the document to be loaded if necessary. This method will be
      used by the guest class to inject the client into specific frames when
      requested by the current integration.
      
      In the case where the frame is discovered by `FrameObserver` this means
      that `onDocumentReady(frame)` will be called twice. That's OK because
      the second call will just complete immediately if the frame is already
      ready.
      3cb14c36
    • Robert Knight's avatar
      05b6a932
    • Robert Knight's avatar
      Route guest frame unload notifications via host frame · c56cf3fa
      Robert Knight authored
      Change how the sidebar is notified of guest frames being unloaded to
      support guest frames where the client has been loaded via means other
      than `HypothesisInjector` or where the guest is cross-origin.
      
      Instead of listening for the guest frame's 'unload' event from the
      parent frame in `HypothesisInjector`, the guest frame instead listens
      for this event itself and sends a `hypothesisGuestUnloaded` message to
      the host frame via `window.postMessage`, which in turn is handled in the
      `Sidebar` class to relay it to the sidebar app via a `destroyFrame` RPC
      call. This indirect route works around a bug in Safari (see code
      comments).
      
      As well as supporting future use cases, this also simplifies the
      `HypothesisInjector` class as it no longer needs access to the `Bridge`.
      c56cf3fa
    • Robert Knight's avatar
      Add toggle button to "Annotatable iframe" test page · 84444667
      Robert Knight authored
      This enables testing handling of the client's discovery of existing
      frames (on page load) as well as handling of dynamic addition and removal after
      the client has started.
      84444667
    • Robert Knight's avatar
      Add test for `FrameSyncService.notifyHost` · d7a7f095
      Robert Knight authored
      d7a7f095
    • Robert Knight's avatar
      Use separate channels for guest / host messages from sidebar · 564e8cfe
      Robert Knight authored
      Use separate channels for sending messages to guests vs the host in the
      sidebar, even for the common case when there is only one guest and it is
      the same frame as the host.
      
      This change makes it clear for readers which part of the annotator code
      is intended to handle a particular message from the sidebar. It is also
      a step towards supporting host frames that are not guests. This will be
      needed in ebook readers where the host frame provides the navigation UI
      and contains the frame displaying the book content, but should not be
      annotatble itself.
      
       - Remove the `bridge` service in the sidebar. The `frameSync` service
         now provides the entry point for other services/components to make RPC calls
         to the host or guest frames. Currently the only use case is
         sending notifications to the host via `FrameSyncService.notifyHost`.
      
       - Create separate `Bridge` instances in `FrameSyncService` for sidebar
         <-> guest and sidebar <-> host communication. The sidebar <-> guest
         bridge works the same as before. The sidebar <-> host bridge
         is established by having `FrameSyncService` create a MessageChannel
         when sending the `hypothesisSidebarReady` notification to the host.
      
         The sidebar / host frames then add respective ports of this channel
         to a Bridge instance.
      
       - Change the various existing RPC calls between frames to use either
         the guest <-> sidebar or host <-> sidebar communication channels as
         appropriate
      564e8cfe
    • Robert Knight's avatar
      Show URLs for all connected frames in help panel · 4d3f72e9
      Robert Knight authored
      Show the URLs of all frames connected to the sidebar in the Version info
      tab of the Help panel. Previously only the URL of the main frame was
      shown.
      
      Initially this will mainly be useful for client developers to check that
      the expected set of frames are connected to the sidebar in different
      scenarios.
      4d3f72e9
  5. 06 Oct, 2021 6 commits
  6. 04 Oct, 2021 3 commits