diff --git a/src/attribution/onFCP.ts b/src/attribution/onFCP.ts index 6c5bbd43..54f23110 100644 --- a/src/attribution/onFCP.ts +++ b/src/attribution/onFCP.ts @@ -17,7 +17,7 @@ import {getBFCacheRestoreTime} from '../lib/bfcache.js'; import {getLoadState} from '../lib/getLoadState.js'; import {getNavigationEntry} from '../lib/getNavigationEntry.js'; -import {invalidTiming} from '../lib/invalidTiming.js'; +import {isInvalidTimestamp} from '../lib/isInvalidTimestamp.js'; import {onFCP as unattributedOnFCP} from '../onFCP.js'; import { FCPMetric, @@ -34,7 +34,7 @@ const attributeFCP = (metric: FCPMetric): void => { if (navigationEntry) { const responseStart = navigationEntry.responseStart; - if (invalidTiming(responseStart)) return; + if (isInvalidTimestamp(responseStart)) return; const activationStart = navigationEntry.activationStart || 0; const ttfb = Math.max(0, responseStart - activationStart); diff --git a/src/attribution/onLCP.ts b/src/attribution/onLCP.ts index fc898de5..b546826b 100644 --- a/src/attribution/onLCP.ts +++ b/src/attribution/onLCP.ts @@ -16,7 +16,7 @@ import {getNavigationEntry} from '../lib/getNavigationEntry.js'; import {getSelector} from '../lib/getSelector.js'; -import {invalidTiming} from '../lib/invalidTiming.js'; +import {isInvalidTimestamp} from '../lib/isInvalidTimestamp.js'; import {onLCP as unattributedOnLCP} from '../onLCP.js'; import { LCPAttribution, @@ -33,7 +33,7 @@ const attributeLCP = (metric: LCPMetric) => { if (navigationEntry) { const responseStart = navigationEntry.responseStart; - if (invalidTiming(responseStart)) return; + if (isInvalidTimestamp(responseStart)) return; const activationStart = navigationEntry.activationStart || 0; const lcpEntry = metric.entries[metric.entries.length - 1]; diff --git a/src/lib/invalidTiming.ts b/src/lib/isInvalidTimestamp.ts similarity index 88% rename from src/lib/invalidTiming.ts rename to src/lib/isInvalidTimestamp.ts index 3decdb9b..4311cf71 100644 --- a/src/lib/invalidTiming.ts +++ b/src/lib/isInvalidTimestamp.ts @@ -14,12 +14,12 @@ * limitations under the License. */ -export const invalidTiming = (timing: number) => { +export const isInvalidTimestamp = (timestamp: DOMHighResTimeStamp) => { // In some cases no value is reported by the browser (for // privacy/security reasons), and in other cases (bugs) the value is // negative or is larger than the current page time. Ignore these cases: // https://github.com/GoogleChrome/web-vitals/issues/137 // https://github.com/GoogleChrome/web-vitals/issues/162 // https://github.com/GoogleChrome/web-vitals/issues/275 - return timing <= 0 || timing > performance.now(); + return timestamp <= 0 || timestamp > performance.now(); }; diff --git a/src/onTTFB.ts b/src/onTTFB.ts index dbab4448..5944bfb8 100644 --- a/src/onTTFB.ts +++ b/src/onTTFB.ts @@ -16,7 +16,7 @@ import {bindReporter} from './lib/bindReporter.js'; import {initMetric} from './lib/initMetric.js'; -import {invalidTiming} from './lib/invalidTiming.js'; +import {isInvalidTimestamp} from './lib/isInvalidTimestamp.js'; import {onBFCacheRestore} from './lib/bfcache.js'; import {getNavigationEntry} from './lib/getNavigationEntry.js'; import { @@ -78,7 +78,7 @@ export const onTTFB = (onReport: TTFBReportCallback, opts?: ReportOpts) => { if (navEntry) { const responseStart = navEntry.responseStart; - if (invalidTiming(responseStart)) return; + if (isInvalidTimestamp(responseStart)) return; // The activationStart reference is used because TTFB should be // relative to page activation rather than navigation start if the