PerformanceElementTiming: url プロパティ
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Experimental: これは実験的な機能です。
本番で使用する前にブラウザー互換性一覧表をチェックしてください。
url は PerformanceElementTiming インターフェイスの読み取り専用プロパティで、要素が画像の場合、リソースのリクエストの初期 URL を返します。
値
画像の場合はリソースリクエストの初期 URL となる文字列、テキストの場合は 0 となります。
例
>url をログ出力
この例では、 elementtiming 属性を追加して <img> 要素を監視しています。 PerformanceObserver は "element" 型のパフォーマンス項目をすべて取得するために登録され、オブザーバー作成前のデータにアクセスするために buffered フラグを用います。 entry.url を呼び出すと https://example.com/image.jpg が返されます。
html
<img
src="https://example.com/image.jpg"
alt="a nice image"
elementtiming="big-image"
id="myImage" />
js
const observer = new PerformanceObserver((list) => {
list.getEntries().forEach((entry) => {
if (entry.identifier === "big-image") {
console.log(entry.url);
}
});
});
observer.observe({ type: "element", buffered: true });
仕様書
| Specification |
|---|
| Element Timing API> # dom-performanceelementtiming-url> |
ブラウザーの互換性
Loading…