WICG / scroll-to-text-fragment

Proposal to allow specifying a text snippet in a URL fragment
Other
589 stars 42 forks source link

There is no way to get the URL when protocol is `file://` #196

Closed zamicol closed 2 years ago

zamicol commented 2 years ago

There is no way to get the URL if the protocol is file://

performance.getEntriesByType("navigation")[0].name does not work when the protocol is file://. performance is the suggested workaround for document.url and others, but this isn't tenable either. I'm not sure why performance doesn't work here, I'd love to know the reason.

As far as the TextFragmentAPI is concerned, I'm on Chrome version 104.0.5112.79 and the TextFragmentAPI doesn't seem to have anything usable here as implemented. The API doc has some useful interfaces, but they don't exist in the object.

Using this URL: https://en.wikipedia.org/wiki/Question#:~:text=linguistically%2C%20a%20question%20may%20be%20defined%20on%20three%20levels.

I get a fragmentDirective that's missing anything useful, such as items: image

bokand commented 2 years ago

The API is something I've been thinking about but haven't gotten past the idea stage - it's implemented in Chrome but behind a flag so it isn't shipped by default. You can try it out by starting chrome with the --enable-blink-features=TextFragmentAPI flag. (alternatively, I believe enabling chrome://flags/#enable-experimental-web-platform-features should also do the trick)

performance is the suggested workaround for document.url and others

I wouldn't say it's suggested - it works today (where the performance API does) but I think it's a bit of a hack that we'd like to eventually remove. See https://crbug.com/1096983

zamicol commented 2 years ago

Thank you @bokand. 👍

Currently, text fragment will only appear in fragment directive when chrome://flags/#enable-experimental-web-platform-features is enabled. I mistakenly thought FragmentDirective's existence guaranteed the needed flags were already enabled.

Also for future readers: I don't know why performance does not contain url /name when the protocol is file:// and I can't find anything googling. If someone knows why, send me a message and I'll update this comment. For now, I'll assume it has something to do with security restrictions on file://.