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

[Proposal] Fragment-directives meant for "UA instructions" #4868

Closed
bokand opened this issue Aug 28, 2019 · 2 comments
Closed

[Proposal] Fragment-directives meant for "UA instructions" #4868

bokand opened this issue Aug 28, 2019 · 2 comments
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest topic: navigation

Comments

@bokand
Copy link
Contributor

bokand commented Aug 28, 2019

This is a corresponding issue to whatwg/url#445

Proposal (Summarized from above issue)

We propose amending the URL specification to allow a ## to indicate a fragment directive. A fragment directive would be a part of the URL reserved for UA instructions that's stripped off during loading before being set on the document. Taking an example

https://example.org#fragment##foo=bar

In this case, the UA processes the foo=bar directive (and uses it to perform some action, e.g. ScrollToText) and strips it from the URL as seen by the page. From the page's point of view:

window.location.href === 'https://example.org#fragment'
window.location.hash === ''
document.URL === 'https://example.org#fragment'

It also has the benefit of likely being parsed as part of the fragment in URL parsers and won't affect the server request so it should be mostly backwards compatible. (Though this URL would fail a strict validation as it's an invalid fragment today)

More details and motivation are in whatwg/url#445

Changes in HTML

There's a number of questions to answer here:

  • Should this affect just HTML or other MIME types?
  • At what point in the loading algorithm is the fragment directive removed?
  • At what point is the fragment directive processed
  • Should the fragment directive be processed on history navigation? Reload?

I've got some thoughts on these questions none of which are strongly held.

  • HTML or other MIME types?
    UA directives could be useful across different types. e.g. targetText could be used in text documents just as well as HTML. Other potential uses might be translation, zoom, accessibility features, etc. These all seem to apply to more than just HTML.

  • When is the fragment directive removed?
    In steps 7 and 8 of create and initialize a Document object we set the Document's URL from the request or response URL. Replace these with:

  1. Let url be null
  2. If request is non-null, then set url to request's current URL.
  3. Otherwise, set url to response's URL.
  4. Set the document's fragment-directive be url's fragment directive. (Note: this is stored on the document but not web-exposed)
  5. Remove all characters in the url following and including the fragment directive delimiter (##)
  6. Set the document's url to be url.
  • Where do we process the fragment directive?
    We can process as part of the try to scroll to the fragment instructions. That is, this would become try to activate the fragment which might perform one or more UA actions and then may or may not attempt to scroll any specified fragment into view.

  • History? Reload?
    As a starting point, I think it makes sense to use the same behavior as fragments.

@nickburris
Copy link

Note that we've updated our proposal to use a fragment directive delimiter that uses valid URL fragment code points, :~:. This means that we won't need to amend URL spec, just HTML spec to allow :~: to indicate a fragment directive as David describes above.

@zcorpan
Copy link
Member

zcorpan commented Apr 23, 2024

Closing in favor of #8282

@zcorpan zcorpan closed this as not planned Won't fix, can't repro, duplicate, stale Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest topic: navigation
Development

No branches or pull requests

4 participants