hypothesis / browser-extension

The Hypothesis browser extensions.
BSD 2-Clause "Simplified" License
477 stars 125 forks source link

Direct links don't work (reliably?) if target page embeds the client #1355

Open robertknight opened 10 months ago

robertknight commented 10 months ago

We changed the way that the bouncer service (hyp.is) activates the extension and configures the extension's client to navigate to a particular annotation. This has ended up breaking direct links to annotations on target pages that embed the client.

Example bouncer link: https://hyp.is/zxCckEH4Ee6tPkNgrU9gKw/chem.libretexts.org/Courses/University_of_Arkansas_Little_Rock/Chem_1403%3A_General_Chemistry_2/Text/10%3A_Review/10.01%3A_Lewis_Dot_Structures

If you follow this link in a Chrome browser that has our extension installed, what happens is:

  1. The bouncer (hyp.is) service sends a message to our extension instructing it to navigate to the target page and scroll to an annotation
  2. The extension's service worker receives the message (see src/background/index.ts) and initiates the navigation
  3. When the navigation completes, the extension injects configuration in the page with the details of the annotation to scroll to and attempts to activate the extension in the tab

When the target page does not embed the client, this all works fine. The problem comes when the target page embeds the client. In this case step (3) will inject configuration into the page, but the extension's client does not activate because the embedded client is already there. The embedded client meanwhile will probably not read this configuration because it was not present in the page when the embedded client initially loaded.

Some possible solutions:

Slack thread: https://hypothes-is.slack.com/archives/C2C2U40LW/p1693313716998819?thread_ts=1692964809.673489&cid=C2C2U40LW

janraev commented 10 months ago

Hubspot ticket: https://app.hubspot.com/contacts/6291320/record/0-5/1855939933

mkdir-washington-edu commented 9 months ago

See also:

dwhly commented 9 months ago

Could possibly add libretexts.org to bouncer's whitelist of sites that embed the client.

janraev commented 1 month ago

Same issue https://app.hubspot.com/contacts/6291320/record/0-5/2767399244

dltj commented 1 month ago

I'm probably that report immediately above:

I'm using an adaptation of Dan Whaley's DropDoc web application to generate transcripts of YouTube videos and provide a way to annotate bits of the transcript. For example, this post on Mastodon about a recent CNI briefing on JSTOR's LLM-driven bot on journal articles: https://code4lib.social/@dltj/112515330860312283. The links on that Mastodon post work fine. However, if I link to a specific Hypothes.is annotation (as I did in this Mastodon post: https://code4lib.social/@dltj/112515476692600406), the JavaScript bits that enable the reader to jump to a specific time in the YouTube recording stop working. (In other words, if you click on a transcript line in the "media.dltj.org" version of the transcript, the video player jumps to the right time. Through "via" though, it does not.) It seems like the YouTube player is not getting initialized; I see this in the console:

Uncaught TypeError: player is undefined at index.html:1847:9

Digging further, the player is defined by onYouTubeIframeAPIReady() in my JavaScript, but that function isn't being called. When I look at the page without going through Via, I see that the function is being called by a bit of YouTube's JavaScript:

Looking at the browser console, I see that the HTTP request is getting redirected by Via to:

So I'm guessing that Hypothesis has blocked that bit of JavaScript. Are there any known workarounds? [Now adding: I see that there are no known workarounds. Also...the code, in all its mid-refactoring ugliness, is on GitHub.]