performance.now() reports incorrect time after smartphone screen was turned off
Reported by
tigran...@gmail.com,
Dec 5
|
|||
Issue descriptionSteps to reproduce the problem: 1. On smartphone, open the attached file or go to https://jsbin.com/gulowepuqu/edit?output 2. Every 10 seconds the script will log elapsed time calculated using Performance API and Date.now(). These two values are identical. 3. Turn smartphone screen off for a minute, then turn it back on. 4. The Performance API's value is now wrong, as if no time has passed while the screen was off. What is the expected behavior? As per the spec: "The now() method MUST return the current high resolution time." "The current high resolution time is the high resolution time from the time origin to the present time (typically called "now")" Hence performance.now() should report time passed from the time origin regardless of whether the screen was off, or the system clock was reset, or other circumstances. What went wrong? performance.now() behaves as though time while smartphone's screen was off was nonexistent. Did this work before? N/A Does this work in other browsers? No Chrome version: 70.0.3538.110 Channel: stable OS Version: 5.0.0 Flash Version: There is no such problem when you put a PC to sleep (tested on Windows 10), and then wake it up again.
,
Dec 6
,
Dec 6
I am writing an app where users can track time for different tasks. Think stopwatch. Using Date.now() while measuring intervals is prone to error due to system time changes. The Android docs linked above list elapsedRealtime() and elapsedRealtimeNanos() functions, which are, in my opinion, more suitable for performance.now(). As the docs put it: "This clock is guaranteed to be monotonic, and continues to tick even when the CPU is in power saving modes, so is the recommend basis for general purpose interval timing." The spec says performance.now() is "time from the time origin to the present time". The time really doesn't stop when in deep sleep. It doesn't stop on PC, but it stops on Android. Both this behaviors cannot be correct at the same time.
,
Dec 6
We use Linux's monotonic clock which seems to go to sleep when the OS is put to sleep. Usually performance.now() is meant to be used as a high resolution timer to determine the duration of some work being done on the website. As such it might not work for your use case. I found this website which seems to work well, so I encourage you to look into how they implement their stopwatch. http://www.timer-tab.com/ |
|||
►
Sign in to add a comment |
|||
Comment 1 by npm@chromium.org
, Dec 5