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

Clarify the initiator steps #714

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 36 additions & 22 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ spec: HTML; urlPrefix: https://html.spec.whatwg.org/multipage/
text: prompt; url: timers-and-user-prompts.html#dom-prompt
text: remove a browsing context; url: browsers.html#bcg-remove
text: report an error; url: webappapis.html#report-the-error
text: resource; url: infrastructure.html#resources
text: run the animation frame callbacks; url: imagebitmap-and-animations.html#run-the-animation-frame-callbacks
text: same origin domain; url: browsers.html#same-origin-domain
text: select an image source from a source set; url: images.html#select-an-image-source-from-a-source-set
Expand Down Expand Up @@ -5260,51 +5261,64 @@ network.Initiator = {
type: "parser" / "script" / "preflight" / "other",
? columnNumber: js-uint,
? lineNumber: js-uint,
? url: text,
? stackTrace: script.StackTrace,
? request: network.Request
};
</pre>

The <code>network.Initiatior</code> type represents the source of a network
OrKoN marked this conversation as resolved.
Show resolved Hide resolved
request.

Note: the purpose of initiator is to allow finding out which resource
initiated a particular request.

<div algorithm>
To <dfn>get the initiator</dfn> given |request|:

1. Let |request id| be |request|'s [=request id=].

1. Let |type| be "<code>other</code>".

1. Let |stack trace|, |url|, |column number|, and |line number| all be null.

1. If |request| is a [=CORS-Preflight Request=], set |type| to
"<code>preflight</code>".

1. TODO: Get the |type|. It's not quite clear how this ought to work; the CDP
data depends on whether the navigation was kicked off by the parser or by
script (so e.g. inserting an image from script causes the initiator to be
"<code>script</code>"), but that doesn't correspond to anything in Fetch.
1. Otherwise, if |request|'s [=request/initiator type=] is "<code>script</code>"
and |request| is [=isTopLevel=], set |type| to "<code>parser</code>".

1. Otherwise, if |request|'s [=request/initiator type=] is "<code>script</code>"
and |request| is not [=isTopLevel=], set |type| to "<code>script</code>".

1. Otherwise, if |request|'s [=request/initiator type=] is "<code>css</code>",
Copy link
Member

Choose a reason for hiding this comment

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

It's not clear to me if this is correct given e.g. @import rules (I don't know how CDP behaves)

set |type| to "<code>parser</code>".

TODO: probably some other initiator types should be treated as "parser".

1. If |request|'s [=request/referrer=] is a URL,
set |url| to |request|'s [=request/referrer=] otherwise set |url| to |request|'s document URL;

1. If |request|'s [=request/initiator type=] is "<code>fetch</code>" or
"<code>xmlhttprequest</code>":

1. Let |stack trace| be the [=current stack trace=].
1. Set |stack trace| to the [=current stack trace=].

1. Otherwise, if |type| is "<code>script</code>" and [=current stack trace=] is available to the implementation:

1. Set |stack trace| to the [=current stack trace=].

1. If |stack trace| has size of 1 or greater, let |line number| be value of the
<code>lineNumber</code> field in |stack trace|[0], and let |column number| be
the value of the <code>columnNumber</code> field in |stack trace|[0]. Otherwise
let |line number| and |column number| be 0.
1. Otherwise, if |type| is "<code>parser</code>" and implementation-defined parser state is available:

Otherwise, let |stack trace|, |column number|, and |line number| all be null.
1. Set |line number| to be zero-based parser line position in the resource that initiated the |request|.

TODO: Chrome includes the current parser position as column number / line
number for parser-inserted resources.
1. Set |column number| to be zero-based parser column position in the resource that initiated the |request|.

1. Return a [=/map=] matching the <code>network.Initiator</code> production, with
the <code>type</code> field set to |type|, the <code>columnNumber</code>
field set to |column number| if it's not null, or omitted otherwise, the
<code>lineNumber</code> field set to |line number| if it's not null, or
omitted otherwise, the <code>stackTrace</code> field set to |stack trace| if
it's not null, or omitted otherwise, and the <code>request</code> field set
to |request id|.
1. Return a [=/map=] matching the <code>network.Initiator</code>
production, with the <code>type</code> field set to |type|, the
<code>columnNumber</code> field set to |column number| if it's not
null, or omitted otherwise, the <code>lineNumber</code> field set to
|line number| if it's not null, or omitted otherwise, the
<code>stackTrace</code> field set to |stack trace| if it's not null,
or omitted otherwise, and the <code>url</code> field set to |url| if
it's not null, or omitted otherwise.

</div>

Expand Down
Loading