Skip to content

Commit

Permalink
Fix the cut logo in IE. Use an enum in the audio component. Change th…
Browse files Browse the repository at this point in the history
…e NPM description.
  • Loading branch information
Finesse committed Nov 17, 2020
1 parent d7cf89f commit 0e6f70d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "@fingerprintjs/fingerprintjs",
"description": "Modern & flexible browser fingerprinting library",
"description": "Browser fingerprinting library with the highest accuracy and stability",
"version": "3.0.3",
"keywords": [
"fraud",
Expand Down
2 changes: 1 addition & 1 deletion resources/logo.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 16 additions & 7 deletions src/sources/audio.ts
Expand Up @@ -3,24 +3,33 @@ import { isDesktopSafari, isWebKit, isWebKit606OrNewer } from '../utils/browser'
const w = window
const d = document

const enum SpecialFingerprint {
/** Making a fingerprint is skipped because the browser is known to always suspend audio context */
KnownToSuspend = -1,
/** The browser doesn't support audio context */
NotSupported = -2,
/** An unexpected timeout has happened */
Timeout = -3,
}

const enum InnerErrorName {
Timeout = 'timeout',
Suspended = 'suspended',
}

// Inspired by and based on https://github.com/cozylife/audio-fingerprint
export default async function getAudioFingerprint(): Promise<number> {
const AudioContext = w.OfflineAudioContext || w.webkitOfflineAudioContext
if (!AudioContext) {
return SpecialFingerprint.NotSupported
}

// In some browsers, audio context always stays suspended unless the context is started in response to a user action
// (e.g. a click or a tap). It prevents audio fingerprint from being taken at an arbitrary moment of time.
// Such browsers are old and unpopular, so the audio fingerprinting is just skipped in them.
// See a similar case explanation at https://stackoverflow.com/questions/46363048/onaudioprocess-not-called-on-ios11#46534088
if (doesCurrentBrowserSuspendAudioContext()) {
return -1
}

const AudioContext = w.OfflineAudioContext || w.webkitOfflineAudioContext
if (!AudioContext) {
return -2
return SpecialFingerprint.KnownToSuspend
}

const context = new AudioContext(1, 44100, 44100)
Expand All @@ -46,7 +55,7 @@ export default async function getAudioFingerprint(): Promise<number> {
buffer = await renderAudio(context)
} catch (error) {
if (error.name === InnerErrorName.Timeout || error.name === InnerErrorName.Suspended) {
return -3
return SpecialFingerprint.Timeout
}
throw error
} finally {
Expand Down

0 comments on commit 0e6f70d

Please sign in to comment.