question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Viewer history enable/disable control is broken

See original GitHub issue

Supposedly it is possible to disable pdfjs viewer restoring viewer state by setting disableHistory to false (is this key even documented anywhere?), but it’s not working at all.

Adding #disableHistory to URL in the viewer does disable the history, but that’s caused by a bugged handling: adding any non-empty hash to the URL will cause history to be disabled.

Meanwhile, trying to set disableHistory through defaultOptions or AppOptions does nothing. The only place where it’s used is inside _initializePdfHistory, but it isn’t doing anything there either since pdf.history will be created regardless.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
Snuffleupaguscommented, Aug 23, 2021

Supposedly it is possible to disable pdfjs viewer restoring viewer state by setting disableHistory to false

That option only controls the browsing history implementation, i.e. https://github.com/mozilla/pdf.js/blob/master/web/pdf_history.js, which allows you to use the back button in the browser to navigate to a previous position after e.g. clicking on a LinkAnnotation within a PDF document.

[…] but it’s not working at all.

Yes, it most certainly does exactly what it’s supposed to!

https://github.com/mozilla/pdf.js/blob/d02233361872d3758eb23ed394c939c4f510e2cb/web/app.js#L1226-L1242

Based on the quoted code your question isn’t actually about PDFHistory but rather about ViewHistory (which is a separate thing, that only stores the last position in localStorage and nothing else). That implementation is controlled by the viewOnLoad option/preference, with the following currently supported values: https://github.com/mozilla/pdf.js/blob/d02233361872d3758eb23ed394c939c4f510e2cb/web/app.js#L89-L93

Hence setting viewOnLoad = 1 is sufficient to discard any view and/or browser history entries and always load all documents at the first page (and with default zoom values).


For future reference: When opening an issue, please remember to provide all of the information requested in https://github.com/mozilla/pdf.js/blob/master/.github/ISSUE_TEMPLATE.md

Furthermore, this issue required some amount of “reading between the lines” to figure out what you really were asking about; hence please see https://github.com/mozilla/pdf.js/blob/master/.github/CONTRIBUTING.md (emphasis mine):

If you are developing a custom solution, first check the examples at https://github.com/mozilla/pdf.js#learning and search existing issues. If this does not help, please prepare a short well-documented example that demonstrates the problem and make it accessible online on your website, JS Bin, GitHub, etc. before opening a new issue or contacting us in the Matrix room – keep in mind that just code snippets won’t help us troubleshoot the problem.

0reactions
Voileexperimentscommented, Aug 23, 2021

I downvoted because while it answers the question, it also dodges the underlying issue of the lack of documentation about viewer configs (what config should I change to achieve anything different from default behaviour?). I am customizing the existing viewer and I find myself often needed to dive into the initialization logic itself just to understand where should I change the code (and then guess wrong, just as this issue has proven). I don’t think this is encouraging to customizing the default viewer.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to enable/disable the Session Inactivity Timeout
In the Session timeout section of the window, click Disconnect sessions if idle: and specify a time from the list. Click Save to...
Read more >
Media Request Overview and Guide | StreamElements
You can add your own media via the 'Add media' button, review past requests by pressing 'History' or remove everything via the remove...
Read more >
Fix site display issues with Compatibility View in Internet ...
To clear the list of Compatibility View sites. Open Internet Explorer, select the Tools button , and then select Internet options. Under Browsing...
Read more >
Find & control your Web & App Activity - Android
Learn how to manage and delete on-device Search history. What's saved as Web & App Activity. Info about your searches and other activity...
Read more >
Disabled UIButton not faded or grey - Stack Overflow
This is not working for view's background color. In my project I combined previous answer and this. – Anton. Mar 20, 2017 at...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found