Automatic update from web-platform-tests Enable InitiatorUrl for ResourceTiming on dedicated and shared workers This CL is part of implementation of "initiator for resource timing" feature. Explainer: https://github.com/MicrosoftEdge/MSEdgeExplainers/blob/main/ResourceTimingInitiatorInfo/explainer.md Chromestatus: https://chromestatus.com/feature/4876586949804032 TaskAttribution is enabled on dedicated and shared workers to facilitate accurate initiator tracking for resources. This allows the different initiator URLs to be propagated across async tasks (e.g. setTimeout()) coming from different scripts(e.g. importScripts()). So, we can report initiator with better granularity than simply reporting worker script for all the resources and still be able to track back to the caller when an async task fetches a resource. There are still limitations on worker thread. What are supported: 1) Resources dynamically fetched by worker script, either directly or via a number of common async function calls covered by WPT tests that are added in this CL. 2) JS files imported by "importScripts()" What will be supported in future: 1) Worker script itself; What will be either supported or documented about if not supported: 1) Modular files used in worker thread; 2) Resources fetched in nested worker script; 3) Resources fetched in files that are imported via "importScripts()". Bug: 40919714 Change-Id: I07d6c744a0f568206404c78290d517865cb31d24 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7732189 Reviewed-by: Nate Chapin <japhet@chromium.org> Commit-Queue: Guohui Deng <guohuideng@microsoft.com> Reviewed-by: Scott Haseley <shaseley@chromium.org> Cr-Commit-Position: refs/heads/main@{#1618936} -- wpt-commits: 573966c6a0191ddff0c7edfb64f360fe37f48f51 wpt-pr: 59406
34 lines
1.1 KiB
JavaScript
34 lines
1.1 KiB
JavaScript
importScripts("/common/get-host-info.sub.js")
|
|
importScripts("/resource-timing/resources/loading-resource-lib.js")
|
|
|
|
const label = "initiator_url_message_handler_shared_worker";
|
|
const resource = "/images/blue.png?"+label;
|
|
const hostInfo = get_host_info();
|
|
const expectedInitiatorUrl = hostInfo["ORIGIN"] +
|
|
"/resource-timing/resources/message-handler-in-shared-worker.js";
|
|
|
|
const observe_entry_no_timeout = entryName => {
|
|
const entry = new Promise(resolve => {
|
|
new PerformanceObserver((entryList, observer) => {
|
|
for (const entry of entryList.getEntries()) {
|
|
if (entry.name.endsWith(entryName)) {
|
|
resolve(entry);
|
|
observer.disconnect();
|
|
return;
|
|
}
|
|
}
|
|
}).observe({"type": "resource", "buffered": true});
|
|
});
|
|
return entry;
|
|
};
|
|
|
|
self.onconnect = (e) => {
|
|
const port = e.ports[0];
|
|
port.onmessage = async function (event) {
|
|
fetch_in_function(resource);
|
|
const entry = await observe_entry_no_timeout(resource);
|
|
port.postMessage({result: entry.initiatorUrl,
|
|
expected: expectedInitiatorUrl});
|
|
};
|
|
};
|