fingerprintjs
123 строки · 4.7 Кб
1import { loadSources, SourcesToComponents } from '../utils/entropy_source'
2import getAudioFingerprint from './audio'
3import getFonts from './fonts'
4import getPlugins from './plugins'
5import getCanvasFingerprint from './canvas'
6import getTouchSupport from './touch_support'
7import getOsCpu from './os_cpu'
8import getLanguages from './languages'
9import getColorDepth from './color_depth'
10import getDeviceMemory from './device_memory'
11import getScreenResolution from './screen_resolution'
12import getScreenFrame from './screen_frame'
13import getHardwareConcurrency from './hardware_concurrency'
14import getTimezone from './timezone'
15import getSessionStorage from './session_storage'
16import getLocalStorage from './local_storage'
17import getIndexedDB from './indexed_db'
18import getOpenDatabase from './open_database'
19import getCpuClass from './cpu_class'
20import getPlatform from './platform'
21import getVendor from './vendor'
22import getVendorFlavors from './vendor_flavors'
23import areCookiesEnabled from './cookies_enabled'
24import getDomBlockers from './dom_blockers'
25import getColorGamut from './color_gamut'
26import areColorsInverted from './inverted_colors'
27import areColorsForced from './forced_colors'
28import getMonochromeDepth from './monochrome'
29import getContrastPreference from './contrast'
30import isMotionReduced from './reduced_motion'
31import isTransparencyReduced from './reduced_transparency'
32import isHDR from './hdr'
33import getMathFingerprint from './math'
34import getFontPreferences from './font_preferences'
35import isPdfViewerEnabled from './pdf_viewer_enabled'
36import getArchitecture from './architecture'
37import getApplePayState from './apple_pay'
38import getPrivateClickMeasurement from './private_click_measurement'
39import { getWebGlBasics, getWebGlExtensions } from './webgl'
40
41/**
42* The list of entropy sources used to make visitor identifiers.
43*
44* This value isn't restricted by Semantic Versioning, i.e. it may be changed without bumping minor or major version of
45* this package.
46*
47* Note: Rollup and Webpack are smart enough to remove unused properties of this object during tree-shaking, so there is
48* no need to export the sources individually.
49*/
50export const sources = {
51// READ FIRST:
52// See https://github.com/fingerprintjs/fingerprintjs/blob/master/contributing.md#how-to-make-an-entropy-source
53// to learn how entropy source works and how to make your own.
54
55// The sources run in this exact order.
56// The asynchronous sources are at the start to run in parallel with other sources.
57fonts: getFonts,
58domBlockers: getDomBlockers,
59fontPreferences: getFontPreferences,
60audio: getAudioFingerprint,
61screenFrame: getScreenFrame,
62canvas: getCanvasFingerprint,
63
64osCpu: getOsCpu,
65languages: getLanguages,
66colorDepth: getColorDepth,
67deviceMemory: getDeviceMemory,
68screenResolution: getScreenResolution,
69hardwareConcurrency: getHardwareConcurrency,
70timezone: getTimezone,
71sessionStorage: getSessionStorage,
72localStorage: getLocalStorage,
73indexedDB: getIndexedDB,
74openDatabase: getOpenDatabase,
75cpuClass: getCpuClass,
76platform: getPlatform,
77plugins: getPlugins,
78touchSupport: getTouchSupport,
79vendor: getVendor,
80vendorFlavors: getVendorFlavors,
81cookiesEnabled: areCookiesEnabled,
82colorGamut: getColorGamut,
83invertedColors: areColorsInverted,
84forcedColors: areColorsForced,
85monochrome: getMonochromeDepth,
86contrast: getContrastPreference,
87reducedMotion: isMotionReduced,
88reducedTransparency: isTransparencyReduced,
89hdr: isHDR,
90math: getMathFingerprint,
91pdfViewerEnabled: isPdfViewerEnabled,
92architecture: getArchitecture,
93applePay: getApplePayState,
94privateClickMeasurement: getPrivateClickMeasurement,
95
96// Some sources can affect other sources (e.g. WebGL can affect canvas), so it's important to run these sources
97// after other sources.
98webGlBasics: getWebGlBasics,
99webGlExtensions: getWebGlExtensions,
100}
101
102/**
103* List of components from the built-in entropy sources.
104*
105* Warning! This type is out of Semantic Versioning, i.e. may have incompatible changes within a major version. If you
106* want to avoid breaking changes, use `UnknownComponents` instead that is more generic but guarantees backward
107* compatibility within a major version. This is because browsers change constantly and therefore entropy sources have
108* to change too.
109*/
110export type BuiltinComponents = SourcesToComponents<typeof sources>
111
112export interface BuiltinSourceOptions {
113debug?: boolean
114cache: Record<string, unknown>
115}
116
117/**
118* Loads the built-in entropy sources.
119* Returns a function that collects the entropy components to make the visitor identifier.
120*/
121export default function loadBuiltinSources(options: BuiltinSourceOptions): () => Promise<BuiltinComponents> {
122return loadSources(sources, options, [])
123}
124