PerformanceNavigationTiming: notRestoredReasons 屬性
PerformanceNavigationTiming 介面的只讀屬性 notRestoredReasons 返回一個 NotRestoredReasons 物件,該物件提供有關當前文件因何種原因被阻止使用後退/前進快取(bfcache)進行導航的報告資料。
值
當關聯的 PerformanceNavigationTiming 物件表示歷史導航時,notRestoredReasons 返回一個 NotRestoredReasons 物件。
當 PerformanceNavigationTiming 物件不表示歷史導航時,notRestoredReasons 將返回 null。這有助於確定 bfcache 是否與特定導航無關(而不是 notRestoredReasons 不被支援,在這種情況下它會返回 undefined)。
注意: 儘管導航型別被報告為後退/前進導航,notRestoredReasons 仍可能返回 null。這些情況包括在新標籤頁中複製後退/前進導航,以及在瀏覽器重啟後恢復後退/前進導航標籤頁。在這種情況下,某些瀏覽器會從原始標籤頁複製導航型別,但由於這些實際上不是後退/前進導航,因此 notRestoredReasons 返回 null。
示例
可以透過 Performance.getEntriesByType() 或 PerformanceObserver 從效能時間線獲取 PerformanceNavigationTiming 資料。
例如,您可以呼叫以下函式來返回當前存在於效能時間線中的所有 PerformanceNavigationTiming 物件,並記錄它們的 notRestoredReasons
function returnNRR() {
const navEntries = performance.getEntriesByType("navigation");
for (let i = 0; i < navEntries.length; i++) {
console.log(`Navigation entry ${i}`);
let navEntry = navEntries[i];
console.log(navEntry.notRestoredReasons);
}
}
PerformanceNavigationTiming.notRestoredReasons 屬性返回一個具有以下結構的 物件,該物件提供了當前文件因何種原因被阻止使用 bfcache 的原因。在此示例中,頂層框架沒有嵌入的子 <iframe>。
{
"children": [],
"id": null,
"name": null,
"reasons": [{ "reason": "unload-listener" }],
"src": "",
"url": "example.com"
}
規範
| 規範 |
|---|
| 導航計時 Level 2 # dom-performancenavigationtiming-notrestoredreasons |
瀏覽器相容性
載入中…