Performance: getEntries() メソッド
        
        
          
                Baseline
                
                  Widely available
                
                
              
        
        
        
          
                
              
                
              
                
              
        
        
      
      This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2017年9月.
getEntries() メソッドは、現在パフォーマンスタイムラインにあるすべての PerformanceEntry オブジェクトの配列を返します。
特定の型や特定の名前を持つパフォーマンス項目だけに関心がある場合は、 getEntriesByType() や getEntriesByName() を参照してください。
メモ:
このメソッドは新しいパフォーマンス項目を通知しません。このメソッドを呼び出した時点でパフォーマンスタイムラインに存在している項目のみを取得します。
利用できるようになった項目の通知を受け取るには、 PerformanceObserver を使用してください。
以下の項目型はこのメソッドではまったく対応しておらず、これらの型の項目が存在したとしても返されません。
- "element"(- PerformanceElementTiming)
- "event"(- PerformanceEventTiming)
- "largest-contentful-paint"(- LargestContentfulPaint)
- "layout-shift"(- LayoutShift)
- "longtask"(- PerformanceLongTaskTiming)
これらの型の項目にアクセスするには、代わりに PerformanceObserver を使用する必要があります。
構文
js
getEntries()
引数
なし。
返値
PerformanceEntry オブジェクトの配列 (Array)。要素は項目の startTime に基づいて時系列に並びます。
例
>パフォーマンスマーカーと測定値をすべてログ出力
自分自身で PerformanceMark および PerformanceMeasure オブジェクトをコードの適切な配置に作成したと想定すると、次のようにすべてコンソールにログ出力したくなるかもしれません。
js
// Example markers/measures
performance.mark("login-started");
performance.mark("login-finished");
performance.mark("form-sent");
performance.mark("video-loaded");
performance.measure("login-duration", "login-started", "login-finished");
const entries = performance.getEntries();
entries.forEach((entry) => {
  if (entry.entryType === "mark") {
    console.log(`${entry.name}'s startTime: ${entry.startTime}`);
  }
  if (entry.entryType === "measure") {
    console.log(`${entry.name}'s duration: ${entry.duration}`);
  }
});
仕様書
| Specification | 
|---|
| Performance Timeline> # dom-performance-getentries> | 
ブラウザーの互換性
Loading…