Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
StructSeeker opened this issue Jan 10, 2025 · 2 comments
Open

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

StructSeeker opened this issue Jan 10, 2025 · 2 comments

Comments

@StructSeeker
Copy link

StructSeeker commented Jan 10, 2025

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 StructSeeker changed the title [Bug] Hypothes.is not updated after uploading new file. [Bug] Hypothes.is not updated after opening new file. Jan 10, 2025
@robertknight
Copy link
Member

robertknight commented Jan 10, 2025

That code should work, although this could be handled in a more efficient way if the Hypothesis client monitored for changes in the current file rather than requiring the whole client to be reloaded. We already support this for web pages, but not PDFs.

We are currently having some internal discussions about packaging PDF.js + Hypothesis in a way that is easier for us to share across projects. In that context we'll need to avoid hard-coding the client URL as it varies depending on context.

My suggestions for the moment are:

  • Go and and use the code snippet you posted in your own project
  • Leave this issue open to track the problem

@StructSeeker
Copy link
Author

@robertknight Thank you for! Please Consider publish the supposed hypothes.is+pdf.js package on npm once your change is done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants