Skip to content

Commit

Permalink
Add more extensive FID feature detect
Browse files Browse the repository at this point in the history
  • Loading branch information
philipwalton committed May 4, 2021
1 parent 9328925 commit 1fe4f5e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/lib/observe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
6 changes: 6 additions & 0 deletions test/utils/browserSupportsEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1fe4f5e

Please sign in to comment.