-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Harmful performance.now() polyfill #762
Comments
Not quite sure what you mean here - it's specifically checking if the method doesn't exist on the object, and adding in that case. If it does exist then the |
I've just done a quick check in the console on the latest Firefox and Chrome, and the test is returning true.
|
Prototype chain it is, meh - nice catch! |
Closed via #763 |
Thanks for the quick turnaround! |
I still need to bake it into a release later today ;-) |
Hello!
Per the code below:
https://github.com/julianshapiro/velocity/blob/master/velocity.js#L498
I'm not quite sure if this is intentional, but this code is changing
performance.now()
in browsers that support it from a high-precision, monotonically non-decreasing timer (performance.now()
) with an epoch ofnavigationStart
to using a low-precision, system-time-affected timer (Date
) with an epoch ofdomComplete
.:(
The problem is that if
performance.now()
exists (e.g. is supported by the browser),!Object.prototype.hasOwnProperty.call(window.performance, "now")
will returntrue
and thusperformance.now()
will be overwritten to useDate
instead.Was it intended to just polyfill
performance.now()
if it didn't already exist? If so, a simpletypeof performance.now === 'function'
should suffice.The second question is, why does it use DOM Complete as its epoch? Is there something in velocity.js that expects this? Using DOM Complete changes the definition of the time origin, which should be Navigation Start.
Unfortunately this change directly affects any third party library that is measuring timestamps and comparing them to other DOMHighResTimeStamp timestamps on the page, i.e. those in NavigationTiming, ResourceTiming, UserTiming, etc.
We stumbled upon this because it is causing several measurements (e.g. Page Load) to be incorrect in boomerang. If one reads
performance.now()
as the first function in theonload
event, it should be essentially equal toperformance.timing.loadEventStart
. By offsetting it by DOM Complete, the two measurements could have values 1000s of ms apart. If you're doing any comparisons ofperformance.now()
to these other timestamps, your math will be off.I'm assuming the above wasn't intentional -- I've opened #763 to fix these two issues.
Thanks!
The text was updated successfully, but these errors were encountered: