404 error on browser back button
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.

How do we reproduce the issue?
- Open the AMP page
- Press the link in the AMP page
- 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/

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
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,
- 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_js_v=0.1#origin=https://www.google.com&cid=1&prerenderSize=1&visibilityState=visible&paddingTop=32&history=1&p2r=0&horizontalScrolling=0&csi=1&storage=1&viewerUrl=https://www.google.com/amp/s/restaurant.ikyu.com/sd/101876/amp/&cap=iframeScroll,navigateTo,fragment,handshakepoll,cid,replaceUrl,fullReplaceHistory"></iframe>

-
But some how the HTTP request is sent w/o any parameters e.g.
usqpandamp_jswhich would result in 404
-
I'm not sure why this request is sent with
sec-fetch-site: same-originwhile it should becross-sitesince it's an cross origin request i.e. www.google.com vs *.ampproject.org
@morsssss
Here are the steps I am seeing that is repeating the issue:
Steps to reproduce.
- Open Google (in ios safari)
- Type "Niel Patel AMP"
- Click on "Why AMP & Facebook Instant Can Be Bad for ... - Neil Patel" result.
- Click on "neilpatel logo" in the orange bar
- Click back
- 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
@mauricengo-revolve
@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
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.
Thanks everyone! I'm pinging some people over here...
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.

/cc @flaviori - have you seen this behavior?
@morsssss Thanks for looking into this. Is there any update on these issues?
Thanks for the ping. Let me check...
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&_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 ?&_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/?&_js_v=0.1
This seems like an old issue however, has anything changed since then? https://github.com/ampproject/amphtml/issues/25179
@choumx @ericfs
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.
Thanks @flaviori for looking into this. This thread is talking about two different issues as far as I can tell.
- The original issue this thread points out. Viewer results in 404 b/c of missing query parameters.
- 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.
I'm having trouble reproducing the 404. @choumx, Are the query and fragment only stripped in certain cases?
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. &_js_v=0.1) cause a 404.
Simplest fix would be to turn off this feature.
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/
@choumx Can you elaborate a little more on what the fallback should do here? I'm not sure I follow the whole issue well.
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.
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.