Search code examples
firefoxbrowsersafarinavigation-timing-apiboomerang

Browser Navigation Timing Level 2 timestamps are sometimes out of order


We are instrumenting pages with Boomerang, including much of the timeline data from Navigation Timing Level 2. Most of the time this all works fine, but for a small percentage of the requests we are instrumenting, we get timestamps that seem out-of-order, leading to negative duration values when we subtract the out-of-order timestamps.

For example, looking at a few hours of our data, out of about 10M hits, I see:

  • 56 instances where the timestamp for responseEnd is earlier than responseStart (e.g. responseEnd = 1619456473999, responseStart = 1619456479419)
  • 17 instances where the timestamp for unloadEventEnd is earlier than unloadEventStart (e.g. unloadEventEnd = 1619457675970, unloadEventStart = 1619457682839)
  • 7 instances where the timestamp for domComplete is earlier than domLoading (e.g. domComplete = 1619399859821, domLoading = 1619399860472)

I'm seeing this in a wide variety of browsers, many of which are old but some of which are newer (Firefox 88, Safari 13.1.2).

Basically I'm trying to figure out if this is something that happens to everybody and is just the state of the world with Nav Timing in real browsers (in which case I should just ignore it), or if it is more likely to be something wrong in our instrumentation (in which case I'll need to figure out what it is and fix it).

Thanks for any advice or feedback on your own experience!

----Scott.


Solution

  • Navigation Timing API / Specification comes in two versions:

    Level 1 is supported by all major browsers

    Level 2 is not yet supported by all browsers, e.g. Safari

    Level 1 relies on JavaScripts Date object, which is imprecise and can lead to falsy timestamps, as you have observed.

    Level 2 uses High Resolution Time to solve exactly this problem and ensures monotonically increasing timestamps.

    Boomerang is using Level 1, thats why you see corrupt timestamps.