-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
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
Exception in IE 9 due to unsupported High Resolution Time API / getNow race-condition #9632
Comments
It looks like this bug also affects IE 11. In IE 10 and 11 the result of the bug will be different, because they might choose You can open the linked JS fiddle in IE 11, choose read-only mode and then repeatedly click the "Result" tab and you'll see the result cycle randomly between eg. 1, 0, -1. |
I think the following would work in all cases without relying on offsets: var getNow = Date.now;
if (inBrowser && window.performance && performance.now
&& document.createEvent('Event').timeStamp <= performance.now()) {
getNow = function () { return performance.now(); };
} |
Fix proposed in #9647. |
@yyx990803 Please re-open this issue, your fix in da77d6a is not sufficient. It sidesteps the bug in IE 9, but does not fix it for IE 10 and IE 11. Please see #9647 for a proper fix. The problem with your fix is that on IE 10/11
Now the timestamp from This is why the comparison needs to happen with a monotonic timer like |
Btw. here is a screenshot from IE 11 running under Windows 10 Pro in VMware Fusion on macOS Mojave that shows how the comparison with Date.now() can fail: https://www.dropbox.com/s/tx4zw0u3bqhfxnl/Screenshot%202019-03-10%2004.33.26.png?raw=1 |
fix vuejs#9729 This reverts vuejs#9667, but also fixes the original issue vuejs#9632 by skipping the check in IE altogether (since all IE use low-res event timestamps).
Version
2.6.8
Reproduction link
https://jsfiddle.net/re08ag7z/
Steps to reproduce
When Vue.js is used in IE 9 (or IE 10/11 in IE 9 Emulation Mode), it sometimes crashes with an exception:
This seems to be due to the usage of
performance.now()
which is not supported in IE 9, see:https://caniuse.com/#feat=high-resolution-time
What is expected?
It should not crash, since IE 9 is a supported browser for Vue 2.x.
What is actually happening?
It crashes sometimes and sometimes it works.
I think the problem is a race-condition in the detection code of getNow:
It looks like if
document.createEvent('Event').timeStamp
returns a unix timestamp, the result of this check is unpredictable, and is sometimes true and sometimes false.Running the following in the IE 11 console when in IE 9 emulation mode sometimes returns true and sometimes false:
This check can also fail in IE 11 in IE 10 emulation mode, so it probably affects IE 10 as well.
A possible workaround would be to check for something like
getNow() > document.createEvent('Event').timeStamp 1000
, though that still seems a bit brittle.In my testing in a Windows 10 VM, the difference for
Date.now() - document.createEvent('Event').timeStamp
was usually /- 2 ms, but sometimes I also got larger offsets, like Date.now() around 22 ms larger than timeStamp.This problem could also be influenced by clock correction, when NTP or the VM host corrects the guest time between calls.
Generally comparisons of realtime clocks in computers is error prone and only monotonic timers should be trusted, which is probably one of the reasons why
performance.now()
was created…The text was updated successfully, but these errors were encountered: