From 1fe4f5eedffaad9a6e7a843e9de9d03b8959d1dd Mon Sep 17 00:00:00 2001 From: Philip Walton Date: Mon, 3 May 2021 18:27:50 -0700 Subject: [PATCH] Add more extensive FID feature detect --- src/lib/observe.ts | 6 ++++++ test/utils/browserSupportsEntry.js | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/lib/observe.ts b/src/lib/observe.ts index 0a48ec16..7c40e005 100644 --- a/src/lib/observe.ts +++ b/src/lib/observe.ts @@ -32,6 +32,12 @@ export const observe = ( ): PerformanceObserver | undefined => { try { if (PerformanceObserver.supportedEntryTypes.includes(type)) { + // More extensive feature detect needed for Firefox due to: + // https://github.com/GoogleChrome/web-vitals/issues/142 + if (type === 'first-input' && !('PerformanceEventTiming' in self)) { + return; + } + const po: PerformanceObserver = new PerformanceObserver((l) => l.getEntries().map(callback)); diff --git a/test/utils/browserSupportsEntry.js b/test/utils/browserSupportsEntry.js index ff7edca5..a212a945 100644 --- a/test/utils/browserSupportsEntry.js +++ b/test/utils/browserSupportsEntry.js @@ -22,6 +22,12 @@ */ function browserSupportsEntry(type) { return browser.execute((type) => { + // More extensive feature detect needed for Firefox due to: + // https://github.com/GoogleChrome/web-vitals/issues/142 + if (type === 'first-input' && !('PerformanceEventTiming' in window)) { + return false; + } + return window.PerformanceObserver && window.PerformanceObserver.supportedEntryTypes && window.PerformanceObserver.supportedEntryTypes.includes(type);