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

Add support for updating the document hash, off by default, when the browser history is updated (issue 5753) #10423

Merged
merged 2 commits into from
Jan 6, 2019

Conversation

Snuffleupagus
Copy link
Collaborator

This is really the best that we can do here, since other proposed solutions would interfere with (and break) the painstakingly implemented browsing history that's present in the default viewer.

I'm still not convinced that this is a good idea in general, but this patch implements it in a way where it is possible to toggle[1] for users that wish to have this feature. In particular, there's a couple of reasons why I'm not finding this feature necessary/great:

  • It's already possible to easily obtain the current hash, by simply clicking on the viewBookmark button at any time.
  • Hash changes requires a bit of special handling[2], i.e. extra code, to prevent issues when the browser history is traversed (see PDFHistory._popState). Currently this is only necessary when the user has manually changed the hash, with this patch it will always be the case (assuming the feature is active).
  • It's not always possible to change the URL when updating the browser history. For example: In the Firefox built-in viewer, the URL cannot be modified for local files (i.e. those using the file:// protocol).
    This leads to inconsistent behaviour, and may in some cases even result in errors being thrown and the history thus not updating, if the browser prevents changes to the URL during pushState/replaceState calls.

[1] Using the historyUpdateUrl viewer preference.

[2] This depends, to a great extent, on browsers always firing popstate events before hashchange events, which may or may not actually be guaranteed.

@timvandermeij
Copy link
Contributor

/botio-linux preview

@pdfjsbot
Copy link

pdfjsbot commented Jan 6, 2019

From: Bot.io (Linux m4)


Received

Command cmd_preview from @timvandermeij received. Current queue size: 0

Live output at: http://54.67.70.0:8877/4fa1744e7fb619d/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Jan 6, 2019

From: Bot.io (Linux m4)


Success

Full output at http://54.67.70.0:8877/4fa1744e7fb619d/output.txt

Total script time: 1.66 mins

Published

web/pdf_history.js Outdated Show resolved Hide resolved
src/shared/compatibility.js Outdated Show resolved Hide resolved
…browser history is updated (issue 5753)

This is *really* the best that we can do here, since other proposed solutions would interfere with (and break) the painstakingly implemented browsing history that's present in the default viewer.

I'm still not convinced that this is a good idea in general, but this patch implements it in a way where it is possible to toggle[1] for users that wish to have this feature. In particular, there's a couple of reasons why I'm not finding this feature necessary/great:
 - It's already possible to easily obtain the current hash, by simply clicking on the `viewBookmark` button at any time.
 - Hash changes requires a bit of special handling[2], i.e. extra code, to prevent issues when the browser history is traversed (see `PDFHistory._popState`). Currently this is only necessary when the user has manually changed the hash, with this patch it will always be the case (assuming the feature is active).
 - It's not always possible to change the URL when updating the browser history. For example: In the Firefox built-in viewer, the URL cannot be modified for local files (i.e. those using the `file://` protocol).
This leads to inconsistent behaviour, and may in some cases even result in errors being thrown and the history thus not updating, if the browser prevents changes to the URL during `pushState`/`replaceState` calls.

---
[1] Using the `historyUpdateUrl` viewer preference.

[2] This depends, to a great extent, on browsers always firing `popstate` events *before* `hashchange` events, which may or may not actually be guaranteed.
@timvandermeij
Copy link
Contributor

/botio-linux preview

@pdfjsbot
Copy link

pdfjsbot commented Jan 6, 2019

From: Bot.io (Linux m4)


Received

Command cmd_preview from @timvandermeij received. Current queue size: 0

Live output at: http://54.67.70.0:8877/85175e4d3c56967/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Jan 6, 2019

From: Bot.io (Linux m4)


Success

Full output at http://54.67.70.0:8877/85175e4d3c56967/output.txt

Total script time: 1.64 mins

Published

@timvandermeij timvandermeij merged commit e4d2a16 into mozilla:master Jan 6, 2019
@timvandermeij
Copy link
Contributor

I'm fine with this since it's off by default. Thank you!

@KiaraGrouwstra
Copy link

That looks great, thank you @Snuffleupagus! 🎉

@Rob--W
Copy link
Member

Rob--W commented May 30, 2019

This feature has no "title" key in preferences_schema.json. This prevents the option from being rendered in the settings page of the Chrome extension.

Preferences should only be hidden if they are internal, non-user facing or instable work-in-progress features. It seems that this feature does not match that description.

@Snuffleupagus If this feature is ready for use by users, could you open a PR and add a meaningful title to the preferences_schema.json, to expose the pref to users?

@Snuffleupagus
Copy link
Collaborator Author

Snuffleupagus commented May 30, 2019

This feature has no "title" key in preferences_schema.json. This prevents the option from being rendered in the settings page of the Chrome extension.

That was completely intentional on my part. (It should still be possible to set the preference manually from the console, as far as I can tell.)

Preferences should only be hidden if they are internal, non-user facing or instable work-in-progress features. It seems that this feature does not match that description.

#10423 (comment) outlines some of the reasons why enabling this feature is a bad idea in my opinion, and thus I really don't think it's a good idea to give it a prominent position in any options UI.

If this feature is ready for use by users, could you open a PR and add a meaningful title to the preferences_schema.json, to expose the pref to users?

Honestly, I'd classify this as only "sort of" supported and thus use only at you're own risk.
Given everything said above, personally I have no intention to put additional work into this feature (and I only submitted this patch to prevent a solution causing outright breakage from landing).

@Rob--W
Copy link
Member

Rob--W commented May 30, 2019

Thanks for the quick reply. The reasoning sounds good to me.

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

Successfully merging this pull request may close these issues.

5 participants