Skip to content

Commit

Permalink
Actualize the isDesktopSafari function
Browse files Browse the repository at this point in the history
  • Loading branch information
Finesse committed Sep 19, 2023
1 parent 9705953 commit 286f98a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions playground/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
getDocumentFocus,
getMozAppearanceSupport,
isAndroid,
isDesktopSafari,
isDesktopWebKit,
} from '../src/utils/browser'
import './style.css'

Expand Down Expand Up @@ -43,7 +43,7 @@ const runDetection = async (): Promise<DetectionResult> => {
documentFocus: getDocumentFocus(),
mozAppearanceSupport: getMozAppearanceSupport(),
isAndroid: isAndroid(),
isDesktopSafari: isDesktopSafari(),
isDesktopWebKit: isDesktopWebKit(),
}

return {
Expand Down
11 changes: 7 additions & 4 deletions src/utils/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,21 @@ 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([
'safari' in w, // Always false in Karma and BrowserStack Automate
!('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
)
}
Expand Down

0 comments on commit 286f98a

Please sign in to comment.