Bug 186919 - Navigation Timing data is corrupt in WebView (UIWebView/WKWebView)
Summary: Navigation Timing data is corrupt in WebView (UIWebView/WKWebView)
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: WebKit Nightly Build
Hardware: iPhone / iPad iOS 11
: P2 Major
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2018-06-22 07:09 PDT by krinklemail
Modified: 2018-06-27 14:39 PDT (History)
8 users (show)

See Also:


Attachments
Test case (1.77 KB, text/html)
2018-06-23 09:37 PDT, krinklemail
no flags Details
Test case (response/request order) (1.73 KB, text/html)
2018-06-23 09:43 PDT, krinklemail
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description krinklemail 2018-06-22 07:09:55 PDT
iOS 8.0 introduced support for the Navigation Timing API, which had issues and was removed in 8.1, then re-introduced in iOS 9.0 with different issues. These were fixed for the Mobile Safari app in 9.1, but WebView remained a source of invalid Navigation Timing data and has continued to have the same issues to this day in iOS 11.

Downstream report: https://phabricator.wikimedia.org/T190977

Specifically, the following two types of data corruption are the most common in data received from Wikipedia users:

* fetchStart went backwards from unloadEventEnd.
* responseStart went backwards from requestStart.

Test url:
https://codepen.io/Krinkle/pen/pKVqPy?editors=0100

Steps to reproduce:
Intermittent, but loading this page within an app (e.g. Apple Dictionary, Facebook Messenger, Feedly, etc.), either directly from a native view, or as secondary navigation after initially entering an embedded view, most often when refreshing the view, will eventually cause the error to occur.

Impact:
For Wikipedia, the data from Navigation Timing API is central to measuring performance from users. iOS WebView is a significant source of traffic (at between 1% and 2% of Wikipedia page views, per Jan-May 2018). Unfortunately, (almost) all of this data is discarded before recording because it does not pass a basic data compliance check.

Here's a dump from the logs of our data validation service from last few hours (sorted by frequency)

| Rank | Hits | Normalised message
| ---- | ---- | ------------------
| #1   | 1987 | (is_compliant:443) Discarding event because responseEnd is out of order [{'os_minor': '4', 'os_major': '11', 'device_family': 'iPhone', 'os_family': 'iOS', 'browser_minor': '0', 'browser_major': '11', 'browser_family': 'Mobile Safari'}]
| #2   | 1566 | (is_compliant:443) Discarding event because requestStart is out of order [{'os_minor': '3', 'os_major': '9', 'device_family': 'iPad', 'os_family': 'iOS', 'browser_minor': '0', 'browser_major': '9', 'browser_family': 'Mobile Safari'}]
| #3   |  821 | (is_compliant:443) Discarding event because responseEnd is out of order [{'os_minor': '3', 'os_major': '11', 'device_family': 'iPhone', 'os_family': 'iOS', 'browser_minor': '0', 'browser_major': '11', 'browser_family': 'Mobile Safari'}]
| #4   |  786 | (is_compliant:443) Discarding event because requestStart is out of order [{'os_minor': '3', 'os_major': '9', 'device_family': 'iPhone', 'os_family': 'iOS', 'browser_minor': '0', 'browser_major': '9', 'browser_family': 'Mobile Safari'}]
| #5   |  468 | (is_compliant:443) Discarding event because responseEnd is out of order [{'os_minor': '2', 'os_major': '11', 'device_family': 'iPhone', 'os_family': 'iOS', 'browser_minor': '0', 'browser_major': '11', 'browser_family': 'Mobile Safari'}]

There used to be a Chrome entry in the top 5 as well (Chrome 62 and earlier produced invalid timing data on redirected navigations), but that was fixed per https://bugs.chromium.org/p/chromium/issues/detail?id=813889.

At this time, Mobile Safari (WebView) accounts for 98% of navigation timing errors.

See also:
* https://bugs.webkit.org/show_bug.cgi?id=184363
* Downstream investigation: https://phabricator.wikimedia.org/T190977
* Similar issue in Chromium (affecting redirects only, FIXED) - https://bugs.chromium.org/p/chromium/issues/detail?id=813889
* Wikipedia performance data validation - https://grafana.wikimedia.org/dashboard/db/eventlogging-schema?var-schema=NavigationTiming (currently around 0.3 errors per second, from a sampling of 1:1000 page views)
Comment 1 Radar WebKit Bug Importer 2018-06-22 23:15:41 PDT
<rdar://problem/41393423>
Comment 2 krinklemail 2018-06-23 09:37:52 PDT
Created attachment 343438 [details]
Test case

Simple HTML file (the pen url only works when using CodePen's Debug View, due to the framed wrapper somehow causing the issue not to happen).
Comment 3 krinklemail 2018-06-23 09:43:14 PDT
Created attachment 343439 [details]
Test case (response/request order)