pdf.js-hypothes.is icon indicating copy to clipboard operation
pdf.js-hypothes.is copied to clipboard

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

Open StructSeeker opened this issue 9 months ago • 2 comments

There is an upload button for hypothesis's pdf.js view: Image 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 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

    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!

StructSeeker avatar Jan 10 '25 08:01 StructSeeker