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 |
浏览器兼容性
加载中…