fingerprint2.js 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477
  1. /*
  2. * Fingerprintjs2 2.1.4 - Modern & flexible browser fingerprint library v2
  3. * https://github.com/fingerprintjs/fingerprintjs
  4. * Copyright (c) 2020 Valentin Vasilyev (valentin@fingerprintjs.com)
  5. * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
  6. *
  7. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  8. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  9. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  10. * ARE DISCLAIMED. IN NO EVENT SHALL VALENTIN VASILYEV BE LIABLE FOR ANY
  11. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  12. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  13. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  14. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  15. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  16. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  17. */
  18. /*
  19. * This software contains code from open-source projects:
  20. * MurmurHash3 by Karan Lyons (https://github.com/karanlyons/murmurHash3.js)
  21. */
  22. /* global define */
  23. (function (name, context, definition) {
  24. 'use strict'
  25. if (typeof window !== 'undefined' && typeof define === 'function' && define.amd) { define(definition) } else if (typeof module !== 'undefined' && module.exports) { module.exports = definition() } else if (context.exports) { context.exports = definition() } else { context[name] = definition() }
  26. })('Fingerprint2', this, function () {
  27. 'use strict'
  28. // detect if object is array
  29. // only implement if no native implementation is available
  30. if (typeof Array.isArray === 'undefined') {
  31. Array.isArray = function (obj) {
  32. return Object.prototype.toString.call(obj) === '[object Array]'
  33. }
  34. };
  35. /// MurmurHash3 related functions
  36. //
  37. // Given two 64bit ints (as an array of two 32bit ints) returns the two
  38. // added together as a 64bit int (as an array of two 32bit ints).
  39. //
  40. var x64Add = function (m, n) {
  41. m = [m[0] >>> 16, m[0] & 0xffff, m[1] >>> 16, m[1] & 0xffff]
  42. n = [n[0] >>> 16, n[0] & 0xffff, n[1] >>> 16, n[1] & 0xffff]
  43. var o = [0, 0, 0, 0]
  44. o[3] += m[3] + n[3]
  45. o[2] += o[3] >>> 16
  46. o[3] &= 0xffff
  47. o[2] += m[2] + n[2]
  48. o[1] += o[2] >>> 16
  49. o[2] &= 0xffff
  50. o[1] += m[1] + n[1]
  51. o[0] += o[1] >>> 16
  52. o[1] &= 0xffff
  53. o[0] += m[0] + n[0]
  54. o[0] &= 0xffff
  55. return [(o[0] << 16) | o[1], (o[2] << 16) | o[3]]
  56. }
  57. //
  58. // Given two 64bit ints (as an array of two 32bit ints) returns the two
  59. // multiplied together as a 64bit int (as an array of two 32bit ints).
  60. //
  61. var x64Multiply = function (m, n) {
  62. m = [m[0] >>> 16, m[0] & 0xffff, m[1] >>> 16, m[1] & 0xffff]
  63. n = [n[0] >>> 16, n[0] & 0xffff, n[1] >>> 16, n[1] & 0xffff]
  64. var o = [0, 0, 0, 0]
  65. o[3] += m[3] * n[3]
  66. o[2] += o[3] >>> 16
  67. o[3] &= 0xffff
  68. o[2] += m[2] * n[3]
  69. o[1] += o[2] >>> 16
  70. o[2] &= 0xffff
  71. o[2] += m[3] * n[2]
  72. o[1] += o[2] >>> 16
  73. o[2] &= 0xffff
  74. o[1] += m[1] * n[3]
  75. o[0] += o[1] >>> 16
  76. o[1] &= 0xffff
  77. o[1] += m[2] * n[2]
  78. o[0] += o[1] >>> 16
  79. o[1] &= 0xffff
  80. o[1] += m[3] * n[1]
  81. o[0] += o[1] >>> 16
  82. o[1] &= 0xffff
  83. o[0] += (m[0] * n[3]) + (m[1] * n[2]) + (m[2] * n[1]) + (m[3] * n[0])
  84. o[0] &= 0xffff
  85. return [(o[0] << 16) | o[1], (o[2] << 16) | o[3]]
  86. }
  87. //
  88. // Given a 64bit int (as an array of two 32bit ints) and an int
  89. // representing a number of bit positions, returns the 64bit int (as an
  90. // array of two 32bit ints) rotated left by that number of positions.
  91. //
  92. var x64Rotl = function (m, n) {
  93. n %= 64
  94. if (n === 32) {
  95. return [m[1], m[0]]
  96. } else if (n < 32) {
  97. return [(m[0] << n) | (m[1] >>> (32 - n)), (m[1] << n) | (m[0] >>> (32 - n))]
  98. } else {
  99. n -= 32
  100. return [(m[1] << n) | (m[0] >>> (32 - n)), (m[0] << n) | (m[1] >>> (32 - n))]
  101. }
  102. }
  103. //
  104. // Given a 64bit int (as an array of two 32bit ints) and an int
  105. // representing a number of bit positions, returns the 64bit int (as an
  106. // array of two 32bit ints) shifted left by that number of positions.
  107. //
  108. var x64LeftShift = function (m, n) {
  109. n %= 64
  110. if (n === 0) {
  111. return m
  112. } else if (n < 32) {
  113. return [(m[0] << n) | (m[1] >>> (32 - n)), m[1] << n]
  114. } else {
  115. return [m[1] << (n - 32), 0]
  116. }
  117. }
  118. //
  119. // Given two 64bit ints (as an array of two 32bit ints) returns the two
  120. // xored together as a 64bit int (as an array of two 32bit ints).
  121. //
  122. var x64Xor = function (m, n) {
  123. return [m[0] ^ n[0], m[1] ^ n[1]]
  124. }
  125. //
  126. // Given a block, returns murmurHash3's final x64 mix of that block.
  127. // (`[0, h[0] >>> 1]` is a 33 bit unsigned right shift. This is the
  128. // only place where we need to right shift 64bit ints.)
  129. //
  130. var x64Fmix = function (h) {
  131. h = x64Xor(h, [0, h[0] >>> 1])
  132. h = x64Multiply(h, [0xff51afd7, 0xed558ccd])
  133. h = x64Xor(h, [0, h[0] >>> 1])
  134. h = x64Multiply(h, [0xc4ceb9fe, 0x1a85ec53])
  135. h = x64Xor(h, [0, h[0] >>> 1])
  136. return h
  137. }
  138. //
  139. // Given a string and an optional seed as an int, returns a 128 bit
  140. // hash using the x64 flavor of MurmurHash3, as an unsigned hex.
  141. //
  142. var x64hash128 = function (key, seed) {
  143. key = key || ''
  144. seed = seed || 0
  145. var remainder = key.length % 16
  146. var bytes = key.length - remainder
  147. var h1 = [0, seed]
  148. var h2 = [0, seed]
  149. var k1 = [0, 0]
  150. var k2 = [0, 0]
  151. var c1 = [0x87c37b91, 0x114253d5]
  152. var c2 = [0x4cf5ad43, 0x2745937f]
  153. for (var i = 0; i < bytes; i = i + 16) {
  154. k1 = [((key.charCodeAt(i + 4) & 0xff)) | ((key.charCodeAt(i + 5) & 0xff) << 8) | ((key.charCodeAt(i + 6) & 0xff) << 16) | ((key.charCodeAt(i + 7) & 0xff) << 24), ((key.charCodeAt(i) & 0xff)) | ((key.charCodeAt(i + 1) & 0xff) << 8) | ((key.charCodeAt(i + 2) & 0xff) << 16) | ((key.charCodeAt(i + 3) & 0xff) << 24)]
  155. k2 = [((key.charCodeAt(i + 12) & 0xff)) | ((key.charCodeAt(i + 13) & 0xff) << 8) | ((key.charCodeAt(i + 14) & 0xff) << 16) | ((key.charCodeAt(i + 15) & 0xff) << 24), ((key.charCodeAt(i + 8) & 0xff)) | ((key.charCodeAt(i + 9) & 0xff) << 8) | ((key.charCodeAt(i + 10) & 0xff) << 16) | ((key.charCodeAt(i + 11) & 0xff) << 24)]
  156. k1 = x64Multiply(k1, c1)
  157. k1 = x64Rotl(k1, 31)
  158. k1 = x64Multiply(k1, c2)
  159. h1 = x64Xor(h1, k1)
  160. h1 = x64Rotl(h1, 27)
  161. h1 = x64Add(h1, h2)
  162. h1 = x64Add(x64Multiply(h1, [0, 5]), [0, 0x52dce729])
  163. k2 = x64Multiply(k2, c2)
  164. k2 = x64Rotl(k2, 33)
  165. k2 = x64Multiply(k2, c1)
  166. h2 = x64Xor(h2, k2)
  167. h2 = x64Rotl(h2, 31)
  168. h2 = x64Add(h2, h1)
  169. h2 = x64Add(x64Multiply(h2, [0, 5]), [0, 0x38495ab5])
  170. }
  171. k1 = [0, 0]
  172. k2 = [0, 0]
  173. switch (remainder) {
  174. case 15:
  175. k2 = x64Xor(k2, x64LeftShift([0, key.charCodeAt(i + 14)], 48))
  176. // fallthrough
  177. case 14:
  178. k2 = x64Xor(k2, x64LeftShift([0, key.charCodeAt(i + 13)], 40))
  179. // fallthrough
  180. case 13:
  181. k2 = x64Xor(k2, x64LeftShift([0, key.charCodeAt(i + 12)], 32))
  182. // fallthrough
  183. case 12:
  184. k2 = x64Xor(k2, x64LeftShift([0, key.charCodeAt(i + 11)], 24))
  185. // fallthrough
  186. case 11:
  187. k2 = x64Xor(k2, x64LeftShift([0, key.charCodeAt(i + 10)], 16))
  188. // fallthrough
  189. case 10:
  190. k2 = x64Xor(k2, x64LeftShift([0, key.charCodeAt(i + 9)], 8))
  191. // fallthrough
  192. case 9:
  193. k2 = x64Xor(k2, [0, key.charCodeAt(i + 8)])
  194. k2 = x64Multiply(k2, c2)
  195. k2 = x64Rotl(k2, 33)
  196. k2 = x64Multiply(k2, c1)
  197. h2 = x64Xor(h2, k2)
  198. // fallthrough
  199. case 8:
  200. k1 = x64Xor(k1, x64LeftShift([0, key.charCodeAt(i + 7)], 56))
  201. // fallthrough
  202. case 7:
  203. k1 = x64Xor(k1, x64LeftShift([0, key.charCodeAt(i + 6)], 48))
  204. // fallthrough
  205. case 6:
  206. k1 = x64Xor(k1, x64LeftShift([0, key.charCodeAt(i + 5)], 40))
  207. // fallthrough
  208. case 5:
  209. k1 = x64Xor(k1, x64LeftShift([0, key.charCodeAt(i + 4)], 32))
  210. // fallthrough
  211. case 4:
  212. k1 = x64Xor(k1, x64LeftShift([0, key.charCodeAt(i + 3)], 24))
  213. // fallthrough
  214. case 3:
  215. k1 = x64Xor(k1, x64LeftShift([0, key.charCodeAt(i + 2)], 16))
  216. // fallthrough
  217. case 2:
  218. k1 = x64Xor(k1, x64LeftShift([0, key.charCodeAt(i + 1)], 8))
  219. // fallthrough
  220. case 1:
  221. k1 = x64Xor(k1, [0, key.charCodeAt(i)])
  222. k1 = x64Multiply(k1, c1)
  223. k1 = x64Rotl(k1, 31)
  224. k1 = x64Multiply(k1, c2)
  225. h1 = x64Xor(h1, k1)
  226. // fallthrough
  227. }
  228. h1 = x64Xor(h1, [0, key.length])
  229. h2 = x64Xor(h2, [0, key.length])
  230. h1 = x64Add(h1, h2)
  231. h2 = x64Add(h2, h1)
  232. h1 = x64Fmix(h1)
  233. h2 = x64Fmix(h2)
  234. h1 = x64Add(h1, h2)
  235. h2 = x64Add(h2, h1)
  236. return ('00000000' + (h1[0] >>> 0).toString(16)).slice(-8) + ('00000000' + (h1[1] >>> 0).toString(16)).slice(-8) + ('00000000' + (h2[0] >>> 0).toString(16)).slice(-8) + ('00000000' + (h2[1] >>> 0).toString(16)).slice(-8)
  237. }
  238. var defaultOptions = {
  239. preprocessor: null,
  240. audio: {
  241. timeout: 1000,
  242. // On iOS 11, audio context can only be used in response to user interaction.
  243. // We require users to explicitly enable audio fingerprinting on iOS 11.
  244. // See https://stackoverflow.com/questions/46363048/onaudioprocess-not-called-on-ios11#46534088
  245. excludeIOS11: true
  246. },
  247. fonts: {
  248. swfContainerId: 'fingerprintjs2',
  249. swfPath: 'flash/compiled/FontList.swf',
  250. userDefinedFonts: [],
  251. extendedJsFonts: false
  252. },
  253. screen: {
  254. // To ensure consistent fingerprints when users rotate their mobile devices
  255. detectScreenOrientation: true
  256. },
  257. plugins: {
  258. sortPluginsFor: [/palemoon/i],
  259. excludeIE: false
  260. },
  261. extraComponents: [],
  262. excludes: {
  263. // Unreliable on Windows, see https://github.com/fingerprintjs/fingerprintjs/issues/375
  264. 'enumerateDevices': true,
  265. // devicePixelRatio depends on browser zoom, and it's impossible to detect browser zoom
  266. 'pixelRatio': true,
  267. // DNT depends on incognito mode for some browsers (Chrome) and it's impossible to detect incognito mode
  268. 'doNotTrack': true,
  269. // uses js fonts already
  270. 'fontsFlash': true,
  271. // Extensions (including AdBlock) are disabled by default in Incognito mod of Chrome and Firefox
  272. // See https://github.com/fingerprintjs/fingerprintjs/issues/405
  273. 'adBlock': true
  274. },
  275. NOT_AVAILABLE: 'not available',
  276. ERROR: 'error',
  277. EXCLUDED: 'excluded'
  278. }
  279. var each = function (obj, iterator) {
  280. if (Array.prototype.forEach && obj.forEach === Array.prototype.forEach) {
  281. obj.forEach(iterator)
  282. } else if (obj.length === +obj.length) {
  283. for (var i = 0, l = obj.length; i < l; i++) {
  284. iterator(obj[i], i, obj)
  285. }
  286. } else {
  287. for (var key in obj) {
  288. if (obj.hasOwnProperty(key)) {
  289. iterator(obj[key], key, obj)
  290. }
  291. }
  292. }
  293. }
  294. var map = function (obj, iterator) {
  295. var results = []
  296. // Not using strict equality so that this acts as a
  297. // shortcut to checking for `null` and `undefined`.
  298. if (obj == null) {
  299. return results
  300. }
  301. if (Array.prototype.map && obj.map === Array.prototype.map) { return obj.map(iterator) }
  302. each(obj, function (value, index, list) {
  303. results.push(iterator(value, index, list))
  304. })
  305. return results
  306. }
  307. var extendSoft = function (target, source) {
  308. if (source == null) { return target }
  309. var value
  310. var key
  311. for (key in source) {
  312. value = source[key]
  313. if (value != null && !(Object.prototype.hasOwnProperty.call(target, key))) {
  314. target[key] = value
  315. }
  316. }
  317. return target
  318. }
  319. // https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/enumerateDevices
  320. var enumerateDevicesKey = function (done, options) {
  321. if (!isEnumerateDevicesSupported()) {
  322. return done(options.NOT_AVAILABLE)
  323. }
  324. navigator.mediaDevices.enumerateDevices().then(function (devices) {
  325. done(devices.map(function (device) {
  326. return 'id=' + device.deviceId + ';gid=' + device.groupId + ';' + device.kind + ';' + device.label
  327. }))
  328. }).catch(function (error) {
  329. done(error)
  330. })
  331. }
  332. var isEnumerateDevicesSupported = function () {
  333. return (navigator.mediaDevices && navigator.mediaDevices.enumerateDevices)
  334. }
  335. // Inspired by and based on https://github.com/cozylife/audio-fingerprint
  336. var audioKey = function (done, options) {
  337. var audioOptions = options.audio
  338. if (audioOptions.excludeIOS11 && navigator.userAgent.match(/OS 11.+Version\/11.+Safari/)) {
  339. // See comment for excludeUserAgent and https://stackoverflow.com/questions/46363048/onaudioprocess-not-called-on-ios11#46534088
  340. return done(options.EXCLUDED)
  341. }
  342. var AudioContext = window.OfflineAudioContext || window.webkitOfflineAudioContext
  343. if (AudioContext == null) {
  344. return done(options.NOT_AVAILABLE)
  345. }
  346. var context = new AudioContext(1, 44100, 44100)
  347. var oscillator = context.createOscillator()
  348. oscillator.type = 'triangle'
  349. oscillator.frequency.setValueAtTime(10000, context.currentTime)
  350. var compressor = context.createDynamicsCompressor()
  351. each([
  352. ['threshold', -50],
  353. ['knee', 40],
  354. ['ratio', 12],
  355. ['reduction', -20],
  356. ['attack', 0],
  357. ['release', 0.25]
  358. ], function (item) {
  359. if (compressor[item[0]] !== undefined && typeof compressor[item[0]].setValueAtTime === 'function') {
  360. compressor[item[0]].setValueAtTime(item[1], context.currentTime)
  361. }
  362. })
  363. oscillator.connect(compressor)
  364. compressor.connect(context.destination)
  365. oscillator.start(0)
  366. context.startRendering()
  367. var audioTimeoutId = setTimeout(function () {
  368. console.warn('Audio fingerprint timed out. Please report bug at https://github.com/fingerprintjs/fingerprintjs with your user agent: "' + navigator.userAgent + '".')
  369. context.oncomplete = function () { }
  370. context = null
  371. return done('audioTimeout')
  372. }, audioOptions.timeout)
  373. context.oncomplete = function (event) {
  374. var fingerprint
  375. try {
  376. clearTimeout(audioTimeoutId)
  377. fingerprint = event.renderedBuffer.getChannelData(0)
  378. .slice(4500, 5000)
  379. .reduce(function (acc, val) { return acc + Math.abs(val) }, 0)
  380. .toString()
  381. oscillator.disconnect()
  382. compressor.disconnect()
  383. } catch (error) {
  384. done(error)
  385. return
  386. }
  387. done(fingerprint)
  388. }
  389. }
  390. var UserAgent = function (done) {
  391. done(navigator.userAgent)
  392. }
  393. var webdriver = function (done, options) {
  394. done(navigator.webdriver == null ? options.NOT_AVAILABLE : navigator.webdriver)
  395. }
  396. var languageKey = function (done, options) {
  397. done(navigator.language || navigator.userLanguage || navigator.browserLanguage || navigator.systemLanguage || options.NOT_AVAILABLE)
  398. }
  399. var colorDepthKey = function (done, options) {
  400. done(window.screen.colorDepth || options.NOT_AVAILABLE)
  401. }
  402. var deviceMemoryKey = function (done, options) {
  403. done(navigator.deviceMemory || options.NOT_AVAILABLE)
  404. }
  405. var pixelRatioKey = function (done, options) {
  406. done(window.devicePixelRatio || options.NOT_AVAILABLE)
  407. }
  408. var screenResolutionKey = function (done, options) {
  409. done(getScreenResolution(options))
  410. }
  411. var getScreenResolution = function (options) {
  412. var resolution = [window.screen.width, window.screen.height]
  413. if (options.screen.detectScreenOrientation) {
  414. resolution.sort().reverse()
  415. }
  416. return resolution
  417. }
  418. var availableScreenResolutionKey = function (done, options) {
  419. done(getAvailableScreenResolution(options))
  420. }
  421. var getAvailableScreenResolution = function (options) {
  422. if (window.screen.availWidth && window.screen.availHeight) {
  423. var available = [window.screen.availHeight, window.screen.availWidth]
  424. if (options.screen.detectScreenOrientation) {
  425. available.sort().reverse()
  426. }
  427. return available
  428. }
  429. // headless browsers
  430. return options.NOT_AVAILABLE
  431. }
  432. var timezoneOffset = function (done) {
  433. done(new Date().getTimezoneOffset())
  434. }
  435. var timezone = function (done, options) {
  436. if (window.Intl && window.Intl.DateTimeFormat) {
  437. done(new window.Intl.DateTimeFormat().resolvedOptions().timeZone || options.NOT_AVAILABLE)
  438. return
  439. }
  440. done(options.NOT_AVAILABLE)
  441. }
  442. var sessionStorageKey = function (done, options) {
  443. done(hasSessionStorage(options))
  444. }
  445. var localStorageKey = function (done, options) {
  446. done(hasLocalStorage(options))
  447. }
  448. var indexedDbKey = function (done, options) {
  449. done(hasIndexedDB(options))
  450. }
  451. var addBehaviorKey = function (done) {
  452. done(!!window.HTMLElement.prototype.addBehavior)
  453. }
  454. var openDatabaseKey = function (done) {
  455. done(!!window.openDatabase)
  456. }
  457. var cpuClassKey = function (done, options) {
  458. done(getNavigatorCpuClass(options))
  459. }
  460. var platformKey = function (done, options) {
  461. done(getNavigatorPlatform(options))
  462. }
  463. var doNotTrackKey = function (done, options) {
  464. done(getDoNotTrack(options))
  465. }
  466. var canvasKey = function (done, options) {
  467. if (isCanvasSupported()) {
  468. done(getCanvasFp(options))
  469. return
  470. }
  471. done(options.NOT_AVAILABLE)
  472. }
  473. var webglKey = function (done, options) {
  474. if (isWebGlSupported()) {
  475. done(getWebglFp())
  476. return
  477. }
  478. done(options.NOT_AVAILABLE)
  479. }
  480. var webglVendorAndRendererKey = function (done) {
  481. if (isWebGlSupported()) {
  482. done(getWebglVendorAndRenderer())
  483. return
  484. }
  485. done()
  486. }
  487. var adBlockKey = function (done) {
  488. done(getAdBlock())
  489. }
  490. var hasLiedLanguagesKey = function (done) {
  491. done(getHasLiedLanguages())
  492. }
  493. var hasLiedResolutionKey = function (done) {
  494. done(getHasLiedResolution())
  495. }
  496. var hasLiedOsKey = function (done) {
  497. done(getHasLiedOs())
  498. }
  499. var hasLiedBrowserKey = function (done) {
  500. done(getHasLiedBrowser())
  501. }
  502. // flash fonts (will increase fingerprinting time 20X to ~ 130-150ms)
  503. var flashFontsKey = function (done, options) {
  504. // we do flash if swfobject is loaded
  505. if (!hasSwfObjectLoaded()) {
  506. return done('swf object not loaded')
  507. }
  508. if (!hasMinFlashInstalled()) {
  509. return done('flash not installed')
  510. }
  511. if (!options.fonts.swfPath) {
  512. return done('missing options.fonts.swfPath')
  513. }
  514. loadSwfAndDetectFonts(function (fonts) {
  515. done(fonts)
  516. }, options)
  517. }
  518. // kudos to http://www.lalit.org/lab/javascript-css-font-detect/
  519. var jsFontsKey = function (done, options) {
  520. // a font will be compared against all the three default fonts.
  521. // and if it doesn't match all 3 then that font is not available.
  522. var baseFonts = ['monospace', 'sans-serif', 'serif']
  523. var fontList = [
  524. 'Andale Mono', 'Arial', 'Arial Black', 'Arial Hebrew', 'Arial MT', 'Arial Narrow', 'Arial Rounded MT Bold', 'Arial Unicode MS',
  525. 'Bitstream Vera Sans Mono', 'Book Antiqua', 'Bookman Old Style',
  526. 'Calibri', 'Cambria', 'Cambria Math', 'Century', 'Century Gothic', 'Century Schoolbook', 'Comic Sans', 'Comic Sans MS', 'Consolas', 'Courier', 'Courier New',
  527. 'Geneva', 'Georgia',
  528. 'Helvetica', 'Helvetica Neue',
  529. 'Impact',
  530. 'Lucida Bright', 'Lucida Calligraphy', 'Lucida Console', 'Lucida Fax', 'LUCIDA GRANDE', 'Lucida Handwriting', 'Lucida Sans', 'Lucida Sans Typewriter', 'Lucida Sans Unicode',
  531. 'Microsoft Sans Serif', 'Monaco', 'Monotype Corsiva', 'MS Gothic', 'MS Outlook', 'MS PGothic', 'MS Reference Sans Serif', 'MS Sans Serif', 'MS Serif', 'MYRIAD', 'MYRIAD PRO',
  532. 'Palatino', 'Palatino Linotype',
  533. 'Segoe Print', 'Segoe Script', 'Segoe UI', 'Segoe UI Light', 'Segoe UI Semibold', 'Segoe UI Symbol',
  534. 'Tahoma', 'Times', 'Times New Roman', 'Times New Roman PS', 'Trebuchet MS',
  535. 'Verdana', 'Wingdings', 'Wingdings 2', 'Wingdings 3'
  536. ]
  537. if (options.fonts.extendedJsFonts) {
  538. var extendedFontList = [
  539. 'Abadi MT Condensed Light', 'Academy Engraved LET', 'ADOBE CASLON PRO', 'Adobe Garamond', 'ADOBE GARAMOND PRO', 'Agency FB', 'Aharoni', 'Albertus Extra Bold', 'Albertus Medium', 'Algerian', 'Amazone BT', 'American Typewriter',
  540. 'American Typewriter Condensed', 'AmerType Md BT', 'Andalus', 'Angsana New', 'AngsanaUPC', 'Antique Olive', 'Aparajita', 'Apple Chancery', 'Apple Color Emoji', 'Apple SD Gothic Neo', 'Arabic Typesetting', 'ARCHER',
  541. 'ARNO PRO', 'Arrus BT', 'Aurora Cn BT', 'AvantGarde Bk BT', 'AvantGarde Md BT', 'AVENIR', 'Ayuthaya', 'Bandy', 'Bangla Sangam MN', 'Bank Gothic', 'BankGothic Md BT', 'Baskerville',
  542. 'Baskerville Old Face', 'Batang', 'BatangChe', 'Bauer Bodoni', 'Bauhaus 93', 'Bazooka', 'Bell MT', 'Bembo', 'Benguiat Bk BT', 'Berlin Sans FB', 'Berlin Sans FB Demi', 'Bernard MT Condensed', 'BernhardFashion BT', 'BernhardMod BT', 'Big Caslon', 'BinnerD',
  543. 'Blackadder ITC', 'BlairMdITC TT', 'Bodoni 72', 'Bodoni 72 Oldstyle', 'Bodoni 72 Smallcaps', 'Bodoni MT', 'Bodoni MT Black', 'Bodoni MT Condensed', 'Bodoni MT Poster Compressed',
  544. 'Bookshelf Symbol 7', 'Boulder', 'Bradley Hand', 'Bradley Hand ITC', 'Bremen Bd BT', 'Britannic Bold', 'Broadway', 'Browallia New', 'BrowalliaUPC', 'Brush Script MT', 'Californian FB', 'Calisto MT', 'Calligrapher', 'Candara',
  545. 'CaslonOpnface BT', 'Castellar', 'Centaur', 'Cezanne', 'CG Omega', 'CG Times', 'Chalkboard', 'Chalkboard SE', 'Chalkduster', 'Charlesworth', 'Charter Bd BT', 'Charter BT', 'Chaucer',
  546. 'ChelthmITC Bk BT', 'Chiller', 'Clarendon', 'Clarendon Condensed', 'CloisterBlack BT', 'Cochin', 'Colonna MT', 'Constantia', 'Cooper Black', 'Copperplate', 'Copperplate Gothic', 'Copperplate Gothic Bold',
  547. 'Copperplate Gothic Light', 'CopperplGoth Bd BT', 'Corbel', 'Cordia New', 'CordiaUPC', 'Cornerstone', 'Coronet', 'Cuckoo', 'Curlz MT', 'DaunPenh', 'Dauphin', 'David', 'DB LCD Temp', 'DELICIOUS', 'Denmark',
  548. 'DFKai-SB', 'Didot', 'DilleniaUPC', 'DIN', 'DokChampa', 'Dotum', 'DotumChe', 'Ebrima', 'Edwardian Script ITC', 'Elephant', 'English 111 Vivace BT', 'Engravers MT', 'EngraversGothic BT', 'Eras Bold ITC', 'Eras Demi ITC', 'Eras Light ITC', 'Eras Medium ITC',
  549. 'EucrosiaUPC', 'Euphemia', 'Euphemia UCAS', 'EUROSTILE', 'Exotc350 Bd BT', 'FangSong', 'Felix Titling', 'Fixedsys', 'FONTIN', 'Footlight MT Light', 'Forte',
  550. 'FrankRuehl', 'Fransiscan', 'Freefrm721 Blk BT', 'FreesiaUPC', 'Freestyle Script', 'French Script MT', 'FrnkGothITC Bk BT', 'Fruitger', 'FRUTIGER',
  551. 'Futura', 'Futura Bk BT', 'Futura Lt BT', 'Futura Md BT', 'Futura ZBlk BT', 'FuturaBlack BT', 'Gabriola', 'Galliard BT', 'Gautami', 'Geeza Pro', 'Geometr231 BT', 'Geometr231 Hv BT', 'Geometr231 Lt BT', 'GeoSlab 703 Lt BT',
  552. 'GeoSlab 703 XBd BT', 'Gigi', 'Gill Sans', 'Gill Sans MT', 'Gill Sans MT Condensed', 'Gill Sans MT Ext Condensed Bold', 'Gill Sans Ultra Bold', 'Gill Sans Ultra Bold Condensed', 'Gisha', 'Gloucester MT Extra Condensed', 'GOTHAM', 'GOTHAM BOLD',
  553. 'Goudy Old Style', 'Goudy Stout', 'GoudyHandtooled BT', 'GoudyOLSt BT', 'Gujarati Sangam MN', 'Gulim', 'GulimChe', 'Gungsuh', 'GungsuhChe', 'Gurmukhi MN', 'Haettenschweiler', 'Harlow Solid Italic', 'Harrington', 'Heather', 'Heiti SC', 'Heiti TC', 'HELV',
  554. 'Herald', 'High Tower Text', 'Hiragino Kaku Gothic ProN', 'Hiragino Mincho ProN', 'Hoefler Text', 'Humanst 521 Cn BT', 'Humanst521 BT', 'Humanst521 Lt BT', 'Imprint MT Shadow', 'Incised901 Bd BT', 'Incised901 BT',
  555. 'Incised901 Lt BT', 'INCONSOLATA', 'Informal Roman', 'Informal011 BT', 'INTERSTATE', 'IrisUPC', 'Iskoola Pota', 'JasmineUPC', 'Jazz LET', 'Jenson', 'Jester', 'Jokerman', 'Juice ITC', 'Kabel Bk BT', 'Kabel Ult BT', 'Kailasa', 'KaiTi', 'Kalinga', 'Kannada Sangam MN',
  556. 'Kartika', 'Kaufmann Bd BT', 'Kaufmann BT', 'Khmer UI', 'KodchiangUPC', 'Kokila', 'Korinna BT', 'Kristen ITC', 'Krungthep', 'Kunstler Script', 'Lao UI', 'Latha', 'Leelawadee', 'Letter Gothic', 'Levenim MT', 'LilyUPC', 'Lithograph', 'Lithograph Light', 'Long Island',
  557. 'Lydian BT', 'Magneto', 'Maiandra GD', 'Malayalam Sangam MN', 'Malgun Gothic',
  558. 'Mangal', 'Marigold', 'Marion', 'Marker Felt', 'Market', 'Marlett', 'Matisse ITC', 'Matura MT Script Capitals', 'Meiryo', 'Meiryo UI', 'Microsoft Himalaya', 'Microsoft JhengHei', 'Microsoft New Tai Lue', 'Microsoft PhagsPa', 'Microsoft Tai Le',
  559. 'Microsoft Uighur', 'Microsoft YaHei', 'Microsoft Yi Baiti', 'MingLiU', 'MingLiU_HKSCS', 'MingLiU_HKSCS-ExtB', 'MingLiU-ExtB', 'Minion', 'Minion Pro', 'Miriam', 'Miriam Fixed', 'Mistral', 'Modern', 'Modern No. 20', 'Mona Lisa Solid ITC TT', 'Mongolian Baiti',
  560. 'MONO', 'MoolBoran', 'Mrs Eaves', 'MS LineDraw', 'MS Mincho', 'MS PMincho', 'MS Reference Specialty', 'MS UI Gothic', 'MT Extra', 'MUSEO', 'MV Boli',
  561. 'Nadeem', 'Narkisim', 'NEVIS', 'News Gothic', 'News GothicMT', 'NewsGoth BT', 'Niagara Engraved', 'Niagara Solid', 'Noteworthy', 'NSimSun', 'Nyala', 'OCR A Extended', 'Old Century', 'Old English Text MT', 'Onyx', 'Onyx BT', 'OPTIMA', 'Oriya Sangam MN',
  562. 'OSAKA', 'OzHandicraft BT', 'Palace Script MT', 'Papyrus', 'Parchment', 'Party LET', 'Pegasus', 'Perpetua', 'Perpetua Titling MT', 'PetitaBold', 'Pickwick', 'Plantagenet Cherokee', 'Playbill', 'PMingLiU', 'PMingLiU-ExtB',
  563. 'Poor Richard', 'Poster', 'PosterBodoni BT', 'PRINCETOWN LET', 'Pristina', 'PTBarnum BT', 'Pythagoras', 'Raavi', 'Rage Italic', 'Ravie', 'Ribbon131 Bd BT', 'Rockwell', 'Rockwell Condensed', 'Rockwell Extra Bold', 'Rod', 'Roman', 'Sakkal Majalla',
  564. 'Santa Fe LET', 'Savoye LET', 'Sceptre', 'Script', 'Script MT Bold', 'SCRIPTINA', 'Serifa', 'Serifa BT', 'Serifa Th BT', 'ShelleyVolante BT', 'Sherwood',
  565. 'Shonar Bangla', 'Showcard Gothic', 'Shruti', 'Signboard', 'SILKSCREEN', 'SimHei', 'Simplified Arabic', 'Simplified Arabic Fixed', 'SimSun', 'SimSun-ExtB', 'Sinhala Sangam MN', 'Sketch Rockwell', 'Skia', 'Small Fonts', 'Snap ITC', 'Snell Roundhand', 'Socket',
  566. 'Souvenir Lt BT', 'Staccato222 BT', 'Steamer', 'Stencil', 'Storybook', 'Styllo', 'Subway', 'Swis721 BlkEx BT', 'Swiss911 XCm BT', 'Sylfaen', 'Synchro LET', 'System', 'Tamil Sangam MN', 'Technical', 'Teletype', 'Telugu Sangam MN', 'Tempus Sans ITC',
  567. 'Terminal', 'Thonburi', 'Traditional Arabic', 'Trajan', 'TRAJAN PRO', 'Tristan', 'Tubular', 'Tunga', 'Tw Cen MT', 'Tw Cen MT Condensed', 'Tw Cen MT Condensed Extra Bold',
  568. 'TypoUpright BT', 'Unicorn', 'Univers', 'Univers CE 55 Medium', 'Univers Condensed', 'Utsaah', 'Vagabond', 'Vani', 'Vijaya', 'Viner Hand ITC', 'VisualUI', 'Vivaldi', 'Vladimir Script', 'Vrinda', 'Westminster', 'WHITNEY', 'Wide Latin',
  569. 'ZapfEllipt BT', 'ZapfHumnst BT', 'ZapfHumnst Dm BT', 'Zapfino', 'Zurich BlkEx BT', 'Zurich Ex BT', 'ZWAdobeF']
  570. fontList = fontList.concat(extendedFontList)
  571. }
  572. fontList = fontList.concat(options.fonts.userDefinedFonts)
  573. // remove duplicate fonts
  574. fontList = fontList.filter(function (font, position) {
  575. return fontList.indexOf(font) === position
  576. })
  577. // we use m or w because these two characters take up the maximum width.
  578. // And we use a LLi so that the same matching fonts can get separated
  579. var testString = 'mmmmmmmmmmlli'
  580. // we test using 72px font size, we may use any size. I guess larger the better.
  581. var testSize = '72px'
  582. var h = document.getElementsByTagName('body')[0]
  583. // div to load spans for the base fonts
  584. var baseFontsDiv = document.createElement('div')
  585. // div to load spans for the fonts to detect
  586. var fontsDiv = document.createElement('div')
  587. var defaultWidth = {}
  588. var defaultHeight = {}
  589. // creates a span where the fonts will be loaded
  590. var createSpan = function () {
  591. var s = document.createElement('span')
  592. /*
  593. * We need this css as in some weird browser this
  594. * span elements shows up for a microSec which creates a
  595. * bad user experience
  596. */
  597. s.style.position = 'absolute'
  598. s.style.left = '-9999px'
  599. s.style.fontSize = testSize
  600. // css font reset to reset external styles
  601. s.style.fontStyle = 'normal'
  602. s.style.fontWeight = 'normal'
  603. s.style.letterSpacing = 'normal'
  604. s.style.lineBreak = 'auto'
  605. s.style.lineHeight = 'normal'
  606. s.style.textTransform = 'none'
  607. s.style.textAlign = 'left'
  608. s.style.textDecoration = 'none'
  609. s.style.textShadow = 'none'
  610. s.style.whiteSpace = 'normal'
  611. s.style.wordBreak = 'normal'
  612. s.style.wordSpacing = 'normal'
  613. s.innerHTML = testString
  614. return s
  615. }
  616. // creates a span and load the font to detect and a base font for fallback
  617. var createSpanWithFonts = function (fontToDetect, baseFont) {
  618. var s = createSpan()
  619. s.style.fontFamily = "'" + fontToDetect + "'," + baseFont
  620. return s
  621. }
  622. // creates spans for the base fonts and adds them to baseFontsDiv
  623. var initializeBaseFontsSpans = function () {
  624. var spans = []
  625. for (var index = 0, length = baseFonts.length; index < length; index++) {
  626. var s = createSpan()
  627. s.style.fontFamily = baseFonts[index]
  628. baseFontsDiv.appendChild(s)
  629. spans.push(s)
  630. }
  631. return spans
  632. }
  633. // creates spans for the fonts to detect and adds them to fontsDiv
  634. var initializeFontsSpans = function () {
  635. var spans = {}
  636. for (var i = 0, l = fontList.length; i < l; i++) {
  637. var fontSpans = []
  638. for (var j = 0, numDefaultFonts = baseFonts.length; j < numDefaultFonts; j++) {
  639. var s = createSpanWithFonts(fontList[i], baseFonts[j])
  640. fontsDiv.appendChild(s)
  641. fontSpans.push(s)
  642. }
  643. spans[fontList[i]] = fontSpans // Stores {fontName : [spans for that font]}
  644. }
  645. return spans
  646. }
  647. // checks if a font is available
  648. var isFontAvailable = function (fontSpans) {
  649. var detected = false
  650. for (var i = 0; i < baseFonts.length; i++) {
  651. detected = (fontSpans[i].offsetWidth !== defaultWidth[baseFonts[i]] || fontSpans[i].offsetHeight !== defaultHeight[baseFonts[i]])
  652. if (detected) {
  653. return detected
  654. }
  655. }
  656. return detected
  657. }
  658. // create spans for base fonts
  659. var baseFontsSpans = initializeBaseFontsSpans()
  660. // add the spans to the DOM
  661. h.appendChild(baseFontsDiv)
  662. // get the default width for the three base fonts
  663. for (var index = 0, length = baseFonts.length; index < length; index++) {
  664. defaultWidth[baseFonts[index]] = baseFontsSpans[index].offsetWidth // width for the default font
  665. defaultHeight[baseFonts[index]] = baseFontsSpans[index].offsetHeight // height for the default font
  666. }
  667. // create spans for fonts to detect
  668. var fontsSpans = initializeFontsSpans()
  669. // add all the spans to the DOM
  670. h.appendChild(fontsDiv)
  671. // check available fonts
  672. var available = []
  673. for (var i = 0, l = fontList.length; i < l; i++) {
  674. if (isFontAvailable(fontsSpans[fontList[i]])) {
  675. available.push(fontList[i])
  676. }
  677. }
  678. // remove spans from DOM
  679. h.removeChild(fontsDiv)
  680. h.removeChild(baseFontsDiv)
  681. done(available)
  682. }
  683. var pluginsComponent = function (done, options) {
  684. if (isIE()) {
  685. if (!options.plugins.excludeIE) {
  686. done(getIEPlugins(options))
  687. } else {
  688. done(options.EXCLUDED)
  689. }
  690. } else {
  691. done(getRegularPlugins(options))
  692. }
  693. }
  694. var getRegularPlugins = function (options) {
  695. if (navigator.plugins == null) {
  696. return options.NOT_AVAILABLE
  697. }
  698. var plugins = []
  699. // plugins isn't defined in Node envs.
  700. for (var i = 0, l = navigator.plugins.length; i < l; i++) {
  701. if (navigator.plugins[i]) { plugins.push(navigator.plugins[i]) }
  702. }
  703. // sorting plugins only for those user agents, that we know randomize the plugins
  704. // every time we try to enumerate them
  705. if (pluginsShouldBeSorted(options)) {
  706. plugins = plugins.sort(function (a, b) {
  707. if (a.name > b.name) { return 1 }
  708. if (a.name < b.name) { return -1 }
  709. return 0
  710. })
  711. }
  712. return map(plugins, function (p) {
  713. var mimeTypes = map(p, function (mt) {
  714. return [mt.type, mt.suffixes]
  715. })
  716. return [p.name, p.description, mimeTypes]
  717. })
  718. }
  719. var getIEPlugins = function (options) {
  720. var result = []
  721. if ((Object.getOwnPropertyDescriptor && Object.getOwnPropertyDescriptor(window, 'ActiveXObject')) || ('ActiveXObject' in window)) {
  722. var names = [
  723. 'AcroPDF.PDF', // Adobe PDF reader 7+
  724. 'Adodb.Stream',
  725. 'AgControl.AgControl', // Silverlight
  726. 'DevalVRXCtrl.DevalVRXCtrl.1',
  727. 'MacromediaFlashPaper.MacromediaFlashPaper',
  728. 'Msxml2.DOMDocument',
  729. 'Msxml2.XMLHTTP',
  730. 'PDF.PdfCtrl', // Adobe PDF reader 6 and earlier, brrr
  731. 'QuickTime.QuickTime', // QuickTime
  732. 'QuickTimeCheckObject.QuickTimeCheck.1',
  733. 'RealPlayer',
  734. 'RealPlayer.RealPlayer(tm) ActiveX Control (32-bit)',
  735. 'RealVideo.RealVideo(tm) ActiveX Control (32-bit)',
  736. 'Scripting.Dictionary',
  737. 'SWCtl.SWCtl', // ShockWave player
  738. 'Shell.UIHelper',
  739. 'ShockwaveFlash.ShockwaveFlash', // flash plugin
  740. 'Skype.Detection',
  741. 'TDCCtl.TDCCtl',
  742. 'WMPlayer.OCX', // Windows media player
  743. 'rmocx.RealPlayer G2 Control',
  744. 'rmocx.RealPlayer G2 Control.1'
  745. ]
  746. // starting to detect plugins in IE
  747. result = map(names, function (name) {
  748. try {
  749. // eslint-disable-next-line no-new
  750. new window.ActiveXObject(name)
  751. return name
  752. } catch (e) {
  753. return options.ERROR
  754. }
  755. })
  756. } else {
  757. result.push(options.NOT_AVAILABLE)
  758. }
  759. if (navigator.plugins) {
  760. result = result.concat(getRegularPlugins(options))
  761. }
  762. return result
  763. }
  764. var pluginsShouldBeSorted = function (options) {
  765. var should = false
  766. for (var i = 0, l = options.plugins.sortPluginsFor.length; i < l; i++) {
  767. var re = options.plugins.sortPluginsFor[i]
  768. if (navigator.userAgent.match(re)) {
  769. should = true
  770. break
  771. }
  772. }
  773. return should
  774. }
  775. var touchSupportKey = function (done) {
  776. done(getTouchSupport())
  777. }
  778. var hardwareConcurrencyKey = function (done, options) {
  779. done(getHardwareConcurrency(options))
  780. }
  781. var hasSessionStorage = function (options) {
  782. try {
  783. return !!window.sessionStorage
  784. } catch (e) {
  785. return options.ERROR // SecurityError when referencing it means it exists
  786. }
  787. }
  788. // https://bugzilla.mozilla.org/show_bug.cgi?id=781447
  789. var hasLocalStorage = function (options) {
  790. try {
  791. return !!window.localStorage
  792. } catch (e) {
  793. return options.ERROR // SecurityError when referencing it means it exists
  794. }
  795. }
  796. var hasIndexedDB = function (options) {
  797. // IE and Edge don't allow accessing indexedDB in private mode, therefore IE and Edge will have different
  798. // fingerprints in normal and private modes.
  799. if (isIEOrOldEdge()) {
  800. return options.EXCLUDED
  801. }
  802. try {
  803. return !!window.indexedDB
  804. } catch (e) {
  805. return options.ERROR // SecurityError when referencing it means it exists
  806. }
  807. }
  808. var getHardwareConcurrency = function (options) {
  809. if (navigator.hardwareConcurrency) {
  810. return navigator.hardwareConcurrency
  811. }
  812. return options.NOT_AVAILABLE
  813. }
  814. var getNavigatorCpuClass = function (options) {
  815. return navigator.cpuClass || options.NOT_AVAILABLE
  816. }
  817. var getNavigatorPlatform = function (options) {
  818. if (navigator.platform) {
  819. return navigator.platform
  820. } else {
  821. return options.NOT_AVAILABLE
  822. }
  823. }
  824. var getDoNotTrack = function (options) {
  825. if (navigator.doNotTrack) {
  826. return navigator.doNotTrack
  827. } else if (navigator.msDoNotTrack) {
  828. return navigator.msDoNotTrack
  829. } else if (window.doNotTrack) {
  830. return window.doNotTrack
  831. } else {
  832. return options.NOT_AVAILABLE
  833. }
  834. }
  835. // This is a crude and primitive touch screen detection.
  836. // It's not possible to currently reliably detect the availability of a touch screen
  837. // with a JS, without actually subscribing to a touch event.
  838. // http://www.stucox.com/blog/you-cant-detect-a-touchscreen/
  839. // https://github.com/Modernizr/Modernizr/issues/548
  840. // method returns an array of 3 values:
  841. // maxTouchPoints, the success or failure of creating a TouchEvent,
  842. // and the availability of the 'ontouchstart' property
  843. var getTouchSupport = function () {
  844. var maxTouchPoints = 0
  845. var touchEvent
  846. if (typeof navigator.maxTouchPoints !== 'undefined') {
  847. maxTouchPoints = navigator.maxTouchPoints
  848. } else if (typeof navigator.msMaxTouchPoints !== 'undefined') {
  849. maxTouchPoints = navigator.msMaxTouchPoints
  850. }
  851. try {
  852. document.createEvent('TouchEvent')
  853. touchEvent = true
  854. } catch (_) {
  855. touchEvent = false
  856. }
  857. var touchStart = 'ontouchstart' in window
  858. return [maxTouchPoints, touchEvent, touchStart]
  859. }
  860. // https://www.browserleaks.com/canvas#how-does-it-work
  861. var getCanvasFp = function (options) {
  862. var result = []
  863. // Very simple now, need to make it more complex (geo shapes etc)
  864. var canvas = document.createElement('canvas')
  865. canvas.width = 2000
  866. canvas.height = 200
  867. canvas.style.display = 'inline'
  868. var ctx = canvas.getContext('2d')
  869. // detect browser support of canvas winding
  870. // http://blogs.adobe.com/webplatform/2013/01/30/winding-rules-in-canvas/
  871. // https://github.com/Modernizr/Modernizr/blob/master/feature-detects/canvas/winding.js
  872. ctx.rect(0, 0, 10, 10)
  873. ctx.rect(2, 2, 6, 6)
  874. result.push('canvas winding:' + ((ctx.isPointInPath(5, 5, 'evenodd') === false) ? 'yes' : 'no'))
  875. ctx.textBaseline = 'alphabetic'
  876. ctx.fillStyle = '#f60'
  877. ctx.fillRect(125, 1, 62, 20)
  878. ctx.fillStyle = '#069'
  879. // https://github.com/fingerprintjs/fingerprintjs/issues/66
  880. if (options.dontUseFakeFontInCanvas) {
  881. ctx.font = '11pt Arial'
  882. } else {
  883. ctx.font = '11pt no-real-font-123'
  884. }
  885. ctx.fillText('Cwm fjordbank glyphs vext quiz, \ud83d\ude03', 2, 15)
  886. ctx.fillStyle = 'rgba(102, 204, 0, 0.2)'
  887. ctx.font = '18pt Arial'
  888. ctx.fillText('Cwm fjordbank glyphs vext quiz, \ud83d\ude03', 4, 45)
  889. // canvas blending
  890. // http://blogs.adobe.com/webplatform/2013/01/28/blending-features-in-canvas/
  891. // http://jsfiddle.net/NDYV8/16/
  892. ctx.globalCompositeOperation = 'multiply'
  893. ctx.fillStyle = 'rgb(255,0,255)'
  894. ctx.beginPath()
  895. ctx.arc(50, 50, 50, 0, Math.PI * 2, true)
  896. ctx.closePath()
  897. ctx.fill()
  898. ctx.fillStyle = 'rgb(0,255,255)'
  899. ctx.beginPath()
  900. ctx.arc(100, 50, 50, 0, Math.PI * 2, true)
  901. ctx.closePath()
  902. ctx.fill()
  903. ctx.fillStyle = 'rgb(255,255,0)'
  904. ctx.beginPath()
  905. ctx.arc(75, 100, 50, 0, Math.PI * 2, true)
  906. ctx.closePath()
  907. ctx.fill()
  908. ctx.fillStyle = 'rgb(255,0,255)'
  909. // canvas winding
  910. // http://blogs.adobe.com/webplatform/2013/01/30/winding-rules-in-canvas/
  911. // http://jsfiddle.net/NDYV8/19/
  912. ctx.arc(75, 75, 75, 0, Math.PI * 2, true)
  913. ctx.arc(75, 75, 25, 0, Math.PI * 2, true)
  914. ctx.fill('evenodd')
  915. if (canvas.toDataURL) { result.push('canvas fp:' + canvas.toDataURL()) }
  916. return result
  917. }
  918. var getWebglFp = function () {
  919. var gl
  920. var fa2s = function (fa) {
  921. gl.clearColor(0.0, 0.0, 0.0, 1.0)
  922. gl.enable(gl.DEPTH_TEST)
  923. gl.depthFunc(gl.LEQUAL)
  924. gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
  925. return '[' + fa[0] + ', ' + fa[1] + ']'
  926. }
  927. var maxAnisotropy = function (gl) {
  928. var ext = gl.getExtension('EXT_texture_filter_anisotropic') || gl.getExtension('WEBKIT_EXT_texture_filter_anisotropic') || gl.getExtension('MOZ_EXT_texture_filter_anisotropic')
  929. if (ext) {
  930. var anisotropy = gl.getParameter(ext.MAX_TEXTURE_MAX_ANISOTROPY_EXT)
  931. if (anisotropy === 0) {
  932. anisotropy = 2
  933. }
  934. return anisotropy
  935. } else {
  936. return null
  937. }
  938. }
  939. gl = getWebglCanvas()
  940. if (!gl) { return null }
  941. // WebGL fingerprinting is a combination of techniques, found in MaxMind antifraud script & Augur fingerprinting.
  942. // First it draws a gradient object with shaders and convers the image to the Base64 string.
  943. // Then it enumerates all WebGL extensions & capabilities and appends them to the Base64 string, resulting in a huge WebGL string, potentially very unique on each device
  944. // Since iOS supports webgl starting from version 8.1 and 8.1 runs on several graphics chips, the results may be different across ios devices, but we need to verify it.
  945. var result = []
  946. var vShaderTemplate = 'attribute vec2 attrVertex;varying vec2 varyinTexCoordinate;uniform vec2 uniformOffset;void main(){varyinTexCoordinate=attrVertex+uniformOffset;gl_Position=vec4(attrVertex,0,1);}'
  947. var fShaderTemplate = 'precision mediump float;varying vec2 varyinTexCoordinate;void main() {gl_FragColor=vec4(varyinTexCoordinate,0,1);}'
  948. var vertexPosBuffer = gl.createBuffer()
  949. gl.bindBuffer(gl.ARRAY_BUFFER, vertexPosBuffer)
  950. var vertices = new Float32Array([-0.2, -0.9, 0, 0.4, -0.26, 0, 0, 0.732134444, 0])
  951. gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW)
  952. vertexPosBuffer.itemSize = 3
  953. vertexPosBuffer.numItems = 3
  954. var program = gl.createProgram()
  955. var vshader = gl.createShader(gl.VERTEX_SHADER)
  956. gl.shaderSource(vshader, vShaderTemplate)
  957. gl.compileShader(vshader)
  958. var fshader = gl.createShader(gl.FRAGMENT_SHADER)
  959. gl.shaderSource(fshader, fShaderTemplate)
  960. gl.compileShader(fshader)
  961. gl.attachShader(program, vshader)
  962. gl.attachShader(program, fshader)
  963. gl.linkProgram(program)
  964. gl.useProgram(program)
  965. program.vertexPosAttrib = gl.getAttribLocation(program, 'attrVertex')
  966. program.offsetUniform = gl.getUniformLocation(program, 'uniformOffset')
  967. gl.enableVertexAttribArray(program.vertexPosArray)
  968. gl.vertexAttribPointer(program.vertexPosAttrib, vertexPosBuffer.itemSize, gl.FLOAT, !1, 0, 0)
  969. gl.uniform2f(program.offsetUniform, 1, 1)
  970. gl.drawArrays(gl.TRIANGLE_STRIP, 0, vertexPosBuffer.numItems)
  971. try {
  972. result.push(gl.canvas.toDataURL())
  973. } catch (e) {
  974. /* .toDataURL may be absent or broken (blocked by extension) */
  975. }
  976. result.push('extensions:' + (gl.getSupportedExtensions() || []).join(';'))
  977. result.push('webgl aliased line width range:' + fa2s(gl.getParameter(gl.ALIASED_LINE_WIDTH_RANGE)))
  978. result.push('webgl aliased point size range:' + fa2s(gl.getParameter(gl.ALIASED_POINT_SIZE_RANGE)))
  979. result.push('webgl alpha bits:' + gl.getParameter(gl.ALPHA_BITS))
  980. result.push('webgl antialiasing:' + (gl.getContextAttributes().antialias ? 'yes' : 'no'))
  981. result.push('webgl blue bits:' + gl.getParameter(gl.BLUE_BITS))
  982. result.push('webgl depth bits:' + gl.getParameter(gl.DEPTH_BITS))
  983. result.push('webgl green bits:' + gl.getParameter(gl.GREEN_BITS))
  984. result.push('webgl max anisotropy:' + maxAnisotropy(gl))
  985. result.push('webgl max combined texture image units:' + gl.getParameter(gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS))
  986. result.push('webgl max cube map texture size:' + gl.getParameter(gl.MAX_CUBE_MAP_TEXTURE_SIZE))
  987. result.push('webgl max fragment uniform vectors:' + gl.getParameter(gl.MAX_FRAGMENT_UNIFORM_VECTORS))
  988. result.push('webgl max render buffer size:' + gl.getParameter(gl.MAX_RENDERBUFFER_SIZE))
  989. result.push('webgl max texture image units:' + gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS))
  990. result.push('webgl max texture size:' + gl.getParameter(gl.MAX_TEXTURE_SIZE))
  991. result.push('webgl max varying vectors:' + gl.getParameter(gl.MAX_VARYING_VECTORS))
  992. result.push('webgl max vertex attribs:' + gl.getParameter(gl.MAX_VERTEX_ATTRIBS))
  993. result.push('webgl max vertex texture image units:' + gl.getParameter(gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS))
  994. result.push('webgl max vertex uniform vectors:' + gl.getParameter(gl.MAX_VERTEX_UNIFORM_VECTORS))
  995. result.push('webgl max viewport dims:' + fa2s(gl.getParameter(gl.MAX_VIEWPORT_DIMS)))
  996. result.push('webgl red bits:' + gl.getParameter(gl.RED_BITS))
  997. result.push('webgl renderer:' + gl.getParameter(gl.RENDERER))
  998. result.push('webgl shading language version:' + gl.getParameter(gl.SHADING_LANGUAGE_VERSION))
  999. result.push('webgl stencil bits:' + gl.getParameter(gl.STENCIL_BITS))
  1000. result.push('webgl vendor:' + gl.getParameter(gl.VENDOR))
  1001. result.push('webgl version:' + gl.getParameter(gl.VERSION))
  1002. try {
  1003. // Add the unmasked vendor and unmasked renderer if the debug_renderer_info extension is available
  1004. var extensionDebugRendererInfo = gl.getExtension('WEBGL_debug_renderer_info')
  1005. if (extensionDebugRendererInfo) {
  1006. result.push('webgl unmasked vendor:' + gl.getParameter(extensionDebugRendererInfo.UNMASKED_VENDOR_WEBGL))
  1007. result.push('webgl unmasked renderer:' + gl.getParameter(extensionDebugRendererInfo.UNMASKED_RENDERER_WEBGL))
  1008. }
  1009. } catch (e) { /* squelch */ }
  1010. if (!gl.getShaderPrecisionFormat) {
  1011. loseWebglContext(gl)
  1012. return result
  1013. }
  1014. each(['FLOAT', 'INT'], function (numType) {
  1015. each(['VERTEX', 'FRAGMENT'], function (shader) {
  1016. each(['HIGH', 'MEDIUM', 'LOW'], function (numSize) {
  1017. each(['precision', 'rangeMin', 'rangeMax'], function (key) {
  1018. var format = gl.getShaderPrecisionFormat(gl[shader + '_SHADER'], gl[numSize + '_' + numType])[key]
  1019. if (key !== 'precision') {
  1020. key = 'precision ' + key
  1021. }
  1022. var line = ['webgl ', shader.toLowerCase(), ' shader ', numSize.toLowerCase(), ' ', numType.toLowerCase(), ' ', key, ':', format].join('')
  1023. result.push(line)
  1024. })
  1025. })
  1026. })
  1027. })
  1028. loseWebglContext(gl)
  1029. return result
  1030. }
  1031. var getWebglVendorAndRenderer = function () {
  1032. /* This a subset of the WebGL fingerprint with a lot of entropy, while being reasonably browser-independent */
  1033. try {
  1034. var glContext = getWebglCanvas()
  1035. var extensionDebugRendererInfo = glContext.getExtension('WEBGL_debug_renderer_info')
  1036. var params = glContext.getParameter(extensionDebugRendererInfo.UNMASKED_VENDOR_WEBGL) + '~' + glContext.getParameter(extensionDebugRendererInfo.UNMASKED_RENDERER_WEBGL)
  1037. loseWebglContext(glContext)
  1038. return params
  1039. } catch (e) {
  1040. return null
  1041. }
  1042. }
  1043. var getAdBlock = function () {
  1044. var ads = document.createElement('div')
  1045. ads.innerHTML = '&nbsp;'
  1046. ads.className = 'adsbox'
  1047. var result = false
  1048. try {
  1049. // body may not exist, that's why we need try/catch
  1050. document.body.appendChild(ads)
  1051. result = document.getElementsByClassName('adsbox')[0].offsetHeight === 0
  1052. document.body.removeChild(ads)
  1053. } catch (e) {
  1054. result = false
  1055. }
  1056. return result
  1057. }
  1058. var getHasLiedLanguages = function () {
  1059. // We check if navigator.language is equal to the first language of navigator.languages
  1060. // navigator.languages is undefined on IE11 (and potentially older IEs)
  1061. if (typeof navigator.languages !== 'undefined') {
  1062. try {
  1063. var firstLanguages = navigator.languages[0].substr(0, 2)
  1064. if (firstLanguages !== navigator.language.substr(0, 2)) {
  1065. return true
  1066. }
  1067. } catch (err) {
  1068. return true
  1069. }
  1070. }
  1071. return false
  1072. }
  1073. var getHasLiedResolution = function () {
  1074. return window.screen.width < window.screen.availWidth || window.screen.height < window.screen.availHeight
  1075. }
  1076. var getHasLiedOs = function () {
  1077. var userAgent = navigator.userAgent.toLowerCase()
  1078. var oscpu = navigator.oscpu
  1079. var platform = navigator.platform.toLowerCase()
  1080. var os
  1081. // We extract the OS from the user agent (respect the order of the if else if statement)
  1082. if (userAgent.indexOf('windows phone') >= 0) {
  1083. os = 'Windows Phone'
  1084. } else if (userAgent.indexOf('windows') >= 0 || userAgent.indexOf('win16') >= 0 || userAgent.indexOf('win32') >= 0 || userAgent.indexOf('win64') >= 0 || userAgent.indexOf('win95') >= 0 || userAgent.indexOf('win98') >= 0 || userAgent.indexOf('winnt') >= 0 || userAgent.indexOf('wow64') >= 0) {
  1085. os = 'Windows'
  1086. } else if (userAgent.indexOf('android') >= 0) {
  1087. os = 'Android'
  1088. } else if (userAgent.indexOf('linux') >= 0 || userAgent.indexOf('cros') >= 0 || userAgent.indexOf('x11') >= 0) {
  1089. os = 'Linux'
  1090. } else if (userAgent.indexOf('iphone') >= 0 || userAgent.indexOf('ipad') >= 0 || userAgent.indexOf('ipod') >= 0 || userAgent.indexOf('crios') >= 0 || userAgent.indexOf('fxios') >= 0) {
  1091. os = 'iOS'
  1092. } else if (userAgent.indexOf('macintosh') >= 0 || userAgent.indexOf('mac_powerpc)') >= 0) {
  1093. os = 'Mac'
  1094. } else {
  1095. os = 'Other'
  1096. }
  1097. // We detect if the person uses a touch device
  1098. var mobileDevice = (('ontouchstart' in window) ||
  1099. (navigator.maxTouchPoints > 0) ||
  1100. (navigator.msMaxTouchPoints > 0))
  1101. if (mobileDevice && os !== 'Windows' && os !== 'Windows Phone' && os !== 'Android' && os !== 'iOS' && os !== 'Other' && userAgent.indexOf('cros') === -1) {
  1102. return true
  1103. }
  1104. // We compare oscpu with the OS extracted from the UA
  1105. if (typeof oscpu !== 'undefined') {
  1106. oscpu = oscpu.toLowerCase()
  1107. if (oscpu.indexOf('win') >= 0 && os !== 'Windows' && os !== 'Windows Phone') {
  1108. return true
  1109. } else if (oscpu.indexOf('linux') >= 0 && os !== 'Linux' && os !== 'Android') {
  1110. return true
  1111. } else if (oscpu.indexOf('mac') >= 0 && os !== 'Mac' && os !== 'iOS') {
  1112. return true
  1113. } else if ((oscpu.indexOf('win') === -1 && oscpu.indexOf('linux') === -1 && oscpu.indexOf('mac') === -1) !== (os === 'Other')) {
  1114. return true
  1115. }
  1116. }
  1117. // We compare platform with the OS extracted from the UA
  1118. if (platform.indexOf('win') >= 0 && os !== 'Windows' && os !== 'Windows Phone') {
  1119. return true
  1120. } else if ((platform.indexOf('linux') >= 0 || platform.indexOf('android') >= 0 || platform.indexOf('pike') >= 0) && os !== 'Linux' && os !== 'Android') {
  1121. return true
  1122. } else if ((platform.indexOf('mac') >= 0 || platform.indexOf('ipad') >= 0 || platform.indexOf('ipod') >= 0 || platform.indexOf('iphone') >= 0) && os !== 'Mac' && os !== 'iOS') {
  1123. return true
  1124. } else if (platform.indexOf('arm') >= 0 && os === 'Windows Phone') {
  1125. return false
  1126. } else if (platform.indexOf('pike') >= 0 && userAgent.indexOf('opera mini') >= 0) {
  1127. return false
  1128. } else {
  1129. var platformIsOther = platform.indexOf('win') < 0 &&
  1130. platform.indexOf('linux') < 0 &&
  1131. platform.indexOf('mac') < 0 &&
  1132. platform.indexOf('iphone') < 0 &&
  1133. platform.indexOf('ipad') < 0 &&
  1134. platform.indexOf('ipod') < 0
  1135. if (platformIsOther !== (os === 'Other')) {
  1136. return true
  1137. }
  1138. }
  1139. return typeof navigator.plugins === 'undefined' && os !== 'Windows' && os !== 'Windows Phone'
  1140. }
  1141. var getHasLiedBrowser = function () {
  1142. var userAgent = navigator.userAgent.toLowerCase()
  1143. var productSub = navigator.productSub
  1144. // we extract the browser from the user agent (respect the order of the tests)
  1145. var browser
  1146. if (userAgent.indexOf('edge/') >= 0 || userAgent.indexOf('iemobile/') >= 0) {
  1147. // Unreliable, different versions use EdgeHTML, Webkit, Blink, etc.
  1148. return false
  1149. } else if (userAgent.indexOf('opera mini') >= 0) {
  1150. // Unreliable, different modes use Presto, WebView, Webkit, etc.
  1151. return false
  1152. } else if (userAgent.indexOf('firefox/') >= 0) {
  1153. browser = 'Firefox'
  1154. } else if (userAgent.indexOf('opera/') >= 0 || userAgent.indexOf(' opr/') >= 0) {
  1155. browser = 'Opera'
  1156. } else if (userAgent.indexOf('chrome/') >= 0) {
  1157. browser = 'Chrome'
  1158. } else if (userAgent.indexOf('safari/') >= 0) {
  1159. if (userAgent.indexOf('android 1.') >= 0 || userAgent.indexOf('android 2.') >= 0 || userAgent.indexOf('android 3.') >= 0 || userAgent.indexOf('android 4.') >= 0) {
  1160. browser = 'AOSP'
  1161. } else {
  1162. browser = 'Safari'
  1163. }
  1164. } else if (userAgent.indexOf('trident/') >= 0) {
  1165. browser = 'Internet Explorer'
  1166. } else {
  1167. browser = 'Other'
  1168. }
  1169. if ((browser === 'Chrome' || browser === 'Safari' || browser === 'Opera') && productSub !== '20030107') {
  1170. return true
  1171. }
  1172. // eslint-disable-next-line no-eval
  1173. var tempRes = eval.toString().length
  1174. if (tempRes === 37 && browser !== 'Safari' && browser !== 'Firefox' && browser !== 'Other') {
  1175. return true
  1176. } else if (tempRes === 39 && browser !== 'Internet Explorer' && browser !== 'Other') {
  1177. return true
  1178. } else if (tempRes === 33 && browser !== 'Chrome' && browser !== 'AOSP' && browser !== 'Opera' && browser !== 'Other') {
  1179. return true
  1180. }
  1181. // We create an error to see how it is handled
  1182. var errFirefox
  1183. try {
  1184. // eslint-disable-next-line no-throw-literal
  1185. throw 'a'
  1186. } catch (err) {
  1187. try {
  1188. err.toSource()
  1189. errFirefox = true
  1190. } catch (errOfErr) {
  1191. errFirefox = false
  1192. }
  1193. }
  1194. return errFirefox && browser !== 'Firefox' && browser !== 'Other'
  1195. }
  1196. var isCanvasSupported = function () {
  1197. var elem = document.createElement('canvas')
  1198. return !!(elem.getContext && elem.getContext('2d'))
  1199. }
  1200. var isWebGlSupported = function () {
  1201. // code taken from Modernizr
  1202. if (!isCanvasSupported()) {
  1203. return false
  1204. }
  1205. var glContext = getWebglCanvas()
  1206. var isSupported = !!window.WebGLRenderingContext && !!glContext
  1207. loseWebglContext(glContext)
  1208. return isSupported
  1209. }
  1210. var isIE = function () {
  1211. if (navigator.appName === 'Microsoft Internet Explorer') {
  1212. return true
  1213. } else if (navigator.appName === 'Netscape' && /Trident/.test(navigator.userAgent)) { // IE 11
  1214. return true
  1215. }
  1216. return false
  1217. }
  1218. var isIEOrOldEdge = function () {
  1219. // The properties are checked to be in IE 10, IE 11 and Edge 18 and not to be in other browsers
  1220. return ('msWriteProfilerMark' in window) + ('msLaunchUri' in navigator) + ('msSaveBlob' in navigator) >= 2
  1221. }
  1222. var hasSwfObjectLoaded = function () {
  1223. return typeof window.swfobject !== 'undefined'
  1224. }
  1225. var hasMinFlashInstalled = function () {
  1226. return window.swfobject.hasFlashPlayerVersion('9.0.0')
  1227. }
  1228. var addFlashDivNode = function (options) {
  1229. var node = document.createElement('div')
  1230. node.setAttribute('id', options.fonts.swfContainerId)
  1231. document.body.appendChild(node)
  1232. }
  1233. var loadSwfAndDetectFonts = function (done, options) {
  1234. var hiddenCallback = '___fp_swf_loaded'
  1235. window[hiddenCallback] = function (fonts) {
  1236. done(fonts)
  1237. }
  1238. var id = options.fonts.swfContainerId
  1239. addFlashDivNode()
  1240. var flashvars = { onReady: hiddenCallback }
  1241. var flashparams = { allowScriptAccess: 'always', menu: 'false' }
  1242. window.swfobject.embedSWF(options.fonts.swfPath, id, '1', '1', '9.0.0', false, flashvars, flashparams, {})
  1243. }
  1244. var getWebglCanvas = function () {
  1245. var canvas = document.createElement('canvas')
  1246. var gl = null
  1247. try {
  1248. gl = canvas.getContext('webgl') || canvas.getContext('experimental-webgl')
  1249. } catch (e) { /* squelch */ }
  1250. if (!gl) { gl = null }
  1251. return gl
  1252. }
  1253. var loseWebglContext = function (context) {
  1254. var loseContextExtension = context.getExtension('WEBGL_lose_context')
  1255. if (loseContextExtension != null) {
  1256. loseContextExtension.loseContext()
  1257. }
  1258. }
  1259. var components = [
  1260. { key: 'userAgent', getData: UserAgent },
  1261. { key: 'webdriver', getData: webdriver },
  1262. { key: 'language', getData: languageKey },
  1263. { key: 'colorDepth', getData: colorDepthKey },
  1264. { key: 'deviceMemory', getData: deviceMemoryKey },
  1265. { key: 'pixelRatio', getData: pixelRatioKey },
  1266. { key: 'hardwareConcurrency', getData: hardwareConcurrencyKey },
  1267. { key: 'screenResolution', getData: screenResolutionKey },
  1268. { key: 'availableScreenResolution', getData: availableScreenResolutionKey },
  1269. { key: 'timezoneOffset', getData: timezoneOffset },
  1270. { key: 'timezone', getData: timezone },
  1271. { key: 'sessionStorage', getData: sessionStorageKey },
  1272. { key: 'localStorage', getData: localStorageKey },
  1273. { key: 'indexedDb', getData: indexedDbKey },
  1274. { key: 'addBehavior', getData: addBehaviorKey },
  1275. { key: 'openDatabase', getData: openDatabaseKey },
  1276. { key: 'cpuClass', getData: cpuClassKey },
  1277. { key: 'platform', getData: platformKey },
  1278. { key: 'doNotTrack', getData: doNotTrackKey },
  1279. { key: 'plugins', getData: pluginsComponent },
  1280. { key: 'canvas', getData: canvasKey },
  1281. { key: 'webgl', getData: webglKey },
  1282. { key: 'webglVendorAndRenderer', getData: webglVendorAndRendererKey },
  1283. { key: 'adBlock', getData: adBlockKey },
  1284. { key: 'hasLiedLanguages', getData: hasLiedLanguagesKey },
  1285. { key: 'hasLiedResolution', getData: hasLiedResolutionKey },
  1286. { key: 'hasLiedOs', getData: hasLiedOsKey },
  1287. { key: 'hasLiedBrowser', getData: hasLiedBrowserKey },
  1288. { key: 'touchSupport', getData: touchSupportKey },
  1289. { key: 'fonts', getData: jsFontsKey, pauseBefore: true },
  1290. { key: 'fontsFlash', getData: flashFontsKey, pauseBefore: true },
  1291. { key: 'audio', getData: audioKey },
  1292. { key: 'enumerateDevices', getData: enumerateDevicesKey }
  1293. ]
  1294. var Fingerprint2 = function (options) {
  1295. throw new Error("'new Fingerprint()' is deprecated, see https://github.com/fingerprintjs/fingerprintjs#upgrade-guide-from-182-to-200")
  1296. }
  1297. Fingerprint2.get = function (options, callback) {
  1298. if (!callback) {
  1299. callback = options
  1300. options = {}
  1301. } else if (!options) {
  1302. options = {}
  1303. }
  1304. extendSoft(options, defaultOptions)
  1305. options.components = options.extraComponents.concat(components)
  1306. var keys = {
  1307. data: [],
  1308. addPreprocessedComponent: function (key, value) {
  1309. if (typeof options.preprocessor === 'function') {
  1310. value = options.preprocessor(key, value)
  1311. }
  1312. keys.data.push({ key: key, value: value })
  1313. }
  1314. }
  1315. var i = -1
  1316. var chainComponents = function (alreadyWaited) {
  1317. i += 1
  1318. if (i >= options.components.length) { // on finish
  1319. callback(keys.data)
  1320. return
  1321. }
  1322. var component = options.components[i]
  1323. if (options.excludes[component.key]) {
  1324. chainComponents(false) // skip
  1325. return
  1326. }
  1327. if (!alreadyWaited && component.pauseBefore) {
  1328. i -= 1
  1329. setTimeout(function () {
  1330. chainComponents(true)
  1331. }, 1)
  1332. return
  1333. }
  1334. try {
  1335. component.getData(function (value) {
  1336. keys.addPreprocessedComponent(component.key, value)
  1337. chainComponents(false)
  1338. }, options)
  1339. } catch (error) {
  1340. // main body error
  1341. keys.addPreprocessedComponent(component.key, String(error))
  1342. chainComponents(false)
  1343. }
  1344. }
  1345. chainComponents(false)
  1346. }
  1347. Fingerprint2.getPromise = function (options) {
  1348. return new Promise(function (resolve, reject) {
  1349. Fingerprint2.get(options, resolve)
  1350. })
  1351. }
  1352. Fingerprint2.getV18 = function (options, callback) {
  1353. if (callback == null) {
  1354. callback = options
  1355. options = {}
  1356. }
  1357. return Fingerprint2.get(options, function (components) {
  1358. var newComponents = []
  1359. for (var i = 0; i < components.length; i++) {
  1360. var component = components[i]
  1361. if (component.value === (options.NOT_AVAILABLE || 'not available')) {
  1362. newComponents.push({ key: component.key, value: 'unknown' })
  1363. } else if (component.key === 'plugins') {
  1364. newComponents.push({
  1365. key: 'plugins',
  1366. value: map(component.value, function (p) {
  1367. var mimeTypes = map(p[2], function (mt) {
  1368. if (mt.join) { return mt.join('~') }
  1369. return mt
  1370. }).join(',')
  1371. return [p[0], p[1], mimeTypes].join('::')
  1372. })
  1373. })
  1374. } else if (['canvas', 'webgl'].indexOf(component.key) !== -1 && Array.isArray(component.value)) {
  1375. // sometimes WebGL returns error in headless browsers (during CI testing for example)
  1376. // so we need to join only if the values are array
  1377. newComponents.push({ key: component.key, value: component.value.join('~') })
  1378. } else if (['sessionStorage', 'localStorage', 'indexedDb', 'addBehavior', 'openDatabase'].indexOf(component.key) !== -1) {
  1379. if (component.value) {
  1380. newComponents.push({ key: component.key, value: 1 })
  1381. } else {
  1382. // skip
  1383. continue
  1384. }
  1385. } else {
  1386. if (component.value) {
  1387. newComponents.push(component.value.join ? { key: component.key, value: component.value.join(';') } : component)
  1388. } else {
  1389. newComponents.push({ key: component.key, value: component.value })
  1390. }
  1391. }
  1392. }
  1393. var murmur = x64hash128(map(newComponents, function (component) { return component.value }).join('~~~'), 31)
  1394. callback(murmur, newComponents)
  1395. })
  1396. }
  1397. Fingerprint2.x64hash128 = x64hash128
  1398. Fingerprint2.VERSION = '2.1.4'
  1399. return Fingerprint2
  1400. })