WICG / scroll-to-text-fragment

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

In mobile chrome copy link is not working with pagination (skips slug "/page/%#%") #215

Closed Jonnas123 closed 1 year ago

Jonnas123 commented 1 year ago

Hi, I have posts split by pagination in a page. If I am at page 2, for example, https://mysite/book/page/2. I highlight text , copy the fragment link and paste in address bar, but it shows like this https://mysite/book/#:~:text={text} but it should be https://mysite/book/page/2/#:~:text={text}. As you can see, it skips slug "page/2"

To reproduce the issue, please install WordPress, create 10 posts, and then add this code https://gist.github.com/mihdan/b4a218961bc609b0246ad2aa9ba0c232 to a custom template to display posts with pagination. Then try with your mobile chrome.

Please note this happens only with mobile , in desktop it works fine.

bokand commented 1 year ago

Any chance you have a repro available at a URL I could try this on?

Jonnas123 commented 1 year ago

The site is under construction. But if you don't mind, give me your email address. I can send you a credential to login.

bokand commented 1 year ago

Please send to bokan@chromium.org, thanks

Jonnas123 commented 1 year ago

Sent, please check. Thank you.

bokand commented 1 year ago

Thanks - I see the issue now.

What's happening is that your page has <link rel="canonical" href="https://etripitaka91.com/tripitaka/"> which makes this the share URL. Chrome's implementation of "Copy Link-to-Highlight" will use this URL instead of the current one so that's what you're seeing.

Curiously <link rel="canonical"> is ignored in this case in the desktop implementation; that's a bit odd to me but I suspect this was added to fix some specific mobile failure case.

In any case - this isn't a bug with the scroll-to-text-fragment spec so I'm going to close this issue - if any thing this would be an issue in Chrome (https://crbug.com/) but even so I believe this is technically working as intended. If you're able to, removing this <link> tag would fix your issue.

Jonnas123 commented 1 year ago

That's automatically added by this plugin Yoast. But actually the problem exists before this tag is added. And I've deactivated the plugin, the tag is removed, but nothing changes.

bokand commented 1 year ago

Hmm, are you sure you're not hitting a cached version of the page? If you can you update the URL you gave me I can take another look but it was quite clearly hitting the <link> case before.

Jonnas123 commented 1 year ago

I purge cache in the servers and clear cache in mobile chrome, remove tab, logout and login again. Still, I cann't copy the slug page/2/ like in the desktop. And I view the page source, the tag is already gone now. You can login to check with the same credential.

As I said, I notice this issue exists many months before this tag is added by this plugin. I just installed this plugin a few days ago. If it's related to this tag, then this issue wouldn't exist because I didn't manually add the tag before.

Jonnas123 commented 1 year ago

Sorry, I double check again, the tag still exists in the header. Now I use this code remove_action('wp_head', 'rel_canonical'); add_filter( 'wpseo_canonical', '__return_false' ); to remove it from WordPress. And it works! Thanks.