From 286f98a754e2f417691bf6aeaf40e2200f35f673 Mon Sep 17 00:00:00 2001 From: Sergey M Date: Tue, 19 Sep 2023 11:20:14 +1000 Subject: [PATCH] Actualize the `isDesktopSafari` function --- playground/index.ts | 4 ++-- src/utils/browser.ts | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/playground/index.ts b/playground/index.ts index 15a50395..51d91aa5 100644 --- a/playground/index.ts +++ b/playground/index.ts @@ -5,7 +5,7 @@ import { getDocumentFocus, getMozAppearanceSupport, isAndroid, - isDesktopSafari, + isDesktopWebKit, } from '../src/utils/browser' import './style.css' @@ -43,7 +43,7 @@ const runDetection = async (): Promise => { documentFocus: getDocumentFocus(), mozAppearanceSupport: getMozAppearanceSupport(), isAndroid: isAndroid(), - isDesktopSafari: isDesktopSafari(), + isDesktopWebKit: isDesktopWebKit(), } return { diff --git a/src/utils/browser.ts b/src/utils/browser.ts index 8cbc1484..aefb336d 100644 --- a/src/utils/browser.ts +++ b/src/utils/browser.ts @@ -93,9 +93,12 @@ export function isAndroid(): boolean { ) } -// Source: https://github.com/fingerprintjs/fingerprintjs/blob/43a84516755440a89f3093a3b27a021d3d7351b6/src/utils/browser.ts#L100C1-L113C2 -export function isDesktopSafari(): boolean { +// Source: https://github.com/fingerprintjs/fingerprintjs/blob/109f8ef802169df3fa1c5d1baa4b7bc0abbc1d91/src/utils/browser.ts#L102C1-L118C2 +export function isDesktopWebKit(): boolean { + // Checked in Safari and DuckDuckGo + const w = window + const { HTMLElement, Document } = w return ( countTruthy([ @@ -103,8 +106,8 @@ export function isDesktopSafari(): boolean { !('ongestureend' in w), !('TouchEvent' in w), !('orientation' in w), - 'HTMLElement' in w && !('autocapitalize' in HTMLElement.prototype), - 'Document' in w && 'pointerLockElement' in Document.prototype, + HTMLElement && !('autocapitalize' in HTMLElement.prototype), + Document && 'pointerLockElement' in Document.prototype, ]) >= 4 ) }