Bug 231563 - iOS 15: History back sometimes scrolls to top of the page
Summary: iOS 15: History back sometimes scrolls to top of the page
Alias: None
Product: WebKit
Classification: Unclassified
Component: Scrolling (show other bugs)
Version: Safari 15
Hardware: iPhone / iPad Unspecified
: P2 Major
Assignee: Simon Fraser (smfr)
Keywords: InRadar
Depends on:
Reported: 2021-10-12 01:08 PDT by Mads Erik Forberg
Modified: 2022-05-12 02:05 PDT (History)
7 users (show)

See Also:

iOS15.4 buggy (7.42 MB, video/quicktime)
2022-03-25 04:38 PDT, olekenneth
no flags Details
Scroll bug on DT.no (4.17 MB, video/mp4)
2022-04-19 02:57 PDT, Mads Erik Forberg
no flags Details
iPadOS showing issue (9.31 MB, video/quicktime)
2022-04-27 06:36 PDT, Johannes Andersen
no flags Details
iOS 15.4.1 NYT scroll bug when app banner is visiblle (67.09 MB, video/mp4)
2022-05-12 02:02 PDT, Vetle Arneberg
no flags Details
iOS 15.14.1 VG scroll bug on app banner (38.97 MB, video/mp4)
2022-05-12 02:05 PDT, Vetle Arneberg
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mads Erik Forberg 2021-10-12 01:08:04 PDT
Steps to reproduce:
1. Go to a page (e.g. https://www.vg.no)
2. Scroll down a bit and click one of the links
3. Swipe back / navigate back to previous page
4. The page will sometimes scroll to the top of the page

See screen recording here: https://drive.google.com/file/d/1iCBs7JbVV5QalKktedhKxHyTT5K0vy_F/view?usp=sharing
Comment 1 Mads Erik Forberg 2021-10-18 10:38:24 PDT
Seems like more users and sites and experiencing this:

Comment 2 Mads Erik Forberg 2021-10-18 11:02:09 PDT
(In reply to Mads Erik Forberg from comment #1)
> Seems like more users and sites and experiencing this:
> https://piunikaweb.com/2021/08/11/ios-15-beta-5-doesnt-fix-safari-forgets-
> scroll-position-on-previous-page/

The article says iOS 15 beta 4 and 5. But it’s still present here on iOS 15.1 latest public beta
Comment 3 Radar WebKit Bug Importer 2021-10-19 01:09:14 PDT
Comment 4 Mads Erik Forberg 2021-10-20 00:03:21 PDT
I've created a small hack / fix for this behavior until the issue is fixed:

Comment 5 Mads Erik Forberg 2022-01-27 00:39:37 PST
Any updates regarding this issue? Seems to be present in latest release and beta of iOS/Safari.
We see this issue on multiple sites.
Comment 6 Mads Erik Forberg 2022-01-28 03:54:29 PST
We've posted a write up about the issue here:
Comment 7 Simon Fraser (smfr) 2022-01-28 12:08:18 PST
It looks like some of these sites now have the workaround? Is there a way I can test without the workaround?
Comment 8 Mads Erik Forberg 2022-01-28 13:22:45 PST
Thank you for the response, Simon.

Yes - that's correct. I've now added a flag via query string to disable it: https://www.vg.no/?ios-bug=true

I'm able to reproduce the bug on that URL.
Comment 9 Simon Fraser (smfr) 2022-01-28 13:34:13 PST
I believe this is fixed in the most recent iOS release (iOS / iPadOS 15.3/19D50). Please test and confirm.
Comment 10 Mads Erik Forberg 2022-01-28 14:20:29 PST
It seems like it's still present in iOS 15.4 Public Beta (19E5209h) when testing on my device (iPhone Xs) using this test URL: https://www.vg.no/?ios-bug=true
Comment 11 Mads Erik Forberg 2022-01-28 14:22:55 PST
Screen recording of testing (with iOS 15.4): 
Comment 12 Mads Erik Forberg 2022-03-24 03:45:06 PDT
This is still present in latest iOS 15.4 - any updates here? :-)
Comment 13 Mads Erik Forberg 2022-03-24 03:52:32 PDT
The bug can easily be reproduced via this URL: https://www.vg.no/?ios-bug=true
Comment 14 Simon Fraser (smfr) 2022-03-24 11:34:01 PDT
I tried a number of times to reproduce this with that URL and was unable.
Comment 15 olekenneth 2022-03-25 04:38:39 PDT
Created attachment 455745 [details]
iOS15.4 buggy
Comment 16 olekenneth 2022-03-25 04:39:39 PDT
I'm using iPhone 12 with iOS 15.4 (19E241).
Comment 17 Mads Erik Forberg 2022-04-19 02:57:01 PDT
Created attachment 457873 [details]
Scroll bug on DT.no

Also buggy on the site www.dt.no
Comment 18 Mads Erik Forberg 2022-04-21 03:44:09 PDT
... and it's still present in latest public beta of iOS 15.5 (19F5057e).
Comment 19 Mads Erik Forberg 2022-04-21 03:55:38 PDT
While testing, I discovered the way that's the easiest to reproduce this:

1. Start a new tab session in Safari
2. Navigate to https://www.vg.no/?ios-bug=true (where the workaround is disabled)
3. Scroll down to a teaser / link a bit out of the first viewport.
4. Swipe / navigate back / use history back and the bug will trigger.

The clue seems to trigger more often when the browser / tab session is "fresh". I'm able to reproduce the bug on multiple devices, both physical and via emulation on BrowserStack.

I hope this will make it easier for you to reproduce the bug.
Comment 20 Mads Erik Forberg 2022-04-22 03:33:53 PDT
On the test page: https://www.vg.no/?ios-bug=true - I've added a `console.log({ scrollY });` in a `pageshow` event, which checks if the page is persisted, which then says that the Y position is `0`.

I've been able to reproduce this on both physical device and via BrowserStack.
Comment 21 Simon Fraser (smfr) 2022-04-22 10:47:07 PDT
I managed to reproduce this just once. The console.log() never fires in my experience.

It may be that page loading speed or behavior differs when loading it from a US IP address.
Comment 22 Simon Fraser (smfr) 2022-04-22 12:18:37 PDT
It's also possible this is related to the app banner. Do devices you reproduce this on also have the native app installed? Does removing the app change behavior?
Comment 23 olekenneth 2022-04-22 22:51:44 PDT
Did a test after removing the app and same result. But good suggestion. 

I see when I'm testing I'm almost always able to reproduce it. But I notice one thing. I'm swiping back while still scrolling or scrollbar are still visible on the page. Could this be relevant?
Comment 24 Simon Fraser (smfr) 2022-04-25 11:12:10 PDT
You're swiping back while still scrolling on the page you navigated to? So it's more like:
1. Tap the teaser link
2. On the page that lots, scroll a bit
3. Swipe back?
Comment 25 olekenneth 2022-04-27 01:04:05 PDT
Yes, but I did some tests now and made sure to stop scroll completely before swiping back and still had the problem. I'm taking to the top of the page right away. So probably not the issue
Comment 26 Johannes Andersen 2022-04-27 06:36:22 PDT
Created attachment 458441 [details]
iPadOS showing issue

iPad Pro (11-inch)
iPadOS: 15.5 (19F5062g)
Comment 27 Mads Erik Forberg 2022-04-28 02:46:26 PDT
*Might* be related; We see that the bug mostly happens if the browser navigates to the same origin and back. So if you click a teaser on `https://www.vg.no/?ios-bug=true` that goes to `https://www.vg.no/*` it seems to trigger.
Comment 28 Mads Erik Forberg 2022-05-10 00:07:27 PDT
Any updates regarding this issue? Seems like the bug triggers when navigating to same origin from the teasers.
Comment 29 Vetle Arneberg 2022-05-12 02:02:32 PDT
Created attachment 459212 [details]
iOS 15.4.1 NYT scroll bug when app banner is visiblle

This recording shows how meeting the app banner on either page (origin or destination) causes this scroll bug to happen on NY times, using iOS 15.14.1
Comment 30 Vetle Arneberg 2022-05-12 02:05:23 PDT
Created attachment 459213 [details]
iOS 15.14.1 VG scroll bug on app banner

To make sure what happened on NYT was consistent, I tested this on VG where the app banner is only shown in articles.

The bug occurred every time when the app banner was displayed in the article, however when I navigated to a page without the app banner, then the issue did not happen.