hypothesis / hypothesis/pdf.js-hypothes.is

[Bug] Hypothes.is not updated after opening new file.

Open
#28 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
408
Forks
84
PR merge metrics
No merged PRs in 30d

Description

There is an upload button for hypothesis's pdf.js view:
![Image](https://github.com/user-attachments/assets/a36eb05f-fb13-4db5-b888-0711163558b9)
However, when i upload a local file via this button, the hypothes.is sidebar remain the content for original file.

I suppose with this bug fixed, it's possible to use hypothes.is on android device without hosting file on server, as i can use a [dummy page](https://via.hypothes.is/https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf) and upload the file, i am actually considering developing a PWA out of it, making the mobile use of hypothes.is easier.

Now, after playing around with the code, it seems the problem can be fixed by modifying `webViewerFileInputChange` in `web/viewer.js` by adding the following at the end of the function

```javascript
function loadHypothesis() {
PDFViewerApplication.initializedPromise.then(() => {
const embedScript = document.createElement('script');
embedScript.src = 'https://hypothes.is/embed.js';
document.body.appendChild(embedScript);
});
}

function unloadHypothesis() {
var appLinkEl =
document.querySelector('link[type="application/annotator+html"]');
appLinkEl.dispatchEvent(new Event('destroy'));
};

function reloadHypothesis(){
unloadHypothesis(); loadHypothesis();
}

reloadHypothesis()
```

I don't know it's the correct way, but Do please consider fix this bug!

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.