Skip to content

Commit 43aa165

Browse files
Guohui Dengchromium-wpt-export-bot
authored andcommitted
Expose initiator-url in resourceTiming for more resources
TaskAttribution is extended to track `initiator-url". The progress of the "initiatorUrl" reporting after this CL is the below: A) Supported: (1) Any static resource from a html file; (2) Resources fetched in script, in main thread, that's not an imported script, under the condition that the resource fetch happens after script loading or beyond a number of common ways to dispatch an asynchronous call: postTask(); fulfillments of a promise; queueMicrotask(); requestAnimationFrame(); requestIdleCallback(); setInterval(); setTimeout(); XMLHttpRequest(); B) Not Supported yet but planned: (1) CSS resources that are initiated from another CSS file; (2) Script resources that are imported JS; (3) Resources fetched in the main thread, by the script that are dispatched via an EventHandler, or a MessageHandler; (4) Resource fetched by script running in a worker thread; C) Not planned to support: any rare cases that requires significant efforts, and any resources fetched via deprecated APIs. Example: (1) document.write(); (2) Resources fetched in the main thread, by the script that are dispatched via rarely used asynchronous calls. In addition, previous tests are re-organized and refactored. Credit to previous contributor: Some "inline-script" test cases are merged from(with significant modification): https://chromium-review.googlesource.com/c/chromium/src/+/4812813 And For script initiators, TaskAttributionInfo is used according to this draft CL: https://chromium-review.googlesource.com/c/chromium/src/+/4931296/21 PERFETTO_TESTS=`autoninja -C out/Default perfetto_diff_tests && out/Default/bin/run_perfetto_diff_tests` Bug: 40919714 Change-Id: I125e62d488eec5a85f8afa6cd61c399183c56d86 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6960132 Commit-Queue: Guohui Deng <guohuideng@microsoft.com> Reviewed-by: Scott Haseley <shaseley@chromium.org> Reviewed-by: Mikhail Khokhlov <khokhlov@google.com> Reviewed-by: Michal Mocny <mmocny@chromium.org> Cr-Commit-Position: refs/heads/main@{#1565205}
1 parent b1a45b8 commit 43aa165

21 files changed

Lines changed: 504 additions & 60 deletions

lint.ignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ SET TIMEOUT: html/webappapis/dynamic-markup-insertion/opening-the-input-stream/c
415415
SET TIMEOUT: html/webappapis/timers/*
416416
SET TIMEOUT: portals/history/resources/portal-harness.js
417417
SET TIMEOUT: requestidlecallback/deadline-after-expired-timer.html
418+
SET TIMEOUT: resource-timing/tentative/initiator-url/set-timeout.html
418419
SET TIMEOUT: resources/*
419420
SET TIMEOUT: scheduler/tentative/current-task-signal-async-abort.any.js
420421
SET TIMEOUT: scheduler/tentative/current-task-signal-async-priority.any.js
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!doctype html>
2+
<html>
3+
<script>
4+
window.addEventListener('message', e => {
5+
const port = e.ports?.[0];
6+
port.postMessage("hello from iframe");
7+
});
8+
</script>
9+
</html>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// This js file actually calls fetch to load an image to
2+
// an element.
3+
async function load_image(label, img_element) {
4+
const url = "/images/blue.png?"+label;
5+
const response = await fetch(url);
6+
blob = await response.blob();
7+
const imgURL = URL.createObjectURL(blob);
8+
img_element.src = imgURL;
9+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
function load_resources() {
2+
//Fetching the Stylesheet
3+
var link = document.createElement("link");
4+
link.rel = "stylesheet";
5+
link.href = "resources/empty_style.css?no_cache";
6+
link.id = "link_id";
7+
document.head.appendChild(link);
8+
9+
// Fetching an image
10+
var img = document.createElement("img");
11+
img.src = "/images/blue.png?no_cache";
12+
img.alt = "Sample Image for testing initiator Attribute";
13+
img.id = "img_id"
14+
document.body.appendChild(img);
15+
16+
// Inserting a script element
17+
var script = document.createElement("script");
18+
script.src = "resources/empty.js?no_cache";
19+
script.id = "script_id"
20+
document.body.appendChild(script);
21+
22+
//Inserting a html document in an iframe
23+
var iframe = document.createElement("iframe");
24+
iframe.src = "resources/green.html?no_cache";
25+
iframe.id = "iframe_id";
26+
document.body.appendChild(iframe);
27+
}
28+
29+
scheduler.postTask(load_resources);
Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
//Fetching the Stylesheet
22
var link = document.createElement("link");
33
link.rel = "stylesheet";
4-
link.href = "../resources/empty_style.css";
4+
link.href = "resources/empty_style.css?no_cache";
5+
link.id = "link_id";
56
document.head.appendChild(link);
67

78
// Fetching an image
89
var img = document.createElement("img");
9-
img.src = "/images/blue.png";
10+
img.src = "/images/blue.png?no_cache";
1011
img.alt = "Sample Image for testing initiator Attribute";
12+
img.id = "img_id"
1113
document.body.appendChild(img);
1214

13-
//Inserting a html document in an iframe
14-
var iframe = document.createElement("iframe");
15-
iframe.src = "../resources/green.html";
16-
document.body.appendChild(iframe);
17-
1815
// Inserting a script element
1916
var script = document.createElement("script");
20-
script.src = "../resources/empty.js";
17+
script.src = "resources/empty.js?no_cache";
18+
script.id = "script_id"
2119
document.body.appendChild(script);
20+
21+
//Inserting a html document in an iframe
22+
var iframe = document.createElement("iframe");
23+
iframe.src = "resources/green.html?no_cache";
24+
iframe.id = "iframe_id";
25+
document.body.appendChild(iframe);
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<!DOCTYPE html>
2+
<head>
3+
<script src="/resources/testharness.js"></script>
4+
<script src="/resources/testharnessreport.js"></script>
5+
<script src="/common/get-host-info.sub.js"></script>
6+
<script src="../../resources/test-initiator.js"></script>
7+
8+
<script src="../../resources/loading-resource-lib.js"></script>
9+
</head>
10+
<body>
11+
<h1>Description</h1>
12+
<p> This test verifies that, for a resource fetched via event handler,
13+
the initiator_url points to script that sets up the event handler.
14+
</p>
15+
</body>
16+
<script>
17+
18+
var img = document.createElement("img");
19+
document.body.appendChild(img);
20+
21+
const frame = document.createElement("iframe");
22+
frame.addEventListener("load", () => {
23+
load_image(label, img);
24+
});
25+
frame.src = "../resources/green.html";
26+
document.body.appendChild(frame);
27+
28+
29+
const label = "initiator_url_eventhandler";
30+
const resource = "/images/blue.png?"+label;
31+
const hostInfo = get_host_info();
32+
const expectedInitiatorUrl = hostInfo["ORIGIN"] +
33+
"/resource-timing/tentative/initiator-url/event-handler.html";
34+
35+
initiator_url_test(resource, expectedInitiatorUrl, resource +
36+
" initiatorUrl from event handlers", resource + " timeout");
37+
</script>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<!DOCTYPE html>
2+
<head>
3+
<script src="/resources/testharness.js"></script>
4+
<script src="/resources/testharnessreport.js"></script>
5+
<script src="/common/get-host-info.sub.js"></script>
6+
<script src="../../resources/test-initiator.js"></script>
7+
8+
</head>
9+
<body>
10+
<script src="../../resources/loading-resources-in-posted-task.js"></script>
11+
12+
<h1>Description</h1>
13+
<p> This test loads a number of resources in the loading-resources.js via scheduler.postTask()
14+
and verifies that `iniatitor_url`s in ResourceTiming are expected.
15+
</p>
16+
</body>
17+
<script>
18+
19+
const hostInfo = get_host_info();
20+
const expectedInitiatorUrl = hostInfo["ORIGIN"] + "/resource-timing/resources/loading-resources-in-posted-task.js";
21+
const resources = [
22+
"empty_style.css?no_cache",
23+
"blue.png?no_cache",
24+
"empty.js?no_cache",
25+
"green.html?no_cache",
26+
];
27+
for (const resource of resources) {
28+
initiator_url_test(resource, expectedInitiatorUrl, resource +
29+
" initiatorUrl by scheduler.postTask() from external scripts", resource + " timeout");
30+
}
31+
</script>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<!DOCTYPE html>
2+
<head>
3+
<script src="/resources/testharness.js"></script>
4+
<script src="/resources/testharnessreport.js"></script>
5+
<script src="/common/get-host-info.sub.js"></script>
6+
<script src="../../resources/test-initiator.js"></script>
7+
8+
</head>
9+
<body>
10+
<script src="../../resources/loading-resources.js"></script>
11+
12+
<h1>Description</h1>
13+
<p> This test loads a number of resources in the loading-resources.js and
14+
verifies that `iniatitor_url`s in ResourceTiming entries are as expected.
15+
</p>
16+
</body>
17+
<script>
18+
19+
const hostInfo = get_host_info();
20+
const expectedInitiatorUrl = hostInfo["ORIGIN"] + "/resource-timing/resources/loading-resources.js";
21+
const resources = [
22+
"empty_style.css?no_cache",
23+
"blue.png?no_cache",
24+
"empty.js?no_cache",
25+
"green.html?no_cache",
26+
];
27+
for (const resource of resources) {
28+
initiator_url_test(resource, expectedInitiatorUrl, resource +
29+
" initiatorUrl from external scripts", resource + " timeout");
30+
}
31+
</script>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!DOCTYPE html>
2+
<head>
3+
<script src="/resources/testharness.js"></script>
4+
<script src="/resources/testharnessreport.js"></script>
5+
<script src="/common/get-host-info.sub.js"></script>
6+
<script src="../../resources/test-initiator.js"></script>
7+
8+
<script src="../../resources/loading-resource-lib.js"></script>
9+
</head>
10+
<body>
11+
<h1>Description</h1>
12+
<p> This test verifies that, for a resource fetched via message handler,
13+
the initiator_url points to script that sends the message.
14+
</p>
15+
</body>
16+
<script>
17+
18+
const channel = new MessageChannel();
19+
const frame = document.createElement("iframe");
20+
frame.addEventListener("load", () => {
21+
frame.contentWindow.postMessage("port", "*", [channel.port2]);
22+
});
23+
frame.src = "../../resources/iframe-post-message.html";
24+
document.body.appendChild(frame);
25+
26+
var img = document.createElement("img");
27+
document.body.appendChild(img);
28+
29+
const label = "initiator_url_iframe_postmessage";
30+
const resource = "/images/blue.png?"+label;
31+
const hostInfo = get_host_info();
32+
const expectedInitiatorUrl = hostInfo["ORIGIN"] +
33+
"/resource-timing/tentative/initiator-url/iframe-post-message.html";
34+
35+
channel.port1.onmessage = e => {
36+
load_image(label, img);
37+
}
38+
39+
initiator_url_test(resource, expectedInitiatorUrl, resource +
40+
" initiatorUrl from iframe postMessage()", resource + " timeout");
41+
42+
</script>

resource-timing/tentative/initiator-url/inline-document-write.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
document.write('<link id="css_written" rel="stylesheet" href="../resources/empty_style.css?inline-script-doc-write">');
1818
document.write('<script id="script_written" src="../resources/empty.js?doc-write"><\/script>');
1919

20-
const host_info = get_host_info();
21-
const expectedInitiatorUrl = host_info["ORIGIN"] +
20+
const hostInfo = get_host_info();
21+
const expectedInitiatorUrl = hostInfo["ORIGIN"] +
2222
"/resource-timing/tentative/initiator-url/inline-document-write.html";
2323

2424
const resources = [

0 commit comments

Comments
 (0)