侦听HTML呈现过程事件

Listen for HTML rendering process events

本文关键字:过程 事件 HTML 侦听      更新时间:2023-09-26

我正在阅读一些关于渲染过程的文章:

https://developers.google.com/web/fundamentals/performance/http://www.sitepoint.com/optimizing-critical-rendering-path/

我希望能够倾听渲染过程中发生的步骤事件,能够知道浏览器何时开始(和完成)处理HTML文档,何时将css规则添加到CSSOM树,。。。

事实上,我正在寻找显示在devtools时间线中的信息,但以正式的格式。

我不认为有一个标准化的模型,但可能有一些浏览器允许监听这些事件。

您只需使用Navigation Timing API的readonly属性,IDL接口:

interface PerformanceTiming {
  readonly attribute unsigned long long navigationStart;
  readonly attribute unsigned long long unloadEventStart;
  readonly attribute unsigned long long unloadEventEnd;
  readonly attribute unsigned long long redirectStart;
  readonly attribute unsigned long long redirectEnd;
  readonly attribute unsigned long long fetchStart;
  readonly attribute unsigned long long domainLookupStart;
  readonly attribute unsigned long long domainLookupEnd;
  readonly attribute unsigned long long connectStart;
  readonly attribute unsigned long long connectEnd;
  readonly attribute unsigned long long secureConnectionStart;
  readonly attribute unsigned long long requestStart;
  readonly attribute unsigned long long responseStart;
  readonly attribute unsigned long long responseEnd;
  readonly attribute unsigned long long domLoading;
  readonly attribute unsigned long long domInteractive;
  readonly attribute unsigned long long domContentLoadedEventStart;
  readonly attribute unsigned long long domContentLoadedEventEnd;
  readonly attribute unsigned long long domComplete;
  readonly attribute unsigned long long loadEventStart;
  readonly attribute unsigned long long loadEventEnd;
};

它来自MDN的完整描述。

但是你听不到performance.timing对象的变化。