PerformanceEntry: startTime property

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2017.

Note: This feature is available in Web Workers.

Thuộc tính chỉ đọc startTime trả về timestamp đầu tiên được ghi nhận cho PerformanceEntry này. Ý nghĩa của thuộc tính này phụ thuộc vào giá trị entryType của entry.

Giá trị

Một DOMHighResTimeStamp biểu thị timestamp đầu tiên khi PerformanceEntry được tạo.

Ý nghĩa của thuộc tính này phụ thuộc vào giá trị entryType của performance entry:

element

Hoặc là giá trị renderTime của entry này nếu nó khác 0, nếu không thì là giá trị loadTime của entry này.

event

Thời gian sự kiện được tạo, tức là thuộc tính timeStamp của sự kiện.

first-input

Thời gian sự kiện nhập đầu tiên được tạo, tức là thuộc tính timeStamp của sự kiện đó.

largest-contentful-paint

Giá trị renderTime của entry này nếu nó khác 0, nếu không thì là giá trị loadTime của entry này.

layout-shift

Thời điểm layout shift bắt đầu.

longtask

Thời điểm tác vụ bắt đầu.

mark

Thời điểm mark được tạo bằng lời gọi performance.mark().

measure

Thời điểm measure được tạo bằng lời gọi performance.measure().

Luôn là 0.

paint

Thời điểm paint xảy ra.

resource

Giá trị thuộc tính fetchStart của entry này.

taskattribution

Luôn là 0.

visibility-state

Thời điểm thay đổi trạng thái hiển thị xảy ra.

Ví dụ

Sử dụng thuộc tính startTime

Ví dụ sau cho thấy cách dùng thuộc tính startTime, bạn có thể ghi lại trong quá trình quan sát hiệu năng.

Lưu ý: phương thức performance.mark() cho phép bạn tự đặt startTime, và phương thức performance.measure() cho phép đặt điểm bắt đầu của phép đo.

js
performance.mark("my-mark");
performance.mark("my-other-mark", { startTime: 12.5 });

loginButton.addEventListener("click", (clickEvent) => {
  performance.measure("login-click", { start: clickEvent.timeStamp });
});

function perfObserver(list, observer) {
  list.getEntries().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}`);
    }
  });
}
const observer = new PerformanceObserver(perfObserver);
observer.observe({ entryTypes: ["measure", "mark"] });

Thông số kỹ thuật

Specification
Performance Timeline
# dom-performanceentry-starttime

Tương thích trình duyệt