hypothesis / client

The Hypothesis web-based annotation client.
Other
625 stars 194 forks source link

Can't annotate https://community.canvaslms.com/ (issue with tsParticles) #6210

Open robertknight opened 4 months ago

robertknight commented 4 months ago

Steps to reproduce:

  1. Activate the Hypothesis browser extension on https://community.canvaslms.com/t5/Canvas-Studio-Blog/Connecting-Studio-OAuth-via-Postman/ba-p/259739
  2. Select text

Expected: Annotate/Highlight toolbar appears Actual: Toolbar does not appear. Browser console shows an error:

html.ts:135 Uncaught TypeError: n.setStart is not a function
    at Bn.toRange (text-range.ts:292:11)
    at Bn.trimmedRange (text-range.ts:325:49)
    at Zi.getAnnotatableRange (html.ts:130:24)
    at dr._onSelection (guest.ts:818:48)
    at guest.ts:289:14
    at selection-observer.ts:30:9

On this page the Range global has been overwritten with a different object which doesn't have the expected API. The problem is caused by the script https://cdn.jsdelivr.net/npm/tsparticles-confetti@2.9.3/tsparticles.confetti.bundle.min.js. Using Chrome devtools to block this script when the page loads prevents the problem from occurring. The issue also occurs on the home page of the tsParticles library - https://particles.js.org.

robertknight commented 4 months ago

I filed an upstream issue to see if the tsParticles library can avoid overwriting the DOM Range object. In the meantime we might need to use some technique other than new Range to construct ranges to prevent this. Enforcing this would require a lint check. We have a similar existing issue with sites that have broken URL polyfills on them.

robertknight commented 4 months ago

The issue in tsParticles was fixed upstream in the v3.2.2 release, so this means we just need to deal with sites that still reference older versions. https://community.canvaslms.com for example is loading https://cdn.jsdelivr.net/npm/tsparticles-confetti@2.9.3/tsparticles.confetti.bundle.min.js at the time of writing.