From 87b128af2e63e9e404b88ccfec166a3d72f935c4 Mon Sep 17 00:00:00 2001 From: Griffin <60614863+h-griffin@users.noreply.github.com> Date: Thu, 5 Dec 2024 15:55:11 -0800 Subject: [PATCH] CRASH FIX- resolve origin domain data crash when FIP First Input Delay metric for percentile is undefined --- basic.js | 8 ++++---- index.js | 11 ++++------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/basic.js b/basic.js index d98b08f..aa5acf6 100644 --- a/basic.js +++ b/basic.js @@ -88,10 +88,10 @@ const getFieldData = async () => { ); // Otherwise Extract Origin Field metrics (if there are) - const fieldFCP = fieldMetrics.FIRST_CONTENTFUL_PAINT_MS.percentile; - const fieldFID = fieldMetrics.FIRST_INPUT_DELAY_MS.percentile; - const fieldLCP = fieldMetrics.LARGEST_CONTENTFUL_PAINT_MS.percentile; - const fieldCLS = fieldMetrics.CUMULATIVE_LAYOUT_SHIFT_SCORE.percentile; + const fieldFCP = fieldMetrics.FIRST_CONTENTFUL_PAINT_MS ? fieldMetrics.FIRST_CONTENTFUL_PAINT_MS.percentile : "FIRST_CONTENTFUL_PAINT_MS undefined"; + const fieldFID = fieldMetrics.FIRST_INPUT_DELAY_MS ? fieldMetrics.FIRST_INPUT_DELAY_MS.percentile : "FIRST_INPUT_DELAY_MS undefined"; + const fieldLCP = fieldMetrics.LARGEST_CONTENTFUL_PAINT_MS ? fieldMetrics.LARGEST_CONTENTFUL_PAINT_MS.percentile : "LARGEST_CONTENTFUL_PAINT_MS undefined"; + const fieldCLS = fieldMetrics.CUMULATIVE_LAYOUT_SHIFT_SCORE ? fieldMetrics.CUMULATIVE_LAYOUT_SHIFT_SCORE.percentile : "CUMULATIVE_LAYOUT_SHIFT_SCORE undefined"; // Construct fieldResult object const fieldResObj = { diff --git a/index.js b/index.js index a0b3460..9fb0790 100644 --- a/index.js +++ b/index.js @@ -109,13 +109,10 @@ const getSpeedData = async (testNum = 1) => { ); // Otherwise Extract Origin Field metrics (if there are) - const fieldFCP = - fieldMetrics.FIRST_CONTENTFUL_PAINT_MS.percentile; - const fieldFID = fieldMetrics.FIRST_INPUT_DELAY_MS.percentile; - const fieldLCP = - fieldMetrics.LARGEST_CONTENTFUL_PAINT_MS.percentile; - const fieldCLS = - fieldMetrics.CUMULATIVE_LAYOUT_SHIFT_SCORE.percentile; + const fieldFCP = fieldMetrics.FIRST_CONTENTFUL_PAINT_MS ? fieldMetrics.FIRST_CONTENTFUL_PAINT_MS.percentile : "FIRST_CONTENTFUL_PAINT_MS undefined"; + const fieldFID = fieldMetrics.FIRST_INPUT_DELAY_MS ? fieldMetrics.FIRST_INPUT_DELAY_MS.percentile : "FIRST_INPUT_DELAY_MS undefined"; + const fieldLCP = fieldMetrics.LARGEST_CONTENTFUL_PAINT_MS ? fieldMetrics.LARGEST_CONTENTFUL_PAINT_MS.percentile : "LARGEST_CONTENTFUL_PAINT_MS undefined"; + const fieldCLS = fieldMetrics.CUMULATIVE_LAYOUT_SHIFT_SCORE ? fieldMetrics.CUMULATIVE_LAYOUT_SHIFT_SCORE.percentile : "CUMULATIVE_LAYOUT_SHIFT_SCORE undefined"; // Construct fieldResult object const fieldResObj = {