1.下載方式
CDN: https://cdnjs.com/libraries/fingerprintjs2(這里查找最新CDN地址)
Bower: bower install fingerprintjs2
NPM: npm install fingerprintjs2
Yarn: yarn add fingerprintjs2
Github地址:https://github.com/Valve/fingerprintjs2
2.使用方式
總結自Github文檔
2.1默認方式
使用setTimeout 或requestIdleCallback 將其延遲幾毫秒以確保指紋一致,options 為自定義配置項,result 是計算出來的指紋ID,components 為計算指紋時所使用到的組件數組
if (window.requestIdleCallback) {
requestIdleCallback(function () {
//必須在v2.0語法提供options參數
Fingerprint2.getV18(options, function (result, components) {
console.log(result);//結果是哈希指紋
console.log(components);//組件是{key:'foo'的數組,值:'組件值'}
})
})
} else {
setTimeout(function () {
Fingerprint2.getV18(options, function (result, components) {
console.log(result);//結果是哈希指紋
console.log(components);//組件是{key:'foo'的數組,值:'組件值'}
})
}, 500)
}
如果使用get ,它不會對結果進行哈希處理,需手動使用murmur哈希函數(可替換成自定義的哈希函數)來創建哈希指紋
Fingerprint2.get(options,function (components) {
var values = components.map(function (component) { return component.value })
var murmur = Fingerprint2.x64hash128(values.join(''), 31)
})
2.2配置
2.2.1配置方式:
var options = {fonts: {extendedJsFonts: true}, excludes: {userAgent: true}}
2.2.2默認選項配置(源碼):
var defaultOptions = {
preprocessor: null,
audio: {
timeout: 1000,
// 在iOS 11上,音頻上下文只能用於響應用戶交互。我們要求用戶在iOS 11上顯式啟用音頻指紋https://stackoverflow.com/questions/46363048/onaudioprocess-not-called-on-ios11#46534088
excludeIOS11: true
},
fonts: {
swfContainerId: 'fingerprintjs2',
swfPath: 'flash/compiled/FontList.swf',
userDefinedFonts: [],
extendedJsFonts: false
},
screen: {
// 當用戶旋轉移動設備時確保指紋一致
detectScreenOrientation: true
},
plugins: {
sortPluginsFor: [/palemoon/i],
excludeIE: false
},
extraComponents: [],
excludes: {
// Unreliable on Windows, see https://github.com/Valve/fingerprintjs2/issues/375
'enumerateDevices': true,
// 取決於瀏覽器縮放
'pixelRatio': true,
//取決於某些瀏覽器的隱身模式
'doNotTrack': true,
// 已經使用JS字體
'fontsFlash': true
},
NOT_AVAILABLE: 'not available',
ERROR: 'error',
EXCLUDED: 'excluded'
}
2.2.3配置項涵義:
參考:
Excludes為{}時將包含即不會排除以下組件(源碼)
var components = [
{key: 'userAgent', getData: UserAgent},//用戶代理
{key: 'language', getData: languageKey},//語言種類
{key: 'colorDepth', getData: colorDepthKey},
//目標設備或緩沖器上的調色板的比特深度
{key: 'deviceMemory', getData: deviceMemoryKey},//設備內存
{key: 'pixelRatio', getData: pixelRatioKey},//設備像素比
{key: 'hardwareConcurrency', getData: hardwareConcurrencyKey},
//可用於運行在用戶的計算機上的線程的邏輯處理器的數量。
{key: 'screenResolution', getData: screenResolutionKey},
//當前屏幕分辨率
{key: 'availableScreenResolution', getData: availableScreenResolutionKey},//屏幕寬高(空白空間)
{key: 'timezoneOffset', getData: timezoneOffset},
//本地時間與 GMT 時間之間的時間差,以分鍾為單位
{key: 'timezone', getData: timezone},//時區
{key: 'sessionStorage', getData: sessionStorageKey},//是否會話存儲
{key: 'localStorage', getData: localStorageKey},//是否具有本地存儲 {key: 'indexedDb', getData: indexedDbKey},//是否具有索引DB
{key: 'addBehavior', getData: addBehaviorKey},//IE是否指定AddBehavior
{key: 'openDatabase', getData: openDatabaseKey},//是否有打開的DB
{key: 'cpuClass', getData: cpuClassKey},//瀏覽器系統的CPU等級
{key: 'platform', getData: platformKey},//運行瀏覽器的操作系統和(或)硬件平台
{key: 'doNotTrack', getData: doNotTrackKey},//do-not-track設置
{key: 'plugins', getData: pluginsComponent},//瀏覽器的插件信息
{key: 'canvas', getData: canvasKey},//使用 Canvas 繪圖
{key: 'webgl', getData: webglKey},//WebGL指紋信息
{key: 'webglVendorAndRenderer', getData: webglVendorAndRendererKey},//具有大量熵的WebGL指紋的子集
{key: 'adBlock', getData: adBlockKey},//是否安裝AdBlock
{key: 'hasLiedLanguages', getData: hasLiedLanguagesKey},
//用戶是否篡改了語言
{key: 'hasLiedResolution', getData: hasLiedResolutionKey},
//用戶是否篡改了屏幕分辨率
{key: 'hasLiedOs', getData: hasLiedOsKey},
//用戶是否篡改了操作系統
{key: 'hasLiedBrowser', getData: hasLiedBrowserKey},
//用戶是否篡改了瀏覽器
{key: 'touchSupport', getData: touchSupportKey},//觸摸屏檢測和能力
{key: 'fonts', getData: jsFontsKey, pauseBefore: true},
//使用JS/CSS檢測到的字體列表
{key: 'fontsFlash', getData: flashFontsKey, pauseBefore: true},
//已安裝的Flash字體列表
{key: 'audio', getData: audioKey},//音頻處理
{key: 'enumerateDevices', getData: enumerateDevicesKey}
//可用的多媒體輸入和輸出設備的信息。
]
原文鏈接:https://blog.csdn.net/qq_29169813/java/article/details/86672205
