GoogleChromeLabs / text-fragments-polyfill

Apache License 2.0
116 stars 27 forks source link

Track `hashchange` event #136

Closed moetelo closed 1 year ago

moetelo commented 2 years ago

In Chrome, if you set a new text fragment hash programmatically, like https://github.com/GoogleChromeLabs/text-fragments-polyfill location.hash = '#:~:text=module%20of%20util-,functions,-for%20generating%20URLs'; , the page will be scrolled to the text.

The behavior does not provide such functionality.

moetelo commented 2 years ago

My guess is that the polyfill should match Chrome's behavior, so the PR is here: https://github.com/GoogleChromeLabs/text-fragments-polyfill/pull/137.

ivan commented 2 years ago

I noticed this as well in Firefox by just changing the #:~:text= in the URL bar and pressing Enter. Chrome (tested 108) highlights and scrolls to the new text, while the polyfill does not.

tomayac commented 2 years ago

@bokand, what do you think is the right behavior here?

bokand commented 2 years ago

There's some context in https://github.com/WICG/scroll-to-text-fragment/issues/74

Given the way STTF is spec'd and implemented, a hash change should cause a scroll-to-text since it invokes the "scroll to the fragment" algorithm which is where STTF is invoked.

tomayac commented 2 years ago

Thanks, @bokand! So @tfmar, are you happy to merge #137?

ZiadJ commented 1 year ago

Any reason why this is not merged yet?

tomayac commented 1 year ago

@bokand @tfmar is anyone from the team owning this?

bokand commented 1 year ago

Apologies for the delay - looks good with a comment I left on the review.

moetelo commented 1 year ago

@bokand Can't find your comment. Could you request changes directly on the PR, if there are any issues?

bokand commented 1 year ago

Sorry - I forgot to hit "submit". You should see it now