WICG / scroll-to-text-fragment

Proposal to allow specifying a text snippet in a URL fragment
Other
586 stars 43 forks source link

document.fragmentDirective doesn't work for feature detection #257

Open foolip opened 4 months ago

foolip commented 4 months ago

Due to https://webkit.org/b/273466, web developers will not be able to rely on document.fragmentDirective to detect support for text fragments.

The possible paths to interop are WebKit adding document.fragmentDirective or Chromium removing it. Either way makes it impossible to use document.fragmentDirective for feature detection. I don't have an opinion on which way to go.

tomayac commented 4 months ago

It makes a lot of sense to make the feature detectable. Else, polyfills that emulate the native highlighting, for example, by injecting <mark> tags, might possibly break the page. See https://github.com/GoogleChromeLabs/link-to-text-fragment/issues/102 for a real-world example.

foolip commented 4 months ago

Can the situation be salvaged though? Is it a problem if the feature appears unsupported even though it's supported?

tomayac commented 4 months ago

In the worst case someone would then inject/load a polyfill despite native support.

foolip commented 4 months ago

I've filed https://github.com/GoogleChromeLabs/text-fragments-polyfill/issues/157 to probe about what will happen with that polyfill.

bokand commented 4 months ago

Hmm, would the polyfill be an issue if a browser has support but claims not to? In that case it'd strip the :~: part of the fragment off so the polyfill wouldn't see it, I think?

The bigger issue is we added it so that sites could selectively add a text directive to an anchor only for agents that it knows will strip it off, given that there were cases where adding it could break a site when followed - though this is fairly rare and I'm not sure if anyone uses it for that.

I'm curious to hear WebKit's take on https://webkit.org/b/273466 - if they did this intentionally and don't see any issues I suppose it might be a signal we could try unshipping it...

tomayac commented 4 months ago

Hmm, would the polyfill be an issue if a browser has support but claims not to? In that case it'd strip the :~: part of the fragment off so the polyfill wouldn't see it, I think?

Correct, this is what I found out and documented in https://github.com/GoogleChromeLabs/text-fragments-polyfill/issues/157#issuecomment-2086029590.