New issue
Advanced search Search tips

Issue 912015 link

Starred by 2 users

Issue metadata

Status: WontFix
Owner: ----
Closed: Dec 6
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Android
Pri: 2
Type: Bug



Sign in to add a comment

performance.now() reports incorrect time after smartphone screen was turned off

Reported by tigran...@gmail.com, Dec 5

Issue description

Steps 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.
 
performance-now.html
672 bytes View Download
This probably means we use uptimeMillis()[1] or similar, which seems correct to me. That is, when the OS enters deep sleep, the apps are not running, so 'time stops'. Note that the requirement for the clock used in performance.now() is only that it is monotonic. Thus, this does not seem to violate the spec.

[1] https://developer.android.com/reference/android/os/SystemClock?authuser=0&hl=kk

Do you have a use case for performance.now() to include time in which Chrome is not running? Given that performance.now() depends on TimeTicks::Now[2] which is used in many places, I don't think this will be changed, but it would be good to know what usage you have in mind.

[2] https://cs.chromium.org/chromium/src/base/time/time.cc?type=cs&g=0&l=348
Labels: Needs-triage-Mobile
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.
Status: WontFix (was: Unconfirmed)
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