大网数据广告活动
Web 标准与前端开发

PerformanceSoftNavigation

· 52CE 我爱测

The `PerformanceSoftNavigation` interface provides timing information about soft navigation as used by client-side routing on SPA sites. It is emitted when a browser observes a soft navigation to have taken place.

Performance API

The PerformanceSoftNavigation interface provides timing information about soft navigation as used by client-side routing on SPA sites. It is emitted when a browser observes a soft navigation to have taken place.

Instance properties

This interface directly defines the following properties:

  • PerformanceSoftNavigation.interactionId
    • : The id of the interaction that resulted in the soft navigation.
  • PerformanceSoftNavigation.navigationType
    • : The type of the navigation.
  • PerformanceSoftNavigation.paintTime
    • : Returns the DOMHighResTimeStamp of when the first rendering phase ended and the paint phase started.
  • PerformanceSoftNavigation.presentationTime
    • : Returns the DOMHighResTimeStamp of when the first painted pixels were actually drawn on the screen.

It also extends the following PerformanceEntry properties, qualifying and constraining them as described:

  • PerformanceEntry.entryType
    • : Returns "soft-navigation".
  • PerformanceEntry.duration
    • : Returns the result of PerformanceSoftNavigation.presentationTime - PerformanceEntry.startTime.
  • PerformanceEntry.name
    • : The new URL navigated to.
  • PerformanceEntry.startTime
    • : Returns the DOMHighResTimeStamp of the interaction that resulted in the soft navigation.

Instance methods

  • PerformanceSoftNavigation.getLargestInteractionContentfulPaint()
    • : Returns the current largest InteractionContentfulPaint for this soft navigation.
  • PerformanceSoftNavigation.toJSON()
    • : Returns a JSON-serializable plain object representing the PerformanceSoftNavigation object. Automatically called by JSON.stringify().

Description

The PerformanceSoftNavigation interface is driven by the browser observing the following:

  • A trusted user interaction.
  • A visible, Contentful Paint as a result of that interaction updating the screen.
  • A URL update in the user's address bar as a result of that interaction.

Having the browser provide this rather than a routing framework calling an API to emit this entry allows SPA performance timing to be measured consistently regardless of how different applications handle navigations (for example, updating the URL at the start or the end of navigation processing).

The PerformanceSoftNavigation interface allows developers to measure SPA performance metrics such as:

  • First Contentful Paint: Can be measured as the first paint from the soft navigation time.
  • Largest Contentful Paint: Can be measured via the InteractionContentfulPaint for the soft navigation.
  • CLS: Can be calculated between navigations.
  • Interaction to Next Paint: Can be calculated between navigations.

Examples

Observing soft navigations

In the following example, a PerformanceObserver is used to log the soft navigations. The buffered flag is used to access data from before observer creation.

const observer = new PerformanceObserver((list) => {
  for (const entry of list.getEntries()) {
    console.log("Soft Nav:", entry.startTime, entry.name);
  }
});
observer.observe({ type: "soft-navigation", buffered: true });

Specifications

Browser compatibility

See also

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。