Skip to content
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

Add a fallback for the time tracking in the web #814

Merged
merged 1 commit into from
Jun 9, 2024

Conversation

CryZe
Copy link
Collaborator

@CryZe CryZe commented Jun 9, 2024

Every browser's performance.now() implementation is not spec compliant, unless the browser is running on Windows. On every other operating system, performance.now() does not properly keep ticking while the operating system is suspended / sleeping. There isn't much that we can do. What we can do is we calculate the initial difference between performance.now() and Date.now() and store it in a thread local. Later, when the phone gets locked, performance.now() starts to break. However, we can detect when the phone gets unlocked again by listening to the visibilitychange event. This is where we can update the difference again. This of course isn't ideal, as Date.now() gets adjusted by NTP synchronizations, but it's the best we can do.

More information:
https://developer.mozilla.org/en-US/docs/Web/API/Performance/now#ticking_during_sleep

Every browser's `performance.now()` implementation is not spec
compliant, unless the browser is running on Windows. On every other
operating system, `performance.now()` does not properly keep ticking
while the operating system is suspended / sleeping. There isn't much
that we can do. What we can do is we calculate the initial difference
between `performance.now()` and `Date.now()` and store it in a thread
local. Later, when the phone gets locked, `performance.now()` starts to
break. However, we can detect when the phone gets unlocked again by
listening to the `visibilitychange` event. This is where we can update
the difference again. This of course isn't ideal, as `Date.now()` gets
adjusted by NTP synchronizations, but it's the best we can do.

More information:
https://developer.mozilla.org/en-US/docs/Web/API/Performance/now#ticking_during_sleep
@CryZe CryZe added bug There is a bug. enhancement An improvement for livesplit-core. priority: high This is a high priority issue. labels Jun 9, 2024
@CryZe CryZe requested a review from wooferzfg June 9, 2024 21:15
@CryZe CryZe merged commit 5e48065 into LiveSplit:master Jun 9, 2024
70 checks passed
@CryZe CryZe deleted the web-time-fallback branch June 9, 2024 21:33
AlexKnauth pushed a commit to AlexKnauth/livesplit-core that referenced this pull request Jun 13, 2024
Every browser's `performance.now()` implementation is not spec
compliant, unless the browser is running on Windows. On every other
operating system, `performance.now()` does not properly keep ticking
while the operating system is suspended / sleeping. There isn't much
that we can do. What we can do is we calculate the initial difference
between `performance.now()` and `Date.now()` and store it in a thread
local. Later, when the phone gets locked, `performance.now()` starts to
break. However, we can detect when the phone gets unlocked again by
listening to the `visibilitychange` event. This is where we can update
the difference again. This of course isn't ideal, as `Date.now()` gets
adjusted by NTP synchronizations, but it's the best we can do.

More information:
https://developer.mozilla.org/en-US/docs/Web/API/Performance/now#ticking_during_sleep
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug There is a bug. enhancement An improvement for livesplit-core. priority: high This is a high priority issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant