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

Specify how timeOrigin is computed #7339

Merged
merged 11 commits into from
Nov 29, 2021
Merged

Specify how timeOrigin is computed #7339

merged 11 commits into from
Nov 29, 2021

Conversation

noamr
Copy link
Collaborator

@noamr noamr commented Nov 15, 2021

The time origin, which is the epoch for all performance timeline APIs,
was previously defined here.

This PR makes its computation explicity, without changing its current
definition and behavior.

  • time origin becomes an environment settings object algorithm,
    computed differently for windows vs. worker scopes

  • The 4 places where this timestamp is set are creation of an
    about:blank context, beginning of navigation, confirmation of an
    unload prompt, and creating a worker.

  • The timestamp is a shared monotonic clock value, which is defined
    in HR-TIME (and internally in ECMAScript).

As part of this PR, also refactored unload prompts to return a result
rather than rely on a somewhat hand-wavy "refused to allow" property.

See w3c/hr-time#131
and w3c/navigation-timing#166

(See WHATWG Working Mode: Changes for more details.)


/browsers.html ( diff )
/browsing-the-web.html ( diff )
/dom.html ( diff )
/history.html ( diff )
/infrastructure.html ( diff )
/webappapis.html ( diff )
/window-object.html ( diff )
/workers.html ( diff )
/worklets.html ( diff )

noamr added a commit to w3c/hr-time that referenced this pull request Nov 15, 2021
See whatwg/html#7339

`time origin` is now an `environment settings object` algorithm,
so the reference here should forward there.

Closes #131
source Outdated
@@ -87911,7 +87940,7 @@ interface <dfn interface>Location</dfn> { // but see also <a href="#the-location
data-x="concept-response-timing-info">timing info</span>,
<span data-x="navigation-params-response">response</span>'s <span
data-x="concept-response-service-worker-timing-info">service worker timing info</span>,
<var>redirectCount</var>, and <var>navigationType</var>.</p></li>
<var>redirectCount</var>, <var>navigationType</var>, and <var>previousTimeOrigin</var>.</p></li>
Copy link
Collaborator Author

@noamr noamr Nov 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to pass the previous time origin because of w3c/navigation-timing#166

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just about to ask the same... Worthwhile to add a note?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, can you clarify why this is correct? Are we replacing the value later?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will need to adjust the values of the ResourceTiming attributes in navigation timing. I didn't get to that patch yet...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a note below

Copy link
Contributor

@yoavweiss yoavweiss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm trying to extract the high-level design here:

  • We're setting loadTimingInfo's startTime when a new browsing context is created
  • When navigating, we set the navigationParams startTime to the moment of the navigation, but then override it after the unload handlers ran.
  • When creating and initializing a Document, we keep the time origin of the previous document and use it for initialization.
  • At the same time, we use the navigationParams' startTime to initialize the Document's loadTimingInfo.

Is that about right? It might be useful to add a description outlining the role of the environment settings object's time origin, the navigationParams start time and the loadTimingInfo's startTime.

source Outdated
@@ -87911,7 +87940,7 @@ interface <dfn interface>Location</dfn> { // but see also <a href="#the-location
data-x="concept-response-timing-info">timing info</span>,
<span data-x="navigation-params-response">response</span>'s <span
data-x="concept-response-service-worker-timing-info">service worker timing info</span>,
<var>redirectCount</var>, and <var>navigationType</var>.</p></li>
<var>redirectCount</var>, <var>navigationType</var>, and <var>previousTimeOrigin</var>.</p></li>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just about to ask the same... Worthwhile to add a note?

source Outdated
@@ -87911,7 +87940,7 @@ interface <dfn interface>Location</dfn> { // but see also <a href="#the-location
data-x="concept-response-timing-info">timing info</span>,
<span data-x="navigation-params-response">response</span>'s <span
data-x="concept-response-service-worker-timing-info">service worker timing info</span>,
<var>redirectCount</var>, and <var>navigationType</var>.</p></li>
<var>redirectCount</var>, <var>navigationType</var>, and <var>previousTimeOrigin</var>.</p></li>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, can you clarify why this is correct? Are we replacing the value later?

Copy link
Contributor

@yoavweiss yoavweiss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-authoritative LGTM!!
Thanks for the latest revamp - the handling of unsafe timers is much clearer now

@noamr
Copy link
Collaborator Author

noamr commented Nov 22, 2021

@domenic care to review?

source Outdated
unloaded</span>, then return.</p></li>
<li><p>If the result of calling <span>prompt to unload</span> with the
<span>active document</span> of the <var>specified browsing context</var> is
"<code data-x="">refuse</code>", then return.</p></li>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preexisting problem, but if you could fix while you're here it'd be nice: since we're in a queued task, we use "abort these steps" instead of "return"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I commented on the wrong line. "close a browsing context" should be "return"; "traverse the history by a delta" should be "abort these steps".

The time origin, which is the epoch for all performance timeline APIs,
was previously defined [here](https://w3c.github.io/hr-time/#dfn-time-origin).

This PR makes its computation explicity, without changing its current
definition and behavior.

- `time origin` becomes an `environment settings object` algorithm,
  computed differently for windows vs. worker scopes

- The 4 places where this timestamp is set are creation of an
`about:blank` context, beginning of navigation, confirmation of an
unload prompt, and creating a worker.

- The timestamp is a `shared monotonic clock` value, which is defined
in HR-TIME (and internally in ECMAScript).

As part of this PR, also refactored unload prompts to return a result
rather than rely on a somewhat hand-wavy "refused to allow" property.

See w3c/hr-time#131
and w3c/navigation-timing#166
noamr added a commit to noamr/ServiceWorker that referenced this pull request Nov 24, 2021
In [this HTML PR](whatwg/html#7339) we add
a `time origin` getter to the `environment settings object`.
We need to account for that value in service workers, which would be the
time the worker environment is created.
Copy link
Collaborator Author

@noamr noamr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Refactored worker creation time initialization to use closure variables instead of new associated things
  • Threaded through unsafeNavigationStartTime
  • Refactored prompt-result switch

Copy link
Member

@domenic domenic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hooray!

@domenic domenic merged commit 60c8bf6 into whatwg:main Nov 29, 2021
noamr added a commit to w3c/hr-time that referenced this pull request Dec 1, 2021
* Remove own version of `timeOrigin` definition

See whatwg/html#7339

`time origin` is now an `environment settings object` algorithm,
so the reference here should forward there.

Closes #131

* Refactor and add note
jakearchibald pushed a commit to w3c/ServiceWorker that referenced this pull request Jan 25, 2022
In [this HTML PR](whatwg/html#7339) we add
a `time origin` getter to the `environment settings object`.
We need to account for that value in service workers, which would be the
time the worker environment is created.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants