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

Resource Timing integration #319

Merged
merged 13 commits into from
Feb 11, 2022
Merged

Resource Timing integration #319

merged 13 commits into from
Feb 11, 2022

Conversation

noamr
Copy link
Contributor

@noamr noamr commented Mar 17, 2021

When response is a network error or body is fully read,
finalize and report the response.

Depends on whatwg/fetch#1185

See:
w3c/resource-timing#261
and w3c/resource-timing#252


Preview | Diff


Preview | Diff

xhr.bs Outdated Show resolved Hide resolved
Copy link
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

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

It seems that the way this works out is that there's a report timing object created just before the load event is invoked, which seems good.

xhr.bs Outdated Show resolved Hide resolved
xhr.bs Outdated Show resolved Hide resolved
@annevk
Copy link
Member

annevk commented Mar 23, 2021

Note that the string formatting comment still stands I think.

xhr.bs Outdated Show resolved Hide resolved
@noamr noamr changed the title WIP: Resource Timing integration Resource Timing integration Mar 24, 2021
xhr.bs Outdated Show resolved Hide resolved
Copy link
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

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

Apologies for not updating this sooner. While reviewing this I ended up filing whatwg/fetch#1201, but forgot to write down the bits that didn't add up for me here.

xhr.bs Outdated
@@ -1018,6 +1024,8 @@ return <a>this</a>'s <a>cross-origin credentials</a>.
<ol>
<li><p>Set <var>xhr</var>'s <a>state</a> to <i>done</i>.

<li><p><a for=/>Report timing</a> for <var>xhr</var>.
Copy link
Member

Choose a reason for hiding this comment

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

We report timings here, but two steps down we set response to a network error. Whereas above we don't report timing at all if response is a network error.

Now per whatwg/fetch#1202 maybe some network errors should get report timing, but I don't think the current setup makes that happen correctly, right?

Copy link
Contributor Author

@noamr noamr Apr 14, 2021

Choose a reason for hiding this comment

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

We always call "Report timing", and let FETCH decide if to report or not (if the response has a timing info).

WDYM by "above we don't report timing at all if response is a network error", I think we do: if <var>xhr</var>'s <a for=XMLHttpRequest>response</a>'s is a <a for=/>network error</a>, run the <a>request error steps</a> for <var>xhr</var> (request error steps would report the timing).

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I think that's right. Let's solve whatwg/fetch#1215 before landing this then as currently finalize and report timing always returns early for network errors I just discovered.

I think it would also be good to ensure we have test coverage here. In the sense that the final readystatechange/load event has access to the RT entry.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's solve whatwg/fetch#1215 before landing this then as currently finalize and report timing always returns early for network errors I just discovered.

whatwg/fetch#1311 addressed this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a requisite test here: web-platform-tests/wpt#31027

@whatwg whatwg deleted a comment from mobinskyman Apr 13, 2021
noamr added a commit to noamr/fetch that referenced this pull request Sep 26, 2021
Also, report timing info for network errors for the fetch() APIs.
The timing info attached to a network error is always "opaque",
containing only start/end time and the original request URL.

This change currently only applies to the fetch API, and should be
applied to the different callers of FETCCH as part of
[this](whatwg/html#6542) and
[this](whatwg/xhr#319) work.

Closes whatwg#1215
noamr added a commit to noamr/fetch that referenced this pull request Sep 28, 2021
Also, report timing info for network errors for the fetch() APIs.
The timing info attached to a network error is always "opaque",
containing only start/end time and the original request URL.

This change currently only applies to the fetch API, and should be
applied to the different callers of FETCCH as part of
[this](whatwg/html#6542) and
[this](whatwg/xhr#319) work.

Closes whatwg#1215
noamr added a commit to web-platform-tests/wpt that referenced this pull request Sep 30, 2021
Test that:
- A ResourceTiming entry is created for an XmlHttpRequest
- The entry is available during load event handling
- The entry's responseEnd time is not after the load event time
- Entries are created for network errors (e.g. CORS fail, wrong scheme)

See whatwg/xhr#319
noamr added a commit to web-platform-tests/wpt that referenced this pull request Oct 4, 2021
* XHR ResourceTiming entry creation

Test that:
- A ResourceTiming entry is created for an XmlHttpRequest
- The entry is available during load event handling
- The entry's responseEnd time is not after the load event time
- Entries are created for network errors (e.g. CORS fail, wrong scheme)

See whatwg/xhr#319

* lint

* Move xhr internals to resource-loaders
@noamr
Copy link
Contributor Author

noamr commented Oct 5, 2021

@annevk I think this should be OK now, in conjunction with the FETCH handling of network errors.

moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Oct 5, 2021
…tonly

Automatic update from web-platform-tests
XHR ResourceTiming entry creation (#31027)

* XHR ResourceTiming entry creation

Test that:
- A ResourceTiming entry is created for an XmlHttpRequest
- The entry is available during load event handling
- The entry's responseEnd time is not after the load event time
- Entries are created for network errors (e.g. CORS fail, wrong scheme)

See whatwg/xhr#319

* lint

* Move xhr internals to resource-loaders
--

wpt-commits: 167763f156d113e154cf35960741dc1876f556a8
wpt-pr: 31027
jamienicol pushed a commit to jamienicol/gecko that referenced this pull request Oct 6, 2021
…tonly

Automatic update from web-platform-tests
XHR ResourceTiming entry creation (#31027)

* XHR ResourceTiming entry creation

Test that:
- A ResourceTiming entry is created for an XmlHttpRequest
- The entry is available during load event handling
- The entry's responseEnd time is not after the load event time
- Entries are created for network errors (e.g. CORS fail, wrong scheme)

See whatwg/xhr#319

* lint

* Move xhr internals to resource-loaders
--

wpt-commits: 167763f156d113e154cf35960741dc1876f556a8
wpt-pr: 31027
Gabisampaio pushed a commit to Gabisampaio/wpt that referenced this pull request Nov 18, 2021
* XHR ResourceTiming entry creation

Test that:
- A ResourceTiming entry is created for an XmlHttpRequest
- The entry is available during load event handling
- The entry's responseEnd time is not after the load event time
- Entries are created for network errors (e.g. CORS fail, wrong scheme)

See whatwg/xhr#319

* lint

* Move xhr internals to resource-loaders
@noamr
Copy link
Contributor Author

noamr commented Dec 14, 2021

@annevk: revised to align with how FETCH handles network errors.
Basically we need to report in all of the network-error cases ("handle errors"), and in the "end of body" case when there is no error. In both cases we report to the timeline before any other reporting (e.g. exception) is done.

@noamr
Copy link
Contributor Author

noamr commented Jan 17, 2022

@annevk: revised to align with how FETCH handles network errors. Basically we need to report in all of the network-error cases ("handle errors"), and in the "end of body" case when there is no error. In both cases we report to the timeline before any other reporting (e.g. exception) is done.

@annevk this has been ready for a while for a review. Could you take a look when you get a chance?

@noamr noamr closed this Feb 8, 2022
@noamr noamr reopened this Feb 8, 2022
xhr.bs Outdated Show resolved Hide resolved
@@ -963,6 +967,8 @@ return <a>this</a>'s <a>cross-origin credentials</a>.
<li><p>If <var>xhr</var>'s <a for=XMLHttpRequest>response</a> is a <a>network error</a>, then
return.

<li><p><a for=/>Report timing</a> for <var>xhr</var>.

Choose a reason for hiding this comment

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

Could we move this to line 966, and avoid calling report timing from 2 different places?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, because handle errors needs to report errors only in certain conditions + we need to report it if there are no errors. So there will always be two places

Copy link
Member

Choose a reason for hiding this comment

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

It seems to me we could move this up if we make it conditional upon the timed out flag? (And in the future perhaps the timed out flag can be replaced by using an aborted network error.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah it wouldn't work because handle errors is also called from processBodyError, in which case the processEndOfBody callback will not be reached at all. We've been through this in early iterations of this PR

@annevk annevk merged commit b4da01a into whatwg:main Feb 11, 2022
@noamr noamr deleted the fetch-rt-integ branch February 11, 2022 12:52
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