Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/integration-tests/utils/replayEventTemplates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const expectedLCPPerformanceSpan = {
startTimestamp: expect.any(Number),
endTimestamp: expect.any(Number),
data: {
duration: expect.any(Number),
value: expect.any(Number),
nodeId: expect.any(Number),
size: expect.any(Number),
},
Expand Down
20 changes: 16 additions & 4 deletions packages/replay/src/util/createPerformanceEntries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,29 @@ function createResourceEntry(entry: PerformanceResourceTiming) {
// TODO: type definition!
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
function createLargestContentfulPaint(entry: PerformanceEntry & { size: number; element: Node }) {
const { duration, entryType, startTime, size } = entry;
const { entryType, startTime, size } = entry;

const start = getAbsoluteTime(startTime);
let startTimeOrNavigationActivation = 0;

if (WINDOW.performance) {
const navEntry = WINDOW.performance.getEntriesByType('navigation')[0] as PerformanceNavigationTiming & {
activationStart: number;
};

// See https://github.com/GoogleChrome/web-vitals/blob/9f11c4c6578fb4c5ee6fa4e32b9d1d756475f135/src/lib/getActivationStart.ts#L21
startTimeOrNavigationActivation = (navEntry && navEntry.activationStart) || 0;
}

const start = getAbsoluteTime(startTimeOrNavigationActivation);
const value = Math.max(startTime - startTimeOrNavigationActivation, 0);

return {
type: entryType,
name: entryType,
start,
end: start + duration,
end: start + value,
data: {
duration,
value,
size,
// Not sure why this errors, Node should be correct (Argument of type 'Node' is not assignable to parameter of type 'INode')
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down