Skip to content

feat(replay): Change LCP calculation #7187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 16, 2023
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