web api instance property
PerformanceResourceTiming: initiatorType property
Available in workers
The initiatorType read-only property is a string representing web platform feature that initiated the resource load.
[!NOTE] This property does not represent the type of content fetched. A
.cssfile can be fetched using a<link>element leading to aninitiatorTypeoflink. When loading images usingbackground: url()in a CSS file, theinitiatorTypewill becssand notimg.
Value
The initiatorType property can have the following values, or other if none of the conditions match.
audio- : If the request was initiated by an
<audio>element’ssrcattribute.
- : If the request was initiated by an
beacon- : If the request was initiated by a
sendBeacon()method.
- : If the request was initiated by a
body- : If the request was initiated by a
<body>element’sbackgroundattribute.
- : If the request was initiated by a
css- : If the request was initiated by a CSS
url()function.
- : If the request was initiated by a CSS
early-hint- : If the request was initiated by an
103Early Hintresponse.
- : If the request was initiated by an
embed- : If the request was initiated by an
<embed>element’ssrcattribute.
- : If the request was initiated by an
fetch- : If the request was initiated by a
fetch()method.
- : If the request was initiated by a
frame- : If the request was initiated by loading a
<frame>element.
- : If the request was initiated by loading a
iframe- : If the request was initiated by an
<iframe>element’ssrcattribute.
- : If the request was initiated by an
icon- : If the request was initiated by a favicon. Non-standard and only reported by Safari.
image- : If the request was initiated by an
<image>element.
- : If the request was initiated by an
img- : If the request was initiated by an
<img>element’ssrcorsrcsetattribute.
- : If the request was initiated by an
input- : If the request was initiated by an
<input>element of typeimage.
- : If the request was initiated by an
link- : If the request was initiated by a
<link>element.
- : If the request was initiated by a
navigation- : If the request was initiated by a navigation request.
object- : If the request was initiated by an
<object>element.
- : If the request was initiated by an
ping- : If the request was initiated by an
<a>element’sping.
- : If the request was initiated by an
script- : If the request was initiated by a
<script>element.
- : If the request was initiated by a
track- : If the request was initiated by a
<track>element’ssrc.
- : If the request was initiated by a
video- : If the request was initiated by a
<video>element’sposterorsrc.
- : If the request was initiated by a
xmlhttprequest- : If the request was initiated by an
XMLHttpRequest.
- : If the request was initiated by an
Examples
Filtering resources
The initiatorType property can be used to get specific resource timing entries only. For example, only those that were initiated by <script> elements.
Example using a PerformanceObserver, which notifies of new resource performance entries as they are recorded in the browser’s performance timeline. Use the buffered option to access entries from before the observer creation.
const observer = new PerformanceObserver((list) => {
const scripts = list
.getEntries()
.filter((entry) => entry.initiatorType === "script");
console.log(scripts);
});
observer.observe({ type: "resource", buffered: true });
Example using getEntriesByType(), which only shows resource performance entries present in the browser’s performance timeline at the time you call this method:
const scripts = performance
.getEntriesByType("resource")
.filter((entry) => entry.initiatorType === "script");
console.log(scripts);