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 Text Fragments in AMP #32139

Closed
sebsg opened this issue Jan 22, 2021 · 4 comments
Closed

Add support for Text Fragments in AMP #32139

sebsg opened this issue Jan 22, 2021 · 4 comments

Comments

@sebsg
Copy link

sebsg commented Jan 22, 2021

Describe the new feature or change to an existing feature you'd like to see

Chrome has implemented this new W3C draft spec about Text Fragments that allows linking to specific parts of a web page. Upon opening the link the browser will scroll-to and highlight the specified section.

While this works on most sites, one big issue with the feature currently is that it doesn't work on AMP pages. For example, the text fragment anchor part of the URL seems stripped from most AMP pages when loaded. From my understanding of AMP, there might be other issues even if the fragment was not stripped.

Some examples:

There seems to be a way to make this work since some pages loaded from a search results page work (e.g. search for "when is ios 14.3 coming out")

Would it be possible to add support for scroll-to text fragments?

@bokand
Copy link

bokand commented Jan 27, 2021

Since the fragment directive (everything including and after :~:) is hidden from the page, it isn't the AMP page somehow interfering with it. A page writing to the location.hash will cause it to clear the text fragment from the omnibox but that's a small UI glitch, it shouldn't affect behavior.

I believe the AMP viewer displays the content in an iframe? If so, that's the reason we don't get text highlighting, to enforce origin isolation, text fragments only work in the main frame.

I think the most promising solution would be to expose information about the text fragment to the page (see WICG/scroll-to-text-fragment#128) and have the root AMP page pass through the data to the iframe'd content.

IIRC, AMP actually had an implementation of scroll-to prior to text-fragment support in the browser, that could be reused (though the matching algorithm may need to be updated to support the text-fragment semantics). Alternatively, there is an open source implementation of the text-fragment spec (see WICG/scroll-to-text-fragment#135) that we could probably pull in.

Could someone on the AMP side comment on the feasibility of this approach (+confirm my assumptions above)?

@dmanek
Copy link
Contributor

dmanek commented Jan 27, 2021

@bokand I haven't had a chance to look into this in depth. Plan to start looking next week and will comment when I have something.

@eligrey
Copy link

eligrey commented May 3, 2021

@bokand fragment directives are still accessible, albeit in a slightly-convoluted manner. See WICG/scroll-to-text-fragment#128 (comment) for some utils that can help web devs interoperate with these directives.

@dmanek
Copy link
Contributor

dmanek commented Aug 25, 2021

Closing this issue as it is now verified using Chrome >= 93.

@dmanek dmanek closed this as completed Aug 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants