amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

404 error on browser back button

Open abeak opened this issue 6 years ago • 30 comments

What's the issue?

When I go back to the AMP page by pressing the back button on the browser, the 404 error page sometimes comes up.

Image from iOS (1)

How do we reproduce the issue?

  1. Open the AMP page
  2. Press the link in the AMP page
  3. Press the browser's back button

The issue occurs when I repeat steps 2 and 3.

It has been confirmed that it occurs on multiple sites. One of the pages in which the issue occurs is as follows.

https://www.google.co.jp/amp/s/restaurant.ikyu.com/sd/101876/amp/

新しいタブ-Google-Chrome-2020-04-15-10-57-56

What browsers are affected?

It did not occur in iPhone Chrome, but it occured in browsers such as Safari.

Which AMP version is affected?

Version 2004030010070

abeak avatar Apr 10 '20 05:04 abeak

Very interesting case. These are the additional debug materials I received in another thread:

  • Additional resources: HAR file
  • Additional information: the repro GIF above is using Chrome 81.0.4044.92(Official Build) (64-bit)

Unfortunately, I was not able to reproduce the issue but by looking at the HAR file,

  1. The viewer, www.google.com, is loading the <iframe> below to load AMP from cache
<iframe class="u2quVpIWVr0__amp-doc v2FKFf" allow="autoplay" allowfullscreen="true" allowpaymentrequest="true" loading="eager" name="https://restaurant.ikyu.com/sd/101876/amp/" src="https://restaurant-ikyu-com.cdn.ampproject.org/v/s/restaurant.ikyu.com/sd/101876/amp/?usqp=mq331AQFKAGwASA%3D&amp;amp_js_v=0.1#origin=https://www.google.com&amp;cid=1&amp;prerenderSize=1&amp;visibilityState=visible&amp;paddingTop=32&amp;history=1&amp;p2r=0&amp;horizontalScrolling=0&amp;csi=1&amp;storage=1&amp;viewerUrl=https://www.google.com/amp/s/restaurant.ikyu.com/sd/101876/amp/&amp;cap=iframeScroll,navigateTo,fragment,handshakepoll,cid,replaceUrl,fullReplaceHistory"></iframe>

iframe

  1. But some how the HTTP request is sent w/o any parameters e.g. usqp and amp_js which would result in 404 request

  2. I'm not sure why this request is sent with sec-fetch-site: same-origin while it should be cross-site since it's an cross origin request i.e. www.google.com vs *.ampproject.org

uskay avatar Apr 15 '20 08:04 uskay

@morsssss

Here are the steps I am seeing that is repeating the issue:

Steps to reproduce.

  1. Open Google (in ios safari)
  2. Type "Niel Patel AMP"
  3. Click on "Why AMP & Facebook Instant Can Be Bad for ... - Neil Patel" result.
  4. Click on "neilpatel logo" in the orange bar
  5. Click back
  6. Links no longer work.

Similar complaints on the web:

https://support.google.com/webmasters/thread/16526831?hl=en&dark=0 https://stackoverflow.com/questions/60809468/amp-page-if-you-use-a-browser-back-you-cant-click-any-other-links https://wordpress.org/support/topic/amp-is-freezing-it-is-not-possible-to-click-on-links/ https://www.drupal.org/project/amp/issues/3105858

coreyching avatar Oct 26 '20 22:10 coreyching

@mauricengo-revolve

coreyching avatar Oct 26 '20 23:10 coreyching

@coreyching , While both are related to browser back, I feel the issue you are mentioning here is more related to #30838 . I'll add a link to your comment there as well.

cc/ @nainar

uskay avatar Oct 27 '20 01:10 uskay

Hi @uskay and @morsssss, we are occasionally seeing both issues occurring with the back button use case — the 404 and the not clickable links. We're waiting on both issues to be addressed before launching our AMP site. @coreyching has been assisting us. Thank you for looking into this.

mauricengo-revolve avatar Oct 27 '20 02:10 mauricengo-revolve

Thanks everyone! I'm pinging some people over here...

morsssss avatar Oct 29 '20 21:10 morsssss

Trying this with https://www.google.co.jp/amp/s/restaurant.ikyu.com/sd/101876/amp/ as described by @abeak above, in Chrome DevTools emulating an iPhone, I get this 404 as well. I don't get it in DevTools emulating an Android device.

Screen Shot 2020-10-29 at 5 44 38 PM

morsssss avatar Oct 29 '20 21:10 morsssss

/cc @flaviori - have you seen this behavior?

morsssss avatar Oct 29 '20 21:10 morsssss

@morsssss Thanks for looking into this. Is there any update on these issues?

mauricengo-revolve avatar Nov 03 '20 18:11 mauricengo-revolve

Thanks for the ping. Let me check...

morsssss avatar Nov 05 '20 23:11 morsssss

This seems to be related to https://github.com/ampproject/amphtml/issues/25179 where the query and fragment parameters are stripped out from the iframe on back on Safari.

In particular, on back the iframe tries to load the following which is a 404 https://restaurant-ikyu-com.cdn.ampproject.org/v/s/restaurant.ikyu.com/sd/101876/amp/

Whereas the URL actually available on the AMP Cache is: https://restaurant-ikyu-com.cdn.ampproject.org/v/s/restaurant.ikyu.com/sd/101876/amp/?usqp=mq331AQFKAGwASA%3D&amp_js_v=0.1#aoh=16046200428269&origin=https://www.google.co.jp&cid=1&prerenderSize=1&visibilityState=visible&paddingTop=32&history=1&p2r=0&csi=1&storage=1&viewerUrl=https://www.google.co.jp/amp/s/restaurant.ikyu.com/sd/101876/amp/&cap=iframeScroll,navigateTo,fragment,handshakepoll,cid,replaceUrl,fullReplaceHistory

Just adding the ?&amp_js_v=0.1 is enough for the page to load. https://restaurant-ikyu-com.cdn.ampproject.org/v/s/restaurant.ikyu.com/sd/101876/amp/?&amp_js_v=0.1

This seems like an old issue however, has anything changed since then? https://github.com/ampproject/amphtml/issues/25179

flaviori avatar Nov 06 '20 00:11 flaviori

@choumx @ericfs

flaviori avatar Nov 06 '20 00:11 flaviori

Worth noting that this only reproducible in the standalone viewer as far as I can see. Whereas if you get to the same page from the viewer in Google Search, the bug won't occur.

flaviori avatar Nov 06 '20 01:11 flaviori

Thanks @flaviori for looking into this. This thread is talking about two different issues as far as I can tell.

  1. The original issue this thread points out. Viewer results in 404 b/c of missing query parameters.
  2. The issue @coreyching points out relates to #30838 where it does show the page on Safari browser back but disables all the links on the page.

I'll loop @flaviori , @choumx and @ericfs into #30838 just in case.

uskay avatar Nov 06 '20 01:11 uskay

I'm having trouble reproducing the 404. @choumx, Are the query and fragment only stripped in certain cases?

ericfs avatar Nov 06 '20 21:11 ericfs

I can repro this too. Flavio is right that this is caused by #25179.

Query params are stripped before navigation (on Safari 13+, in viewer) and restored either immediately (target=_blank) or when restoring page from back/forward cache (target=_top).

Looks like the issue is the case where the page is stored in bfcache but needs to do a partial cold load (the AMP iframe's CDN URL is preserved, but its content is reloaded). In this case, the missing viewer query params (e.g. &amp_js_v=0.1) cause a 404.

Simplest fix would be to turn off this feature.

dreamofabear avatar Nov 09 '20 16:11 dreamofabear

Poked around a little more.

  • It appears the feature is still useful in Safari 14 for preserving document referrer
  • I can only repro inconsistently on my MBP and iPhone

@abeak @uskay Do we have a sense of how many users are impacted by this?

@ampproject/wg-caching Is it possible to add a fallback for missing required query params for cache URLs? E.g. missing amp_js_v=0.1 causes 404: https://restaurant-ikyu-com.cdn.ampproject.org/v/s/restaurant.ikyu.com/sd/101876/amp/

dreamofabear avatar Nov 09 '20 17:11 dreamofabear

@choumx Can you elaborate a little more on what the fallback should do here? I'm not sure I follow the whole issue well.

Gregable avatar Nov 09 '20 18:11 Gregable

I think @seanjallen may have had a proposal about how to simplify amp_js_v usage, which could help here. I'll need to dig to find the proposal.

ericfs avatar Nov 09 '20 18:11 ericfs

Can you elaborate a little more on what the fallback should do here?

I believe the ?amp_js_v param controls the version of amp-viewer-integration-X.Y.js script that's injected into the page. If it's missing, we could fallback to a default version (currently 0.1) instead of 404'ing.

However, this is not a complete recovery since the iframe fragment would still be missing. This means paddingTop is not set (viewer header occlusion) and no viewer capabilities (swiping between articles). So maybe this isn't the best idea.

OTOH, manually refreshing the page containing the 404'ed iframe is a workaround with a complete recovery.

dreamofabear avatar Nov 09 '20 19:11 dreamofabear