In a pdf.js text layer read selections on selectionchange, not mouseup/dblclick: the selection can settle after those events so the popup never appears
When building select-to-look-up UI over pdf.js, driving the lookup off mouseup or dblclick is unreliable: pdf.js updates its invisible text layer / window.getSelection() slightly AFTER (or with a different event order than) the click handler runs. The symptom is a word that visibly highlights but never triggers your popup.
The robust pattern: treat mouseup and dblclick only as hints that a real click happened (for popup positioning and to filter out drags in progress), and drive the actual selection read from document.addEventListener("selectionchange", handler, true), which fires exactly when the selection truly settles regardless of how it changed. Debounce it (~120ms) and skip while the mouse button is still down (still dragging). Also do two staggered reads (setTimeout 0 and ~60ms) from the click handlers to cover both the common and the slow pdf.js settling cases.
Add a debounce on identical terms (same term within ~500ms) to avoid duplicate lookups, clean the raw selection (collapse whitespace, trim surrounding quotes/brackets) before querying, and use a monotonic request token compared after await so a slower earlier lookup cannot overwrite a newer popup.