From 4e76ee293f310d817408a702d331e0a110f017c8 Mon Sep 17 00:00:00 2001 From: Alex Rudenko Date: Tue, 21 May 2024 13:46:40 +0200 Subject: [PATCH 1/6] Update initiator algorithms --- index.bs | 56 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/index.bs b/index.bs index 752a6db0..a3cdd65b 100644 --- a/index.bs +++ b/index.bs @@ -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 @@ -5257,11 +5258,11 @@ To deserialize header given |protocol header|:
 network.Initiator = {
-    type: "parser" / "script" / "preflight" / "other",
+    type: text,
     ? columnNumber: js-uint,
     ? lineNumber: js-uint,
+    ? url: text,
     ? stackTrace: script.StackTrace,
-    ? request: network.Request
 };
 
@@ -5271,40 +5272,41 @@ request.
To get the initiator given |request|: -1. Let |request id| be |request|'s [=request id=]. - -1. Let |type| be "other". - -1. If |request| is a [=CORS-Preflight Request=], set |type| to - "preflight". - -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 - "script"), but that doesn't correspond to anything in Fetch. +1. Let |type| be |request|'s [=request/initiator type=]. 1. If |request|'s [=request/initiator type=] is "fetch" or "xmlhttprequest": 1. Let |stack trace| be the [=current stack trace=]. - 1. If |stack trace| has size of 1 or greater, let |line number| be value of the - lineNumber field in |stack trace|[0], and let |column number| be - the value of the columnNumber field in |stack trace|[0]. Otherwise - let |line number| and |column number| be 0. + 1. If |stack trace| has size of 1 or greater: + + 1. Let |url| be value of the url in |stack trace|[0]. + + 1. Let |line number| be value of the lineNumber field in + |stack trace|[0]. + + 1. Let |column number| be the value of the columnNumber + field in |stack trace|[0]. + +1. Otherwise: + + 1. Let |stack trace| be null. + + 1. Let |url| be the URL of the [=resource=] that initiated |request|. - Otherwise, let |stack trace|, |column number|, and |line number| all be null. + 1. Let |column number| be the column number within the [=resource=] that initiated |request|. - TODO: Chrome includes the current parser position as column number / line - number for parser-inserted resources. + 1. Let |line number| be the line number within the [=resource=] that initiated |request|. -1. Return a [=/map=] matching the network.Initiator production, with - the type field set to |type|, the columnNumber - field set to |column number| if it's not null, or omitted otherwise, the - lineNumber field set to |line number| if it's not null, or - omitted otherwise, the stackTrace field set to |stack trace| if - it's not null, or omitted otherwise, and the request field set - to |request id|. +1. Return a [=/map=] matching the network.Initiator + production, with the type field set to |type|, the + columnNumber field set to |column number| if it's not + null, or omitted otherwise, the lineNumber field set to + |line number| if it's not null, or omitted otherwise, the + stackTrace field set to |stack trace| if it's not null, + or omitted otherwise, and the url field set to |url| if + it's not null, or omitted otherwise.
From 41c1632ab2f04652b92c4ab8f55f70a491758f24 Mon Sep 17 00:00:00 2001 From: Alex Rudenko Date: Fri, 24 May 2024 09:42:26 +0200 Subject: [PATCH 2/6] Is parser-inserted metadata close enough? --- index.bs | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/index.bs b/index.bs index a3cdd65b..a96f99c8 100644 --- a/index.bs +++ b/index.bs @@ -5258,7 +5258,7 @@ To deserialize header given |protocol header|:
 network.Initiator = {
-    type: text,
+    type: "parser" / "script" / "preflight" / "other",
     ? columnNumber: js-uint,
     ? lineNumber: js-uint,
     ? url: text,
@@ -5272,32 +5272,34 @@ request.
 
To get the initiator given |request|: -1. Let |type| be |request|'s [=request/initiator type=]. +1. Let |type| be "other". -1. If |request|'s [=request/initiator type=] is "fetch" or - "xmlhttprequest": +1. If |request| is a [=CORS-Preflight Request=], set |type| to + "preflight". - 1. Let |stack trace| be the [=current stack trace=]. +1. Otherwise, if |requests|'s [=parser metadata=] is "not-parser-inserted", + set |type| to "script". - 1. If |stack trace| has size of 1 or greater: +1. Otherwise, if |requests|'s [=parser metadata=] is "parser-inserted", + set |type| to "parser". - 1. Let |url| be value of the url in |stack trace|[0]. +1. If |type| is "script": - 1. Let |line number| be value of the lineNumber field in - |stack trace|[0]. + 1. Let |stack trace| be the [=current stack trace=]. - 1. Let |column number| be the value of the columnNumber - field in |stack trace|[0]. + 1. Let |url| be value of the url in |stack trace|[0]. -1. Otherwise: + 1. Let |line number| be value of the lineNumber field in + |stack trace|[0]. - 1. Let |stack trace| be null. + 1. Let |column number| be the value of the columnNumber + field in |stack trace|[0]. - 1. Let |url| be the URL of the [=resource=] that initiated |request|. +1. Otherwise, if |type| is "parser": - 1. Let |column number| be the column number within the [=resource=] that initiated |request|. + 1. TODO: set url/line/column based on the parser positions. - 1. Let |line number| be the line number within the [=resource=] that initiated |request|. +1. Otherwise, let |stack trace|, |column number|, and |line number| all be null. 1. Return a [=/map=] matching the network.Initiator production, with the type field set to |type|, the From a524f967fb668d9124d852aa039b8f19f54b529d Mon Sep 17 00:00:00 2001 From: Alex Rudenko Date: Thu, 13 Jun 2024 19:59:31 +0200 Subject: [PATCH 3/6] initiator steps --- index.bs | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/index.bs b/index.bs index a96f99c8..f359aae0 100644 --- a/index.bs +++ b/index.bs @@ -5269,37 +5269,47 @@ network.Initiator = { The network.Initiatior type represents the source of a network request. +Note: the purpose of initiator to allow finding out which resource +initiated a particular request. +
To get the initiator given |request|: 1. Let |type| be "other". +1. Let |stack trace|, |url|, |column number|, and |line number| all be null. + 1. If |request| is a [=CORS-Preflight Request=], set |type| to "preflight". -1. Otherwise, if |requests|'s [=parser metadata=] is "not-parser-inserted", - set |type| to "script". +1. Otherwise, if |request|'s [=request/initiator type=] is "script" + and |request| is [=isTopLevel=], set |type| to "parser". -1. Otherwise, if |requests|'s [=parser metadata=] is "parser-inserted", +1. Otherwise, if |request|'s [=request/initiator type=] is "script" + and |request| is not [=isTopLevel=], set |type| to "script". + +1. Otherwise, if |request|'s [=request/initiator type=] is "css", set |type| to "parser". -1. If |type| is "script": + 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. Let |stack trace| be the [=current stack trace=]. +1. If |request|'s [=request/initiator type=] is "fetch" or + "xmlhttprequest": - 1. Let |url| be value of the url in |stack trace|[0]. + 1. Set |stack trace| be the [=current stack trace=]. - 1. Let |line number| be value of the lineNumber field in - |stack trace|[0]. +1. Otherwise, if |type| is "script" and [=current stack trace=] is available to the implementation: - 1. Let |column number| be the value of the columnNumber - field in |stack trace|[0]. + 1. Set |stack trace| be the [=current stack trace=]. -1. Otherwise, if |type| is "parser": +1. Otherwise, if |type| is "parser" and implementation-defined parser state is available: - 1. TODO: set url/line/column based on the parser positions. + 1. Set |line number| to be zero-based parser line position in the resource that initiated the |request|. -1. Otherwise, let |stack trace|, |column number|, and |line number| all be null. + 1. Set |column number| to be zero-based parser column position in the resource that initiated the |request|. 1. Return a [=/map=] matching the network.Initiator production, with the type field set to |type|, the From 080afc9d69a3c13dbd99b7a4e3363fb072e75be9 Mon Sep 17 00:00:00 2001 From: Alex Rudenko Date: Thu, 27 Jun 2024 12:26:32 +0200 Subject: [PATCH 4/6] Update index.bs Co-authored-by: Julian Descottes --- index.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.bs b/index.bs index f359aae0..ed9db7b6 100644 --- a/index.bs +++ b/index.bs @@ -5269,7 +5269,7 @@ network.Initiator = { The network.Initiatior type represents the source of a network request. -Note: the purpose of initiator to allow finding out which resource +Note: the purpose of initiator is to allow finding out which resource initiated a particular request.
From c3024c7127338c2c61a39f09c469feb023904c62 Mon Sep 17 00:00:00 2001 From: Alex Rudenko Date: Thu, 27 Jun 2024 12:26:54 +0200 Subject: [PATCH 5/6] Update index.bs Co-authored-by: Julian Descottes --- index.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.bs b/index.bs index ed9db7b6..9f6a8fa5 100644 --- a/index.bs +++ b/index.bs @@ -5299,7 +5299,7 @@ To get the initiator given |request|: 1. If |request|'s [=request/initiator type=] is "fetch" or "xmlhttprequest": - 1. Set |stack trace| be the [=current stack trace=]. + 1. Set |stack trace| to the [=current stack trace=]. 1. Otherwise, if |type| is "script" and [=current stack trace=] is available to the implementation: From 1ff00d44726a6ed742e5651ef5dd07a2e75e34aa Mon Sep 17 00:00:00 2001 From: Alex Rudenko Date: Thu, 27 Jun 2024 12:26:59 +0200 Subject: [PATCH 6/6] Update index.bs Co-authored-by: Julian Descottes --- index.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.bs b/index.bs index 9f6a8fa5..93a57ede 100644 --- a/index.bs +++ b/index.bs @@ -5303,7 +5303,7 @@ To get the initiator given |request|: 1. Otherwise, if |type| is "script" and [=current stack trace=] is available to the implementation: - 1. Set |stack trace| be the [=current stack trace=]. + 1. Set |stack trace| to the [=current stack trace=]. 1. Otherwise, if |type| is "parser" and implementation-defined parser state is available: