IOS – Mobile Safari opens tab with window.scrollY set to large negative number, only Smart Banner visible

iosipadmobile-safarisafariscrolling

I'm trying to figure out a very vexing bug (which might well be a mobile Safari issue) where opening a URL from an app is causing the page to load with a large negative scroll value and only the Smart Banner appearing.

In the example below, window.scrollY = -324. This is on iOS 8.1.2, both iPad and iPhones.

iPad Smart Banner initial scroll problem

The page does not have any scrolling-related javascript executed on page load. Everything appears as expected in the DOM, but when Smart Banner is enabled, this scroll issue happens somewhat sporadically. (It appears to happen most consistently

The issue resolves itself after any touch or rotate event, suggesting the browser knows that window.scrollY should be 0.

Has anyone dealt with a similar issue?

Best Answer

This appears to be a bug in mobile Safari. I was able to replicate this bug using a demo iOS app. Full details are here: https://github.com/than/Mobile-Safari-Smart-Banner-Viewport-Bug

Video of the bug in action: https://www.youtube.com/watch?v=IEILZ9uyH4g