1. 19 Sep, 2023 2 commits
    • Robert Knight's avatar
      Remove strict checks on source/target frame roles · d58567d0
      Robert Knight authored
      These checks had not been updated for the addition of the "profile" application.
      Also at a conceptual level the responsibility for deciding which types of frames
      are allowed to connect to each other belongs to the `PortProvider` in the host
      frame, not the `PortFinder` in other frames.
      d58567d0
    • Robert Knight's avatar
      Handle sidebar iframe reloads more gracefully · fcf87072
      Robert Knight authored
      If the `<hypothesis-sidebar>` element is moved around in the DOM, this can cause
      the sidebar to reload. There may also be other causes of the sidebar reloading
      (eg. process crash for out-of-process iframe?). If the sidebar loads a second
      time, it will fail to connect to the host frame since `PortProvider` will try to
      re-use the `MessageChannel` it has already allocated, but sending that channels
      ports will fail since they have already been transferred.
      
      Recovering from this scenario fully involves a lot of changes since all the
      places that have a connection to the sidebar would need to support replacing
      that channel. Also various state in host/guest frames (eg. currently loaded
      annotations) will be out of sync and need resetting.
      
      What this commit does is just to handle the situation more gracefully, by
      logging a meaningful error in the console and, after a delay, showing an error
      message in the sidebar telling the user to reload the page. This also avoids
      spamming Sentry [1] with errors about a situation that is out of our control. We
      get a lot of error reports about this each month, mainly from certain
      high-traffic pages that embed the client, but so far no actual complaints from
      users about Hypothesis not working. Therefore it doesn't yet seem valuable
      enough to do all the work to recover from a sidebar frame reload automatically.
      
      [1] https://hypothesis.sentry.io/issues/2975780063/
      fcf87072
  2. 18 Sep, 2023 10 commits
  3. 15 Sep, 2023 3 commits
    • Robert Knight's avatar
      Cleanup and abort if annotator finds existing `<hypothesis-sidebar>` · a7239d05
      Robert Knight authored
      Fix an issue where multiple Hypothesis sidebar (and possibly notebook, profile
      etc.) iframes could get created when saving a local snapshot of a web page where
      Hypothesis was loaded. This would lead to one of the sidebars not functioning
      because the host frame only allows one sidebar to connect.
      
      Aside from there being multiple sidebars, there are other problems in such an
      environment, such as the URL not matching the original page URL.  Hence this
      commit handles this scenario by detecting it when the annotator bundle loads,
      removing the existing `<hypothesis-sidebar>` element and then aborting startup.
      
      The end result for the user is that if they save a snapshot of a page with
      Hypothesis loaded and later reload it, the visible highlights will still appear
      in the page but other Hypothesis UI elements will not be visible.
      
      The scenario described here applies in Chrome when saving a snapshot with the
      "Web Page, Complete" file type. If the user instead selects "Web Page, HTML
      only" or "Web Page, single file" they will get different results, but those
      were already not problematic because no JS was executed.
      
      Fixes https://github.com/hypothesis/client/issues/5827
      a7239d05
    • Robert Knight's avatar
      Ignore coverage for edge-case early exit · 5c3cdd5f
      Robert Knight authored
      This is only relevant in the edge case that `document.documentElement` is null.
      5c3cdd5f
    • Robert Knight's avatar
      Handle `document.documentElement` being null when installing shortcut · b3e062dc
      Robert Knight authored
      `documentElement` is never null in "normal" circumstances, but it can be `null`
      if something explicitly removes the root element from the document, and this
      situation has apparently occurred in the wild on some ChromeOS devices [1].
      
      [1] https://hypothesis.sentry.io/issues/3987992034
      b3e062dc
  4. 14 Sep, 2023 2 commits
  5. 13 Sep, 2023 2 commits
    • Robert Knight's avatar
      Fix error if `matchShortcut` is called with non-KeyboardEvent · 54cae019
      Robert Knight authored
      Work around an exception when testing for shortcuts in `keydown` event handlers,
      if the handler is called with an argument that is not a `KeyboardEvent`, and is
      missing the expected `key` property. The workaround has been added to
      `matchShortcut` because it is easier to do there than remember for each
      `keydown` event handler, although there is a risk that other code in these
      handlers could get caught out by the same issue.
      
      I was able to reproduce this problem locally in Chrome 118 when using autofill
      to insert text into the search input field (see comments), though there might be
      other causes as well.
      
      This should fix https://hypothesis.sentry.io/issues/3987386810/?project=69811
      54cae019
    • Robert Knight's avatar
      Add missing null check for content frame in `ExportAnnotations` · 42858d04
      Robert Knight authored
      The `store.defaultContentFrame` selector had an incorrect return type, `Frame`
      instead of `Frame|null`, because `frames[0]` has the static type `Frame`, even
      though this can actually return undefined at runtime. As a result, TypeScript
      didn't catch a missing null check when generating the default filename for the
      export.
      
      Fixes https://github.com/hypothesis/client/issues/5818
      42858d04
  6. 12 Sep, 2023 1 commit
    • Robert Knight's avatar
      Add knowledge base links to Import / Export tabs · c01e96ec
      Robert Knight authored
       - Add links at the top of the Import and Export tabs to a knowledge base
         article with information about using these features for various workflows.
      
       - Use a `<label>` for the "Select Hypothesis export file", since it is
         logically a label. This label is associated to the file input via `htmlFor`,
         but note the custom file input will still read the fixed button text ("Select
         a file")
      
       - Make labels bold in Import / Export tab to make them stand out against the
         help text, and also for consistency with the "Share" tab
      
      Part of https://github.com/hypothesis/client/issues/5783
      c01e96ec
  7. 11 Sep, 2023 13 commits
  8. 08 Sep, 2023 1 commit
  9. 07 Sep, 2023 2 commits
  10. 05 Sep, 2023 1 commit
  11. 04 Sep, 2023 3 commits