fp.cjs.js 129 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244
  1. /**
  2. * FingerprintJS v4.6.2 - Copyright (c) FingerprintJS, Inc, 2025 (https://fingerprint.com)
  3. *
  4. * Licensed under Business Source License 1.1 https://mariadb.com/bsl11/
  5. * Licensor: FingerprintJS, Inc.
  6. * Licensed Work: FingerprintJS browser fingerprinting library
  7. * Additional Use Grant: None
  8. * Change Date: Four years from first release for the specific version.
  9. * Change License: MIT, text at https://opensource.org/license/mit/ with the following copyright notice:
  10. * Copyright 2015-present FingerprintJS, Inc.
  11. */
  12. 'use strict';
  13. Object.defineProperty(exports, '__esModule', { value: true });
  14. var tslib = require('tslib');
  15. var version = "4.6.2";
  16. function wait(durationMs, resolveWith) {
  17. return new Promise(function (resolve) { return setTimeout(resolve, durationMs, resolveWith); });
  18. }
  19. /**
  20. * Allows asynchronous actions and microtasks to happen.
  21. */
  22. function releaseEventLoop() {
  23. // Don't use setTimeout because Chrome throttles it in some cases causing very long agent execution:
  24. // https://stackoverflow.com/a/6032591/1118709
  25. // https://github.com/chromium/chromium/commit/0295dd09496330f3a9103ef7e543fa9b6050409b
  26. // Reusing a MessageChannel object gives no noticeable benefits
  27. return new Promise(function (resolve) {
  28. var channel = new MessageChannel();
  29. channel.port1.onmessage = function () { return resolve(); };
  30. channel.port2.postMessage(null);
  31. });
  32. }
  33. function requestIdleCallbackIfAvailable(fallbackTimeout, deadlineTimeout) {
  34. if (deadlineTimeout === void 0) { deadlineTimeout = Infinity; }
  35. var requestIdleCallback = window.requestIdleCallback;
  36. if (requestIdleCallback) {
  37. // The function `requestIdleCallback` loses the binding to `window` here.
  38. // `globalThis` isn't always equal `window` (see https://github.com/fingerprintjs/fingerprintjs/issues/683).
  39. // Therefore, an error can occur. `call(window,` prevents the error.
  40. return new Promise(function (resolve) { return requestIdleCallback.call(window, function () { return resolve(); }, { timeout: deadlineTimeout }); });
  41. }
  42. else {
  43. return wait(Math.min(fallbackTimeout, deadlineTimeout));
  44. }
  45. }
  46. function isPromise(value) {
  47. return !!value && typeof value.then === 'function';
  48. }
  49. /**
  50. * Calls a maybe asynchronous function without creating microtasks when the function is synchronous.
  51. * Catches errors in both cases.
  52. *
  53. * If just you run a code like this:
  54. * ```
  55. * console.time('Action duration')
  56. * await action()
  57. * console.timeEnd('Action duration')
  58. * ```
  59. * The synchronous function time can be measured incorrectly because another microtask may run before the `await`
  60. * returns the control back to the code.
  61. */
  62. function awaitIfAsync(action, callback) {
  63. try {
  64. var returnedValue = action();
  65. if (isPromise(returnedValue)) {
  66. returnedValue.then(function (result) { return callback(true, result); }, function (error) { return callback(false, error); });
  67. }
  68. else {
  69. callback(true, returnedValue);
  70. }
  71. }
  72. catch (error) {
  73. callback(false, error);
  74. }
  75. }
  76. /**
  77. * If you run many synchronous tasks without using this function, the JS main loop will be busy and asynchronous tasks
  78. * (e.g. completing a network request, rendering the page) won't be able to happen.
  79. * This function allows running many synchronous tasks such way that asynchronous tasks can run too in background.
  80. */
  81. function mapWithBreaks(items, callback, loopReleaseInterval) {
  82. if (loopReleaseInterval === void 0) { loopReleaseInterval = 16; }
  83. return tslib.__awaiter(this, void 0, void 0, function () {
  84. var results, lastLoopReleaseTime, i, now;
  85. return tslib.__generator(this, function (_a) {
  86. switch (_a.label) {
  87. case 0:
  88. results = Array(items.length);
  89. lastLoopReleaseTime = Date.now();
  90. i = 0;
  91. _a.label = 1;
  92. case 1:
  93. if (!(i < items.length)) return [3 /*break*/, 4];
  94. results[i] = callback(items[i], i);
  95. now = Date.now();
  96. if (!(now >= lastLoopReleaseTime + loopReleaseInterval)) return [3 /*break*/, 3];
  97. lastLoopReleaseTime = now;
  98. return [4 /*yield*/, releaseEventLoop()];
  99. case 2:
  100. _a.sent();
  101. _a.label = 3;
  102. case 3:
  103. ++i;
  104. return [3 /*break*/, 1];
  105. case 4: return [2 /*return*/, results];
  106. }
  107. });
  108. });
  109. }
  110. /**
  111. * Makes the given promise never emit an unhandled promise rejection console warning.
  112. * The promise will still pass errors to the next promises.
  113. * Returns the input promise for convenience.
  114. *
  115. * Otherwise, promise emits a console warning unless it has a `catch` listener.
  116. */
  117. function suppressUnhandledRejectionWarning(promise) {
  118. promise.then(undefined, function () { return undefined; });
  119. return promise;
  120. }
  121. /*
  122. * This file contains functions to work with pure data only (no browser features, DOM, side effects, etc).
  123. */
  124. /**
  125. * Does the same as Array.prototype.includes but has better typing
  126. */
  127. function includes(haystack, needle) {
  128. for (var i = 0, l = haystack.length; i < l; ++i) {
  129. if (haystack[i] === needle) {
  130. return true;
  131. }
  132. }
  133. return false;
  134. }
  135. /**
  136. * Like `!includes()` but with proper typing
  137. */
  138. function excludes(haystack, needle) {
  139. return !includes(haystack, needle);
  140. }
  141. /**
  142. * Be careful, NaN can return
  143. */
  144. function toInt(value) {
  145. return parseInt(value);
  146. }
  147. /**
  148. * Be careful, NaN can return
  149. */
  150. function toFloat(value) {
  151. return parseFloat(value);
  152. }
  153. function replaceNaN(value, replacement) {
  154. return typeof value === 'number' && isNaN(value) ? replacement : value;
  155. }
  156. function countTruthy(values) {
  157. return values.reduce(function (sum, value) { return sum + (value ? 1 : 0); }, 0);
  158. }
  159. function round(value, base) {
  160. if (base === void 0) { base = 1; }
  161. if (Math.abs(base) >= 1) {
  162. return Math.round(value / base) * base;
  163. }
  164. else {
  165. // Sometimes when a number is multiplied by a small number, precision is lost,
  166. // for example 1234 * 0.0001 === 0.12340000000000001, and it's more precise divide: 1234 / (1 / 0.0001) === 0.1234.
  167. var counterBase = 1 / base;
  168. return Math.round(value * counterBase) / counterBase;
  169. }
  170. }
  171. /**
  172. * Parses a CSS selector into tag name with HTML attributes.
  173. * Only single element selector are supported (without operators like space, +, >, etc).
  174. *
  175. * Multiple values can be returned for each attribute. You decide how to handle them.
  176. */
  177. function parseSimpleCssSelector(selector) {
  178. var _a, _b;
  179. var errorMessage = "Unexpected syntax '".concat(selector, "'");
  180. var tagMatch = /^\s*([a-z-]*)(.*)$/i.exec(selector);
  181. var tag = tagMatch[1] || undefined;
  182. var attributes = {};
  183. var partsRegex = /([.:#][\w-]+|\[.+?\])/gi;
  184. var addAttribute = function (name, value) {
  185. attributes[name] = attributes[name] || [];
  186. attributes[name].push(value);
  187. };
  188. for (;;) {
  189. var match = partsRegex.exec(tagMatch[2]);
  190. if (!match) {
  191. break;
  192. }
  193. var part = match[0];
  194. switch (part[0]) {
  195. case '.':
  196. addAttribute('class', part.slice(1));
  197. break;
  198. case '#':
  199. addAttribute('id', part.slice(1));
  200. break;
  201. case '[': {
  202. var attributeMatch = /^\[([\w-]+)([~|^$*]?=("(.*?)"|([\w-]+)))?(\s+[is])?\]$/.exec(part);
  203. if (attributeMatch) {
  204. addAttribute(attributeMatch[1], (_b = (_a = attributeMatch[4]) !== null && _a !== void 0 ? _a : attributeMatch[5]) !== null && _b !== void 0 ? _b : '');
  205. }
  206. else {
  207. throw new Error(errorMessage);
  208. }
  209. break;
  210. }
  211. default:
  212. throw new Error(errorMessage);
  213. }
  214. }
  215. return [tag, attributes];
  216. }
  217. /**
  218. * Converts a string to UTF8 bytes
  219. */
  220. function getUTF8Bytes(input) {
  221. // Benchmark: https://jsbench.me/b6klaaxgwq/1
  222. // If you want to just count bytes, see solutions at https://jsbench.me/ehklab415e/1
  223. var result = new Uint8Array(input.length);
  224. for (var i = 0; i < input.length; i++) {
  225. // `charCode` is faster than encoding, so we prefer that when it's possible
  226. var charCode = input.charCodeAt(i);
  227. // In case of non-ASCII symbols we use proper encoding
  228. if (charCode > 127) {
  229. return new TextEncoder().encode(input);
  230. }
  231. result[i] = charCode;
  232. }
  233. return result;
  234. }
  235. /*
  236. * Based on https://github.com/karanlyons/murmurHash3.js/blob/a33d0723127e2e5415056c455f8aed2451ace208/murmurHash3.js
  237. */
  238. /**
  239. * Adds two 64-bit values (provided as tuples of 32-bit values)
  240. * and updates (mutates) first value to write the result
  241. */
  242. function x64Add(m, n) {
  243. var m0 = m[0] >>> 16, m1 = m[0] & 0xffff, m2 = m[1] >>> 16, m3 = m[1] & 0xffff;
  244. var n0 = n[0] >>> 16, n1 = n[0] & 0xffff, n2 = n[1] >>> 16, n3 = n[1] & 0xffff;
  245. var o0 = 0, o1 = 0, o2 = 0, o3 = 0;
  246. o3 += m3 + n3;
  247. o2 += o3 >>> 16;
  248. o3 &= 0xffff;
  249. o2 += m2 + n2;
  250. o1 += o2 >>> 16;
  251. o2 &= 0xffff;
  252. o1 += m1 + n1;
  253. o0 += o1 >>> 16;
  254. o1 &= 0xffff;
  255. o0 += m0 + n0;
  256. o0 &= 0xffff;
  257. m[0] = (o0 << 16) | o1;
  258. m[1] = (o2 << 16) | o3;
  259. }
  260. /**
  261. * Multiplies two 64-bit values (provided as tuples of 32-bit values)
  262. * and updates (mutates) first value to write the result
  263. */
  264. function x64Multiply(m, n) {
  265. var m0 = m[0] >>> 16, m1 = m[0] & 0xffff, m2 = m[1] >>> 16, m3 = m[1] & 0xffff;
  266. var n0 = n[0] >>> 16, n1 = n[0] & 0xffff, n2 = n[1] >>> 16, n3 = n[1] & 0xffff;
  267. var o0 = 0, o1 = 0, o2 = 0, o3 = 0;
  268. o3 += m3 * n3;
  269. o2 += o3 >>> 16;
  270. o3 &= 0xffff;
  271. o2 += m2 * n3;
  272. o1 += o2 >>> 16;
  273. o2 &= 0xffff;
  274. o2 += m3 * n2;
  275. o1 += o2 >>> 16;
  276. o2 &= 0xffff;
  277. o1 += m1 * n3;
  278. o0 += o1 >>> 16;
  279. o1 &= 0xffff;
  280. o1 += m2 * n2;
  281. o0 += o1 >>> 16;
  282. o1 &= 0xffff;
  283. o1 += m3 * n1;
  284. o0 += o1 >>> 16;
  285. o1 &= 0xffff;
  286. o0 += m0 * n3 + m1 * n2 + m2 * n1 + m3 * n0;
  287. o0 &= 0xffff;
  288. m[0] = (o0 << 16) | o1;
  289. m[1] = (o2 << 16) | o3;
  290. }
  291. /**
  292. * Provides left rotation of the given int64 value (provided as tuple of two int32)
  293. * by given number of bits. Result is written back to the value
  294. */
  295. function x64Rotl(m, bits) {
  296. var m0 = m[0];
  297. bits %= 64;
  298. if (bits === 32) {
  299. m[0] = m[1];
  300. m[1] = m0;
  301. }
  302. else if (bits < 32) {
  303. m[0] = (m0 << bits) | (m[1] >>> (32 - bits));
  304. m[1] = (m[1] << bits) | (m0 >>> (32 - bits));
  305. }
  306. else {
  307. bits -= 32;
  308. m[0] = (m[1] << bits) | (m0 >>> (32 - bits));
  309. m[1] = (m0 << bits) | (m[1] >>> (32 - bits));
  310. }
  311. }
  312. /**
  313. * Provides a left shift of the given int32 value (provided as tuple of [0, int32])
  314. * by given number of bits. Result is written back to the value
  315. */
  316. function x64LeftShift(m, bits) {
  317. bits %= 64;
  318. if (bits === 0) {
  319. return;
  320. }
  321. else if (bits < 32) {
  322. m[0] = m[1] >>> (32 - bits);
  323. m[1] = m[1] << bits;
  324. }
  325. else {
  326. m[0] = m[1] << (bits - 32);
  327. m[1] = 0;
  328. }
  329. }
  330. /**
  331. * Provides a XOR of the given int64 values(provided as tuple of two int32).
  332. * Result is written back to the first value
  333. */
  334. function x64Xor(m, n) {
  335. m[0] ^= n[0];
  336. m[1] ^= n[1];
  337. }
  338. var F1 = [0xff51afd7, 0xed558ccd];
  339. var F2 = [0xc4ceb9fe, 0x1a85ec53];
  340. /**
  341. * Calculates murmurHash3's final x64 mix of that block and writes result back to the input value.
  342. * (`[0, h[0] >>> 1]` is a 33 bit unsigned right shift. This is the
  343. * only place where we need to right shift 64bit ints.)
  344. */
  345. function x64Fmix(h) {
  346. var shifted = [0, h[0] >>> 1];
  347. x64Xor(h, shifted);
  348. x64Multiply(h, F1);
  349. shifted[1] = h[0] >>> 1;
  350. x64Xor(h, shifted);
  351. x64Multiply(h, F2);
  352. shifted[1] = h[0] >>> 1;
  353. x64Xor(h, shifted);
  354. }
  355. var C1 = [0x87c37b91, 0x114253d5];
  356. var C2 = [0x4cf5ad43, 0x2745937f];
  357. var M$1 = [0, 5];
  358. var N1 = [0, 0x52dce729];
  359. var N2 = [0, 0x38495ab5];
  360. /**
  361. * Given a string and an optional seed as an int, returns a 128 bit
  362. * hash using the x64 flavor of MurmurHash3, as an unsigned hex.
  363. * All internal functions mutates passed value to achieve minimal memory allocations and GC load
  364. *
  365. * Benchmark https://jsbench.me/p4lkpaoabi/1
  366. */
  367. function x64hash128(input, seed) {
  368. var key = getUTF8Bytes(input);
  369. seed = seed || 0;
  370. var length = [0, key.length];
  371. var remainder = length[1] % 16;
  372. var bytes = length[1] - remainder;
  373. var h1 = [0, seed];
  374. var h2 = [0, seed];
  375. var k1 = [0, 0];
  376. var k2 = [0, 0];
  377. var i;
  378. for (i = 0; i < bytes; i = i + 16) {
  379. k1[0] = key[i + 4] | (key[i + 5] << 8) | (key[i + 6] << 16) | (key[i + 7] << 24);
  380. k1[1] = key[i] | (key[i + 1] << 8) | (key[i + 2] << 16) | (key[i + 3] << 24);
  381. k2[0] = key[i + 12] | (key[i + 13] << 8) | (key[i + 14] << 16) | (key[i + 15] << 24);
  382. k2[1] = key[i + 8] | (key[i + 9] << 8) | (key[i + 10] << 16) | (key[i + 11] << 24);
  383. x64Multiply(k1, C1);
  384. x64Rotl(k1, 31);
  385. x64Multiply(k1, C2);
  386. x64Xor(h1, k1);
  387. x64Rotl(h1, 27);
  388. x64Add(h1, h2);
  389. x64Multiply(h1, M$1);
  390. x64Add(h1, N1);
  391. x64Multiply(k2, C2);
  392. x64Rotl(k2, 33);
  393. x64Multiply(k2, C1);
  394. x64Xor(h2, k2);
  395. x64Rotl(h2, 31);
  396. x64Add(h2, h1);
  397. x64Multiply(h2, M$1);
  398. x64Add(h2, N2);
  399. }
  400. k1[0] = 0;
  401. k1[1] = 0;
  402. k2[0] = 0;
  403. k2[1] = 0;
  404. var val = [0, 0];
  405. switch (remainder) {
  406. case 15:
  407. val[1] = key[i + 14];
  408. x64LeftShift(val, 48);
  409. x64Xor(k2, val);
  410. // fallthrough
  411. case 14:
  412. val[1] = key[i + 13];
  413. x64LeftShift(val, 40);
  414. x64Xor(k2, val);
  415. // fallthrough
  416. case 13:
  417. val[1] = key[i + 12];
  418. x64LeftShift(val, 32);
  419. x64Xor(k2, val);
  420. // fallthrough
  421. case 12:
  422. val[1] = key[i + 11];
  423. x64LeftShift(val, 24);
  424. x64Xor(k2, val);
  425. // fallthrough
  426. case 11:
  427. val[1] = key[i + 10];
  428. x64LeftShift(val, 16);
  429. x64Xor(k2, val);
  430. // fallthrough
  431. case 10:
  432. val[1] = key[i + 9];
  433. x64LeftShift(val, 8);
  434. x64Xor(k2, val);
  435. // fallthrough
  436. case 9:
  437. val[1] = key[i + 8];
  438. x64Xor(k2, val);
  439. x64Multiply(k2, C2);
  440. x64Rotl(k2, 33);
  441. x64Multiply(k2, C1);
  442. x64Xor(h2, k2);
  443. // fallthrough
  444. case 8:
  445. val[1] = key[i + 7];
  446. x64LeftShift(val, 56);
  447. x64Xor(k1, val);
  448. // fallthrough
  449. case 7:
  450. val[1] = key[i + 6];
  451. x64LeftShift(val, 48);
  452. x64Xor(k1, val);
  453. // fallthrough
  454. case 6:
  455. val[1] = key[i + 5];
  456. x64LeftShift(val, 40);
  457. x64Xor(k1, val);
  458. // fallthrough
  459. case 5:
  460. val[1] = key[i + 4];
  461. x64LeftShift(val, 32);
  462. x64Xor(k1, val);
  463. // fallthrough
  464. case 4:
  465. val[1] = key[i + 3];
  466. x64LeftShift(val, 24);
  467. x64Xor(k1, val);
  468. // fallthrough
  469. case 3:
  470. val[1] = key[i + 2];
  471. x64LeftShift(val, 16);
  472. x64Xor(k1, val);
  473. // fallthrough
  474. case 2:
  475. val[1] = key[i + 1];
  476. x64LeftShift(val, 8);
  477. x64Xor(k1, val);
  478. // fallthrough
  479. case 1:
  480. val[1] = key[i];
  481. x64Xor(k1, val);
  482. x64Multiply(k1, C1);
  483. x64Rotl(k1, 31);
  484. x64Multiply(k1, C2);
  485. x64Xor(h1, k1);
  486. // fallthrough
  487. }
  488. x64Xor(h1, length);
  489. x64Xor(h2, length);
  490. x64Add(h1, h2);
  491. x64Add(h2, h1);
  492. x64Fmix(h1);
  493. x64Fmix(h2);
  494. x64Add(h1, h2);
  495. x64Add(h2, h1);
  496. return (('00000000' + (h1[0] >>> 0).toString(16)).slice(-8) +
  497. ('00000000' + (h1[1] >>> 0).toString(16)).slice(-8) +
  498. ('00000000' + (h2[0] >>> 0).toString(16)).slice(-8) +
  499. ('00000000' + (h2[1] >>> 0).toString(16)).slice(-8));
  500. }
  501. /**
  502. * Converts an error object to a plain object that can be used with `JSON.stringify`.
  503. * If you just run `JSON.stringify(error)`, you'll get `'{}'`.
  504. */
  505. function errorToObject(error) {
  506. var _a;
  507. return tslib.__assign({ name: error.name, message: error.message, stack: (_a = error.stack) === null || _a === void 0 ? void 0 : _a.split('\n') }, error);
  508. }
  509. function isFunctionNative(func) {
  510. return /^function\s.*?\{\s*\[native code]\s*}$/.test(String(func));
  511. }
  512. function isFinalResultLoaded(loadResult) {
  513. return typeof loadResult !== 'function';
  514. }
  515. /**
  516. * Loads the given entropy source. Returns a function that gets an entropy component from the source.
  517. *
  518. * The result is returned synchronously to prevent `loadSources` from
  519. * waiting for one source to load before getting the components from the other sources.
  520. */
  521. function loadSource(source, sourceOptions) {
  522. var sourceLoadPromise = suppressUnhandledRejectionWarning(new Promise(function (resolveLoad) {
  523. var loadStartTime = Date.now();
  524. // `awaitIfAsync` is used instead of just `await` in order to measure the duration of synchronous sources
  525. // correctly (other microtasks won't affect the duration).
  526. awaitIfAsync(source.bind(null, sourceOptions), function () {
  527. var loadArgs = [];
  528. for (var _i = 0; _i < arguments.length; _i++) {
  529. loadArgs[_i] = arguments[_i];
  530. }
  531. var loadDuration = Date.now() - loadStartTime;
  532. // Source loading failed
  533. if (!loadArgs[0]) {
  534. return resolveLoad(function () { return ({ error: loadArgs[1], duration: loadDuration }); });
  535. }
  536. var loadResult = loadArgs[1];
  537. // Source loaded with the final result
  538. if (isFinalResultLoaded(loadResult)) {
  539. return resolveLoad(function () { return ({ value: loadResult, duration: loadDuration }); });
  540. }
  541. // Source loaded with "get" stage
  542. resolveLoad(function () {
  543. return new Promise(function (resolveGet) {
  544. var getStartTime = Date.now();
  545. awaitIfAsync(loadResult, function () {
  546. var getArgs = [];
  547. for (var _i = 0; _i < arguments.length; _i++) {
  548. getArgs[_i] = arguments[_i];
  549. }
  550. var duration = loadDuration + Date.now() - getStartTime;
  551. // Source getting failed
  552. if (!getArgs[0]) {
  553. return resolveGet({ error: getArgs[1], duration: duration });
  554. }
  555. // Source getting succeeded
  556. resolveGet({ value: getArgs[1], duration: duration });
  557. });
  558. });
  559. });
  560. });
  561. }));
  562. return function getComponent() {
  563. return sourceLoadPromise.then(function (finalizeSource) { return finalizeSource(); });
  564. };
  565. }
  566. /**
  567. * Loads the given entropy sources. Returns a function that collects the entropy components.
  568. *
  569. * The result is returned synchronously in order to allow start getting the components
  570. * before the sources are loaded completely.
  571. *
  572. * Warning for package users:
  573. * This function is out of Semantic Versioning, i.e. can change unexpectedly. Usage is at your own risk.
  574. */
  575. function loadSources(sources, sourceOptions, excludeSources, loopReleaseInterval) {
  576. var includedSources = Object.keys(sources).filter(function (sourceKey) { return excludes(excludeSources, sourceKey); });
  577. // Using `mapWithBreaks` allows asynchronous sources to complete between synchronous sources
  578. // and measure the duration correctly
  579. var sourceGettersPromise = suppressUnhandledRejectionWarning(mapWithBreaks(includedSources, function (sourceKey) { return loadSource(sources[sourceKey], sourceOptions); }, loopReleaseInterval));
  580. return function getComponents() {
  581. return tslib.__awaiter(this, void 0, void 0, function () {
  582. var sourceGetters, componentPromises, componentArray, components, index;
  583. return tslib.__generator(this, function (_a) {
  584. switch (_a.label) {
  585. case 0: return [4 /*yield*/, sourceGettersPromise];
  586. case 1:
  587. sourceGetters = _a.sent();
  588. return [4 /*yield*/, mapWithBreaks(sourceGetters, function (sourceGetter) { return suppressUnhandledRejectionWarning(sourceGetter()); }, loopReleaseInterval)];
  589. case 2:
  590. componentPromises = _a.sent();
  591. return [4 /*yield*/, Promise.all(componentPromises)
  592. // Keeping the component keys order the same as the source keys order
  593. ];
  594. case 3:
  595. componentArray = _a.sent();
  596. components = {};
  597. for (index = 0; index < includedSources.length; ++index) {
  598. components[includedSources[index]] = componentArray[index];
  599. }
  600. return [2 /*return*/, components];
  601. }
  602. });
  603. });
  604. };
  605. }
  606. /**
  607. * Modifies an entropy source by transforming its returned value with the given function.
  608. * Keeps the source properties: sync/async, 1/2 stages.
  609. *
  610. * Warning for package users:
  611. * This function is out of Semantic Versioning, i.e. can change unexpectedly. Usage is at your own risk.
  612. */
  613. function transformSource(source, transformValue) {
  614. var transformLoadResult = function (loadResult) {
  615. if (isFinalResultLoaded(loadResult)) {
  616. return transformValue(loadResult);
  617. }
  618. return function () {
  619. var getResult = loadResult();
  620. if (isPromise(getResult)) {
  621. return getResult.then(transformValue);
  622. }
  623. return transformValue(getResult);
  624. };
  625. };
  626. return function (options) {
  627. var loadResult = source(options);
  628. if (isPromise(loadResult)) {
  629. return loadResult.then(transformLoadResult);
  630. }
  631. return transformLoadResult(loadResult);
  632. };
  633. }
  634. /*
  635. * Functions to help with features that vary through browsers
  636. */
  637. /**
  638. * Checks whether the browser is based on Trident (the Internet Explorer engine) without using user-agent.
  639. *
  640. * Warning for package users:
  641. * This function is out of Semantic Versioning, i.e. can change unexpectedly. Usage is at your own risk.
  642. */
  643. function isTrident() {
  644. var w = window;
  645. var n = navigator;
  646. // The properties are checked to be in IE 10, IE 11 and not to be in other browsers in October 2020
  647. return (countTruthy([
  648. 'MSCSSMatrix' in w,
  649. 'msSetImmediate' in w,
  650. 'msIndexedDB' in w,
  651. 'msMaxTouchPoints' in n,
  652. 'msPointerEnabled' in n,
  653. ]) >= 4);
  654. }
  655. /**
  656. * Checks whether the browser is based on EdgeHTML (the pre-Chromium Edge engine) without using user-agent.
  657. *
  658. * Warning for package users:
  659. * This function is out of Semantic Versioning, i.e. can change unexpectedly. Usage is at your own risk.
  660. */
  661. function isEdgeHTML() {
  662. // Based on research in October 2020
  663. var w = window;
  664. var n = navigator;
  665. return (countTruthy(['msWriteProfilerMark' in w, 'MSStream' in w, 'msLaunchUri' in n, 'msSaveBlob' in n]) >= 3 &&
  666. !isTrident());
  667. }
  668. /**
  669. * Checks whether the browser is based on Chromium without using user-agent.
  670. *
  671. * Warning for package users:
  672. * This function is out of Semantic Versioning, i.e. can change unexpectedly. Usage is at your own risk.
  673. */
  674. function isChromium() {
  675. // Based on research in October 2020. Tested to detect Chromium 42-86.
  676. var w = window;
  677. var n = navigator;
  678. return (countTruthy([
  679. 'webkitPersistentStorage' in n,
  680. 'webkitTemporaryStorage' in n,
  681. (n.vendor || '').indexOf('Google') === 0,
  682. 'webkitResolveLocalFileSystemURL' in w,
  683. 'BatteryManager' in w,
  684. 'webkitMediaStream' in w,
  685. 'webkitSpeechGrammar' in w,
  686. ]) >= 5);
  687. }
  688. /**
  689. * Checks whether the browser is based on mobile or desktop Safari without using user-agent.
  690. * All iOS browsers use WebKit (the Safari engine).
  691. *
  692. * Warning for package users:
  693. * This function is out of Semantic Versioning, i.e. can change unexpectedly. Usage is at your own risk.
  694. */
  695. function isWebKit() {
  696. // Based on research in August 2024
  697. var w = window;
  698. var n = navigator;
  699. return (countTruthy([
  700. 'ApplePayError' in w,
  701. 'CSSPrimitiveValue' in w,
  702. 'Counter' in w,
  703. n.vendor.indexOf('Apple') === 0,
  704. 'RGBColor' in w,
  705. 'WebKitMediaKeys' in w,
  706. ]) >= 4);
  707. }
  708. /**
  709. * Checks whether this WebKit browser is a desktop browser.
  710. * It doesn't check that the browser is based on WebKit, there is a separate function for this.
  711. *
  712. * Warning for package users:
  713. * This function is out of Semantic Versioning, i.e. can change unexpectedly. Usage is at your own risk.
  714. */
  715. function isDesktopWebKit() {
  716. // Checked in Safari and DuckDuckGo
  717. var w = window;
  718. var HTMLElement = w.HTMLElement, Document = w.Document;
  719. return (countTruthy([
  720. 'safari' in w,
  721. !('ongestureend' in w),
  722. !('TouchEvent' in w),
  723. !('orientation' in w),
  724. HTMLElement && !('autocapitalize' in HTMLElement.prototype),
  725. Document && 'pointerLockElement' in Document.prototype,
  726. ]) >= 4);
  727. }
  728. /**
  729. * Checks whether this WebKit browser is Safari.
  730. * It doesn't check that the browser is based on WebKit, there is a separate function for this.
  731. *
  732. * Warning! The function works properly only for Safari version 15.4 and newer.
  733. */
  734. function isSafariWebKit() {
  735. // Checked in Safari, Chrome, Firefox, Yandex, UC Browser, Opera, Edge and DuckDuckGo.
  736. // iOS Safari and Chrome were checked on iOS 11-18. DuckDuckGo was checked on iOS 17-18 and macOS 14-15.
  737. // Desktop Safari versions 12-18 were checked.
  738. // The other browsers were checked on iOS 17 and 18; there was no chance to check them on the other OS versions.
  739. var w = window;
  740. return (
  741. // Filters-out Chrome, Yandex, DuckDuckGo (macOS and iOS), Edge
  742. isFunctionNative(w.print) &&
  743. // Doesn't work in Safari < 15.4
  744. String(w.browser) === '[object WebPageNamespace]');
  745. }
  746. /**
  747. * Checks whether the browser is based on Gecko (Firefox engine) without using user-agent.
  748. *
  749. * Warning for package users:
  750. * This function is out of Semantic Versioning, i.e. can change unexpectedly. Usage is at your own risk.
  751. */
  752. function isGecko() {
  753. var _a, _b;
  754. var w = window;
  755. // Based on research in September 2020
  756. return (countTruthy([
  757. 'buildID' in navigator,
  758. 'MozAppearance' in ((_b = (_a = document.documentElement) === null || _a === void 0 ? void 0 : _a.style) !== null && _b !== void 0 ? _b : {}),
  759. 'onmozfullscreenchange' in w,
  760. 'mozInnerScreenX' in w,
  761. 'CSSMozDocumentRule' in w,
  762. 'CanvasCaptureMediaStream' in w,
  763. ]) >= 4);
  764. }
  765. /**
  766. * Checks whether the browser is based on Chromium version ≥86 without using user-agent.
  767. * It doesn't check that the browser is based on Chromium, there is a separate function for this.
  768. */
  769. function isChromium86OrNewer() {
  770. // Checked in Chrome 85 vs Chrome 86 both on desktop and Android. Checked in macOS Chrome 128, Android Chrome 127.
  771. var w = window;
  772. return (countTruthy([
  773. !('MediaSettingsRange' in w),
  774. 'RTCEncodedAudioFrame' in w,
  775. '' + w.Intl === '[object Intl]',
  776. '' + w.Reflect === '[object Reflect]',
  777. ]) >= 3);
  778. }
  779. /**
  780. * Checks whether the browser is based on Chromium version ≥122 without using user-agent.
  781. * It doesn't check that the browser is based on Chromium, there is a separate function for this.
  782. */
  783. function isChromium122OrNewer() {
  784. // Checked in Chrome 121 vs Chrome 122 and 129 both on desktop and Android
  785. var w = window;
  786. var URLPattern = w.URLPattern;
  787. return (countTruthy([
  788. 'union' in Set.prototype,
  789. 'Iterator' in w,
  790. URLPattern && 'hasRegExpGroups' in URLPattern.prototype,
  791. 'RGB8' in WebGLRenderingContext.prototype,
  792. ]) >= 3);
  793. }
  794. /**
  795. * Checks whether the browser is based on WebKit version ≥606 (Safari ≥12) without using user-agent.
  796. * It doesn't check that the browser is based on WebKit, there is a separate function for this.
  797. *
  798. * @see https://en.wikipedia.org/wiki/Safari_version_history#Release_history Safari-WebKit versions map
  799. */
  800. function isWebKit606OrNewer() {
  801. // Checked in Safari 9–18
  802. var w = window;
  803. return (countTruthy([
  804. 'DOMRectList' in w,
  805. 'RTCPeerConnectionIceEvent' in w,
  806. 'SVGGeometryElement' in w,
  807. 'ontransitioncancel' in w,
  808. ]) >= 3);
  809. }
  810. /**
  811. * Checks whether the browser is based on WebKit version ≥616 (Safari ≥17) without using user-agent.
  812. * It doesn't check that the browser is based on WebKit, there is a separate function for this.
  813. *
  814. * @see https://developer.apple.com/documentation/safari-release-notes/safari-17-release-notes Safari 17 release notes
  815. * @see https://tauri.app/v1/references/webview-versions/#webkit-versions-in-safari Safari-WebKit versions map
  816. */
  817. function isWebKit616OrNewer() {
  818. var w = window;
  819. var n = navigator;
  820. var CSS = w.CSS, HTMLButtonElement = w.HTMLButtonElement;
  821. return (countTruthy([
  822. !('getStorageUpdates' in n),
  823. HTMLButtonElement && 'popover' in HTMLButtonElement.prototype,
  824. 'CSSCounterStyleRule' in w,
  825. CSS.supports('font-size-adjust: ex-height 0.5'),
  826. CSS.supports('text-transform: full-width'),
  827. ]) >= 4);
  828. }
  829. /**
  830. * Checks whether the device is an iPad.
  831. * It doesn't check that the engine is WebKit and that the WebKit isn't desktop.
  832. */
  833. function isIPad() {
  834. // Checked on:
  835. // Safari on iPadOS (both mobile and desktop modes): 8, 11-18
  836. // Chrome on iPadOS (both mobile and desktop modes): 11-18
  837. // Safari on iOS (both mobile and desktop modes): 9-18
  838. // Chrome on iOS (both mobile and desktop modes): 9-18
  839. // Before iOS 13. Safari tampers the value in "request desktop site" mode since iOS 13.
  840. if (navigator.platform === 'iPad') {
  841. return true;
  842. }
  843. var s = screen;
  844. var screenRatio = s.width / s.height;
  845. return (countTruthy([
  846. // Since iOS 13. Doesn't work in Chrome on iPadOS <15, but works in desktop mode.
  847. 'MediaSource' in window,
  848. // Since iOS 12. Doesn't work in Chrome on iPadOS.
  849. !!Element.prototype.webkitRequestFullscreen,
  850. // iPhone 4S that runs iOS 9 matches this, but it is not supported
  851. // Doesn't work in incognito mode of Safari ≥17 with split screen because of tracking prevention
  852. screenRatio > 0.65 && screenRatio < 1.53,
  853. ]) >= 2);
  854. }
  855. /**
  856. * Warning for package users:
  857. * This function is out of Semantic Versioning, i.e. can change unexpectedly. Usage is at your own risk.
  858. */
  859. function getFullscreenElement() {
  860. var d = document;
  861. return d.fullscreenElement || d.msFullscreenElement || d.mozFullScreenElement || d.webkitFullscreenElement || null;
  862. }
  863. function exitFullscreen() {
  864. var d = document;
  865. // `call` is required because the function throws an error without a proper "this" context
  866. return (d.exitFullscreen || d.msExitFullscreen || d.mozCancelFullScreen || d.webkitExitFullscreen).call(d);
  867. }
  868. /**
  869. * Checks whether the device runs on Android without using user-agent.
  870. *
  871. * Warning for package users:
  872. * This function is out of Semantic Versioning, i.e. can change unexpectedly. Usage is at your own risk.
  873. */
  874. function isAndroid() {
  875. var isItChromium = isChromium();
  876. var isItGecko = isGecko();
  877. var w = window;
  878. var n = navigator;
  879. var c = 'connection';
  880. // Chrome removes all words "Android" from `navigator` when desktop version is requested
  881. // Firefox keeps "Android" in `navigator.appVersion` when desktop version is requested
  882. if (isItChromium) {
  883. return (countTruthy([
  884. !('SharedWorker' in w),
  885. // `typechange` is deprecated, but it's still present on Android (tested on Chrome Mobile 117)
  886. // Removal proposal https://bugs.chromium.org/p/chromium/issues/detail?id=699892
  887. // Note: this expression returns true on ChromeOS, so additional detectors are required to avoid false-positives
  888. n[c] && 'ontypechange' in n[c],
  889. !('sinkId' in new Audio()),
  890. ]) >= 2);
  891. }
  892. else if (isItGecko) {
  893. return countTruthy(['onorientationchange' in w, 'orientation' in w, /android/i.test(n.appVersion)]) >= 2;
  894. }
  895. else {
  896. // Only 2 browser engines are presented on Android.
  897. // Actually, there is also Android 4.1 browser, but it's not worth detecting it at the moment.
  898. return false;
  899. }
  900. }
  901. /**
  902. * Checks whether the browser is Samsung Internet without using user-agent.
  903. * It doesn't check that the browser is based on Chromium, please use `isChromium` before using this function.
  904. *
  905. * Warning for package users:
  906. * This function is out of Semantic Versioning, i.e. can change unexpectedly. Usage is at your own risk.
  907. */
  908. function isSamsungInternet() {
  909. // Checked in Samsung Internet 21, 25 and 27
  910. var n = navigator;
  911. var w = window;
  912. var audioPrototype = Audio.prototype;
  913. var visualViewport = w.visualViewport;
  914. return (countTruthy([
  915. 'srLatency' in audioPrototype,
  916. 'srChannelCount' in audioPrototype,
  917. 'devicePosture' in n,
  918. visualViewport && 'segments' in visualViewport,
  919. 'getTextInformation' in Image.prototype, // Not available in Samsung Internet 21
  920. ]) >= 3);
  921. }
  922. /**
  923. * A deep description: https://fingerprint.com/blog/audio-fingerprinting/
  924. * Inspired by and based on https://github.com/cozylife/audio-fingerprint
  925. *
  926. * A version of the entropy source with stabilization to make it suitable for static fingerprinting.
  927. * Audio signal is noised in private mode of Safari 17, so audio fingerprinting is skipped in Safari 17.
  928. */
  929. function getAudioFingerprint() {
  930. if (doesBrowserPerformAntifingerprinting$1()) {
  931. return -4 /* SpecialFingerprint.KnownForAntifingerprinting */;
  932. }
  933. return getUnstableAudioFingerprint();
  934. }
  935. /**
  936. * A version of the entropy source without stabilization.
  937. *
  938. * Warning for package users:
  939. * This function is out of Semantic Versioning, i.e. can change unexpectedly. Usage is at your own risk.
  940. */
  941. function getUnstableAudioFingerprint() {
  942. var w = window;
  943. var AudioContext = w.OfflineAudioContext || w.webkitOfflineAudioContext;
  944. if (!AudioContext) {
  945. return -2 /* SpecialFingerprint.NotSupported */;
  946. }
  947. // In some browsers, audio context always stays suspended unless the context is started in response to a user action
  948. // (e.g. a click or a tap). It prevents audio fingerprint from being taken at an arbitrary moment of time.
  949. // Such browsers are old and unpopular, so the audio fingerprinting is just skipped in them.
  950. // See a similar case explanation at https://stackoverflow.com/questions/46363048/onaudioprocess-not-called-on-ios11#46534088
  951. if (doesBrowserSuspendAudioContext()) {
  952. return -1 /* SpecialFingerprint.KnownForSuspending */;
  953. }
  954. var hashFromIndex = 4500;
  955. var hashToIndex = 5000;
  956. var context = new AudioContext(1, hashToIndex, 44100);
  957. var oscillator = context.createOscillator();
  958. oscillator.type = 'triangle';
  959. oscillator.frequency.value = 10000;
  960. var compressor = context.createDynamicsCompressor();
  961. compressor.threshold.value = -50;
  962. compressor.knee.value = 40;
  963. compressor.ratio.value = 12;
  964. compressor.attack.value = 0;
  965. compressor.release.value = 0.25;
  966. oscillator.connect(compressor);
  967. compressor.connect(context.destination);
  968. oscillator.start(0);
  969. var _a = startRenderingAudio(context), renderPromise = _a[0], finishRendering = _a[1];
  970. // Suppresses the console error message in case when the fingerprint fails before requested
  971. var fingerprintPromise = suppressUnhandledRejectionWarning(renderPromise.then(function (buffer) { return getHash(buffer.getChannelData(0).subarray(hashFromIndex)); }, function (error) {
  972. if (error.name === "timeout" /* InnerErrorName.Timeout */ || error.name === "suspended" /* InnerErrorName.Suspended */) {
  973. return -3 /* SpecialFingerprint.Timeout */;
  974. }
  975. throw error;
  976. }));
  977. return function () {
  978. finishRendering();
  979. return fingerprintPromise;
  980. };
  981. }
  982. /**
  983. * Checks if the current browser is known for always suspending audio context
  984. */
  985. function doesBrowserSuspendAudioContext() {
  986. // Mobile Safari 11 and older
  987. return isWebKit() && !isDesktopWebKit() && !isWebKit606OrNewer();
  988. }
  989. /**
  990. * Checks if the current browser is known for applying anti-fingerprinting measures in all or some critical modes
  991. */
  992. function doesBrowserPerformAntifingerprinting$1() {
  993. return (
  994. // Safari ≥17
  995. (isWebKit() && isWebKit616OrNewer() && isSafariWebKit()) ||
  996. // Samsung Internet ≥26
  997. (isChromium() && isSamsungInternet() && isChromium122OrNewer()));
  998. }
  999. /**
  1000. * Starts rendering the audio context.
  1001. * When the returned function is called, the render process starts finishing.
  1002. */
  1003. function startRenderingAudio(context) {
  1004. var renderTryMaxCount = 3;
  1005. var renderRetryDelay = 500;
  1006. var runningMaxAwaitTime = 500;
  1007. var runningSufficientTime = 5000;
  1008. var finalize = function () { return undefined; };
  1009. var resultPromise = new Promise(function (resolve, reject) {
  1010. var isFinalized = false;
  1011. var renderTryCount = 0;
  1012. var startedRunningAt = 0;
  1013. context.oncomplete = function (event) { return resolve(event.renderedBuffer); };
  1014. var startRunningTimeout = function () {
  1015. setTimeout(function () { return reject(makeInnerError("timeout" /* InnerErrorName.Timeout */)); }, Math.min(runningMaxAwaitTime, startedRunningAt + runningSufficientTime - Date.now()));
  1016. };
  1017. var tryRender = function () {
  1018. try {
  1019. var renderingPromise = context.startRendering();
  1020. // `context.startRendering` has two APIs: Promise and callback, we check that it's really a promise just in case
  1021. if (isPromise(renderingPromise)) {
  1022. // Suppresses all unhandled rejections in case of scheduled redundant retries after successful rendering
  1023. suppressUnhandledRejectionWarning(renderingPromise);
  1024. }
  1025. switch (context.state) {
  1026. case 'running':
  1027. startedRunningAt = Date.now();
  1028. if (isFinalized) {
  1029. startRunningTimeout();
  1030. }
  1031. break;
  1032. // Sometimes the audio context doesn't start after calling `startRendering` (in addition to the cases where
  1033. // audio context doesn't start at all). A known case is starting an audio context when the browser tab is in
  1034. // background on iPhone. Retries usually help in this case.
  1035. case 'suspended':
  1036. // The audio context can reject starting until the tab is in foreground. Long fingerprint duration
  1037. // in background isn't a problem, therefore the retry attempts don't count in background. It can lead to
  1038. // a situation when a fingerprint takes very long time and finishes successfully. FYI, the audio context
  1039. // can be suspended when `document.hidden === false` and start running after a retry.
  1040. if (!document.hidden) {
  1041. renderTryCount++;
  1042. }
  1043. if (isFinalized && renderTryCount >= renderTryMaxCount) {
  1044. reject(makeInnerError("suspended" /* InnerErrorName.Suspended */));
  1045. }
  1046. else {
  1047. setTimeout(tryRender, renderRetryDelay);
  1048. }
  1049. break;
  1050. }
  1051. }
  1052. catch (error) {
  1053. reject(error);
  1054. }
  1055. };
  1056. tryRender();
  1057. finalize = function () {
  1058. if (!isFinalized) {
  1059. isFinalized = true;
  1060. if (startedRunningAt > 0) {
  1061. startRunningTimeout();
  1062. }
  1063. }
  1064. };
  1065. });
  1066. return [resultPromise, finalize];
  1067. }
  1068. function getHash(signal) {
  1069. var hash = 0;
  1070. for (var i = 0; i < signal.length; ++i) {
  1071. hash += Math.abs(signal[i]);
  1072. }
  1073. return hash;
  1074. }
  1075. function makeInnerError(name) {
  1076. var error = new Error(name);
  1077. error.name = name;
  1078. return error;
  1079. }
  1080. /**
  1081. * Creates and keeps an invisible iframe while the given function runs.
  1082. * The given function is called when the iframe is loaded and has a body.
  1083. * The iframe allows to measure DOM sizes inside itself.
  1084. *
  1085. * Notice: passing an initial HTML code doesn't work in IE.
  1086. *
  1087. * Warning for package users:
  1088. * This function is out of Semantic Versioning, i.e. can change unexpectedly. Usage is at your own risk.
  1089. */
  1090. function withIframe(action, initialHtml, domPollInterval) {
  1091. var _a, _b, _c;
  1092. if (domPollInterval === void 0) { domPollInterval = 50; }
  1093. return tslib.__awaiter(this, void 0, void 0, function () {
  1094. var d, iframe;
  1095. return tslib.__generator(this, function (_d) {
  1096. switch (_d.label) {
  1097. case 0:
  1098. d = document;
  1099. _d.label = 1;
  1100. case 1:
  1101. if (!!d.body) return [3 /*break*/, 3];
  1102. return [4 /*yield*/, wait(domPollInterval)];
  1103. case 2:
  1104. _d.sent();
  1105. return [3 /*break*/, 1];
  1106. case 3:
  1107. iframe = d.createElement('iframe');
  1108. _d.label = 4;
  1109. case 4:
  1110. _d.trys.push([4, , 10, 11]);
  1111. return [4 /*yield*/, new Promise(function (_resolve, _reject) {
  1112. var isComplete = false;
  1113. var resolve = function () {
  1114. isComplete = true;
  1115. _resolve();
  1116. };
  1117. var reject = function (error) {
  1118. isComplete = true;
  1119. _reject(error);
  1120. };
  1121. iframe.onload = resolve;
  1122. iframe.onerror = reject;
  1123. var style = iframe.style;
  1124. style.setProperty('display', 'block', 'important'); // Required for browsers to calculate the layout
  1125. style.position = 'absolute';
  1126. style.top = '0';
  1127. style.left = '0';
  1128. style.visibility = 'hidden';
  1129. if (initialHtml && 'srcdoc' in iframe) {
  1130. iframe.srcdoc = initialHtml;
  1131. }
  1132. else {
  1133. iframe.src = 'about:blank';
  1134. }
  1135. d.body.appendChild(iframe);
  1136. // WebKit in WeChat doesn't fire the iframe's `onload` for some reason.
  1137. // This code checks for the loading state manually.
  1138. // See https://github.com/fingerprintjs/fingerprintjs/issues/645
  1139. var checkReadyState = function () {
  1140. var _a, _b;
  1141. // The ready state may never become 'complete' in Firefox despite the 'load' event being fired.
  1142. // So an infinite setTimeout loop can happen without this check.
  1143. // See https://github.com/fingerprintjs/fingerprintjs/pull/716#issuecomment-986898796
  1144. if (isComplete) {
  1145. return;
  1146. }
  1147. // Make sure iframe.contentWindow and iframe.contentWindow.document are both loaded
  1148. // The contentWindow.document can miss in JSDOM (https://github.com/jsdom/jsdom).
  1149. if (((_b = (_a = iframe.contentWindow) === null || _a === void 0 ? void 0 : _a.document) === null || _b === void 0 ? void 0 : _b.readyState) === 'complete') {
  1150. resolve();
  1151. }
  1152. else {
  1153. setTimeout(checkReadyState, 10);
  1154. }
  1155. };
  1156. checkReadyState();
  1157. })];
  1158. case 5:
  1159. _d.sent();
  1160. _d.label = 6;
  1161. case 6:
  1162. if (!!((_b = (_a = iframe.contentWindow) === null || _a === void 0 ? void 0 : _a.document) === null || _b === void 0 ? void 0 : _b.body)) return [3 /*break*/, 8];
  1163. return [4 /*yield*/, wait(domPollInterval)];
  1164. case 7:
  1165. _d.sent();
  1166. return [3 /*break*/, 6];
  1167. case 8: return [4 /*yield*/, action(iframe, iframe.contentWindow)];
  1168. case 9: return [2 /*return*/, _d.sent()];
  1169. case 10:
  1170. (_c = iframe.parentNode) === null || _c === void 0 ? void 0 : _c.removeChild(iframe);
  1171. return [7 /*endfinally*/];
  1172. case 11: return [2 /*return*/];
  1173. }
  1174. });
  1175. });
  1176. }
  1177. /**
  1178. * Creates a DOM element that matches the given selector.
  1179. * Only single element selector are supported (without operators like space, +, >, etc).
  1180. */
  1181. function selectorToElement(selector) {
  1182. var _a = parseSimpleCssSelector(selector), tag = _a[0], attributes = _a[1];
  1183. var element = document.createElement(tag !== null && tag !== void 0 ? tag : 'div');
  1184. for (var _i = 0, _b = Object.keys(attributes); _i < _b.length; _i++) {
  1185. var name_1 = _b[_i];
  1186. var value = attributes[name_1].join(' ');
  1187. // Changing the `style` attribute can cause a CSP error, therefore we change the `style.cssText` property.
  1188. // https://github.com/fingerprintjs/fingerprintjs/issues/733
  1189. if (name_1 === 'style') {
  1190. addStyleString(element.style, value);
  1191. }
  1192. else {
  1193. element.setAttribute(name_1, value);
  1194. }
  1195. }
  1196. return element;
  1197. }
  1198. /**
  1199. * Adds CSS styles from a string in such a way that doesn't trigger a CSP warning (unsafe-inline or unsafe-eval)
  1200. */
  1201. function addStyleString(style, source) {
  1202. // We don't use `style.cssText` because browsers must block it when no `unsafe-eval` CSP is presented: https://csplite.com/csp145/#w3c_note
  1203. // Even though the browsers ignore this standard, we don't use `cssText` just in case.
  1204. for (var _i = 0, _a = source.split(';'); _i < _a.length; _i++) {
  1205. var property = _a[_i];
  1206. var match = /^\s*([\w-]+)\s*:\s*(.+?)(\s*!([\w-]+))?\s*$/.exec(property);
  1207. if (match) {
  1208. var name_2 = match[1], value = match[2], priority = match[4];
  1209. style.setProperty(name_2, value, priority || ''); // The last argument can't be undefined in IE11
  1210. }
  1211. }
  1212. }
  1213. /**
  1214. * Returns true if the code runs in an iframe, and any parent page's origin doesn't match the current origin
  1215. */
  1216. function isAnyParentCrossOrigin() {
  1217. var currentWindow = window;
  1218. for (;;) {
  1219. var parentWindow = currentWindow.parent;
  1220. if (!parentWindow || parentWindow === currentWindow) {
  1221. return false; // The top page is reached
  1222. }
  1223. try {
  1224. if (parentWindow.location.origin !== currentWindow.location.origin) {
  1225. return true;
  1226. }
  1227. }
  1228. catch (error) {
  1229. // The error is thrown when `origin` is accessed on `parentWindow.location` when the parent is cross-origin
  1230. if (error instanceof Error && error.name === 'SecurityError') {
  1231. return true;
  1232. }
  1233. throw error;
  1234. }
  1235. currentWindow = parentWindow;
  1236. }
  1237. }
  1238. // We use m or w because these two characters take up the maximum width.
  1239. // And we use a LLi so that the same matching fonts can get separated.
  1240. var testString = 'mmMwWLliI0O&1';
  1241. // We test using 48px font size, we may use any size. I guess larger the better.
  1242. var textSize = '48px';
  1243. // A font will be compared against all the three default fonts.
  1244. // And if for any default fonts it doesn't match, then that font is available.
  1245. var baseFonts = ['monospace', 'sans-serif', 'serif'];
  1246. var fontList = [
  1247. // This is android-specific font from "Roboto" family
  1248. 'sans-serif-thin',
  1249. 'ARNO PRO',
  1250. 'Agency FB',
  1251. 'Arabic Typesetting',
  1252. 'Arial Unicode MS',
  1253. 'AvantGarde Bk BT',
  1254. 'BankGothic Md BT',
  1255. 'Batang',
  1256. 'Bitstream Vera Sans Mono',
  1257. 'Calibri',
  1258. 'Century',
  1259. 'Century Gothic',
  1260. 'Clarendon',
  1261. 'EUROSTILE',
  1262. 'Franklin Gothic',
  1263. 'Futura Bk BT',
  1264. 'Futura Md BT',
  1265. 'GOTHAM',
  1266. 'Gill Sans',
  1267. 'HELV',
  1268. 'Haettenschweiler',
  1269. 'Helvetica Neue',
  1270. 'Humanst521 BT',
  1271. 'Leelawadee',
  1272. 'Letter Gothic',
  1273. 'Levenim MT',
  1274. 'Lucida Bright',
  1275. 'Lucida Sans',
  1276. 'Menlo',
  1277. 'MS Mincho',
  1278. 'MS Outlook',
  1279. 'MS Reference Specialty',
  1280. 'MS UI Gothic',
  1281. 'MT Extra',
  1282. 'MYRIAD PRO',
  1283. 'Marlett',
  1284. 'Meiryo UI',
  1285. 'Microsoft Uighur',
  1286. 'Minion Pro',
  1287. 'Monotype Corsiva',
  1288. 'PMingLiU',
  1289. 'Pristina',
  1290. 'SCRIPTINA',
  1291. 'Segoe UI Light',
  1292. 'Serifa',
  1293. 'SimHei',
  1294. 'Small Fonts',
  1295. 'Staccato222 BT',
  1296. 'TRAJAN PRO',
  1297. 'Univers CE 55 Medium',
  1298. 'Vrinda',
  1299. 'ZWAdobeF',
  1300. ];
  1301. // kudos to http://www.lalit.org/lab/javascript-css-font-detect/
  1302. function getFonts() {
  1303. var _this = this;
  1304. // Running the script in an iframe makes it not affect the page look and not be affected by the page CSS. See:
  1305. // https://github.com/fingerprintjs/fingerprintjs/issues/592
  1306. // https://github.com/fingerprintjs/fingerprintjs/issues/628
  1307. return withIframe(function (_, _a) {
  1308. var document = _a.document;
  1309. return tslib.__awaiter(_this, void 0, void 0, function () {
  1310. var holder, spansContainer, defaultWidth, defaultHeight, createSpan, createSpanWithFonts, initializeBaseFontsSpans, initializeFontsSpans, isFontAvailable, baseFontsSpans, fontsSpans, index;
  1311. return tslib.__generator(this, function (_b) {
  1312. holder = document.body;
  1313. holder.style.fontSize = textSize;
  1314. spansContainer = document.createElement('div');
  1315. spansContainer.style.setProperty('visibility', 'hidden', 'important');
  1316. defaultWidth = {};
  1317. defaultHeight = {};
  1318. createSpan = function (fontFamily) {
  1319. var span = document.createElement('span');
  1320. var style = span.style;
  1321. style.position = 'absolute';
  1322. style.top = '0';
  1323. style.left = '0';
  1324. style.fontFamily = fontFamily;
  1325. span.textContent = testString;
  1326. spansContainer.appendChild(span);
  1327. return span;
  1328. };
  1329. createSpanWithFonts = function (fontToDetect, baseFont) {
  1330. return createSpan("'".concat(fontToDetect, "',").concat(baseFont));
  1331. };
  1332. initializeBaseFontsSpans = function () {
  1333. return baseFonts.map(createSpan);
  1334. };
  1335. initializeFontsSpans = function () {
  1336. // Stores {fontName : [spans for that font]}
  1337. var spans = {};
  1338. var _loop_1 = function (font) {
  1339. spans[font] = baseFonts.map(function (baseFont) { return createSpanWithFonts(font, baseFont); });
  1340. };
  1341. for (var _i = 0, fontList_1 = fontList; _i < fontList_1.length; _i++) {
  1342. var font = fontList_1[_i];
  1343. _loop_1(font);
  1344. }
  1345. return spans;
  1346. };
  1347. isFontAvailable = function (fontSpans) {
  1348. return baseFonts.some(function (baseFont, baseFontIndex) {
  1349. return fontSpans[baseFontIndex].offsetWidth !== defaultWidth[baseFont] ||
  1350. fontSpans[baseFontIndex].offsetHeight !== defaultHeight[baseFont];
  1351. });
  1352. };
  1353. baseFontsSpans = initializeBaseFontsSpans();
  1354. fontsSpans = initializeFontsSpans();
  1355. // add all the spans to the DOM
  1356. holder.appendChild(spansContainer);
  1357. // get the default width for the three base fonts
  1358. for (index = 0; index < baseFonts.length; index++) {
  1359. defaultWidth[baseFonts[index]] = baseFontsSpans[index].offsetWidth; // width for the default font
  1360. defaultHeight[baseFonts[index]] = baseFontsSpans[index].offsetHeight; // height for the default font
  1361. }
  1362. // check available fonts
  1363. return [2 /*return*/, fontList.filter(function (font) { return isFontAvailable(fontsSpans[font]); })];
  1364. });
  1365. });
  1366. });
  1367. }
  1368. function getPlugins() {
  1369. var rawPlugins = navigator.plugins;
  1370. if (!rawPlugins) {
  1371. return undefined;
  1372. }
  1373. var plugins = [];
  1374. // Safari 10 doesn't support iterating navigator.plugins with for...of
  1375. for (var i = 0; i < rawPlugins.length; ++i) {
  1376. var plugin = rawPlugins[i];
  1377. if (!plugin) {
  1378. continue;
  1379. }
  1380. var mimeTypes = [];
  1381. for (var j = 0; j < plugin.length; ++j) {
  1382. var mimeType = plugin[j];
  1383. mimeTypes.push({
  1384. type: mimeType.type,
  1385. suffixes: mimeType.suffixes,
  1386. });
  1387. }
  1388. plugins.push({
  1389. name: plugin.name,
  1390. description: plugin.description,
  1391. mimeTypes: mimeTypes,
  1392. });
  1393. }
  1394. return plugins;
  1395. }
  1396. /**
  1397. * @see https://www.browserleaks.com/canvas#how-does-it-work
  1398. *
  1399. * A version of the entropy source with stabilization to make it suitable for static fingerprinting.
  1400. * Canvas image is noised in private mode of Safari 17, so image rendering is skipped in Safari 17.
  1401. */
  1402. function getCanvasFingerprint() {
  1403. return getUnstableCanvasFingerprint(doesBrowserPerformAntifingerprinting());
  1404. }
  1405. /**
  1406. * A version of the entropy source without stabilization.
  1407. *
  1408. * Warning for package users:
  1409. * This function is out of Semantic Versioning, i.e. can change unexpectedly. Usage is at your own risk.
  1410. */
  1411. function getUnstableCanvasFingerprint(skipImages) {
  1412. var _a;
  1413. var winding = false;
  1414. var geometry;
  1415. var text;
  1416. var _b = makeCanvasContext(), canvas = _b[0], context = _b[1];
  1417. if (!isSupported(canvas, context)) {
  1418. geometry = text = "unsupported" /* ImageStatus.Unsupported */;
  1419. }
  1420. else {
  1421. winding = doesSupportWinding(context);
  1422. if (skipImages) {
  1423. geometry = text = "skipped" /* ImageStatus.Skipped */;
  1424. }
  1425. else {
  1426. _a = renderImages(canvas, context), geometry = _a[0], text = _a[1];
  1427. }
  1428. }
  1429. return { winding: winding, geometry: geometry, text: text };
  1430. }
  1431. function makeCanvasContext() {
  1432. var canvas = document.createElement('canvas');
  1433. canvas.width = 1;
  1434. canvas.height = 1;
  1435. return [canvas, canvas.getContext('2d')];
  1436. }
  1437. function isSupported(canvas, context) {
  1438. return !!(context && canvas.toDataURL);
  1439. }
  1440. function doesSupportWinding(context) {
  1441. // https://web.archive.org/web/20170825024655/http://blogs.adobe.com/webplatform/2013/01/30/winding-rules-in-canvas/
  1442. // https://github.com/Modernizr/Modernizr/blob/master/feature-detects/canvas/winding.js
  1443. context.rect(0, 0, 10, 10);
  1444. context.rect(2, 2, 6, 6);
  1445. return !context.isPointInPath(5, 5, 'evenodd');
  1446. }
  1447. function renderImages(canvas, context) {
  1448. renderTextImage(canvas, context);
  1449. var textImage1 = canvasToString(canvas);
  1450. var textImage2 = canvasToString(canvas); // It's slightly faster to double-encode the text image
  1451. // Some browsers add a noise to the canvas: https://github.com/fingerprintjs/fingerprintjs/issues/791
  1452. // The canvas is excluded from the fingerprint in this case
  1453. if (textImage1 !== textImage2) {
  1454. return ["unstable" /* ImageStatus.Unstable */, "unstable" /* ImageStatus.Unstable */];
  1455. }
  1456. // Text is unstable:
  1457. // https://github.com/fingerprintjs/fingerprintjs/issues/583
  1458. // https://github.com/fingerprintjs/fingerprintjs/issues/103
  1459. // Therefore it's extracted into a separate image.
  1460. renderGeometryImage(canvas, context);
  1461. var geometryImage = canvasToString(canvas);
  1462. return [geometryImage, textImage1];
  1463. }
  1464. function renderTextImage(canvas, context) {
  1465. // Resizing the canvas cleans it
  1466. canvas.width = 240;
  1467. canvas.height = 60;
  1468. context.textBaseline = 'alphabetic';
  1469. context.fillStyle = '#f60';
  1470. context.fillRect(100, 1, 62, 20);
  1471. context.fillStyle = '#069';
  1472. // It's important to use explicit built-in fonts in order to exclude the affect of font preferences
  1473. // (there is a separate entropy source for them).
  1474. context.font = '11pt "Times New Roman"';
  1475. // The choice of emojis has a gigantic impact on rendering performance (especially in FF).
  1476. // Some newer emojis cause it to slow down 50-200 times.
  1477. // There must be no text to the right of the emoji, see https://github.com/fingerprintjs/fingerprintjs/issues/574
  1478. // A bare emoji shouldn't be used because the canvas will change depending on the script encoding:
  1479. // https://github.com/fingerprintjs/fingerprintjs/issues/66
  1480. // Escape sequence shouldn't be used too because Terser will turn it into a bare unicode.
  1481. var printedText = "Cwm fjordbank gly ".concat(String.fromCharCode(55357, 56835) /* 😃 */);
  1482. context.fillText(printedText, 2, 15);
  1483. context.fillStyle = 'rgba(102, 204, 0, 0.2)';
  1484. context.font = '18pt Arial';
  1485. context.fillText(printedText, 4, 45);
  1486. }
  1487. function renderGeometryImage(canvas, context) {
  1488. // Resizing the canvas cleans it
  1489. canvas.width = 122;
  1490. canvas.height = 110;
  1491. // Canvas blending
  1492. // https://web.archive.org/web/20170826194121/http://blogs.adobe.com/webplatform/2013/01/28/blending-features-in-canvas/
  1493. // http://jsfiddle.net/NDYV8/16/
  1494. context.globalCompositeOperation = 'multiply';
  1495. for (var _i = 0, _a = [
  1496. ['#f2f', 40, 40],
  1497. ['#2ff', 80, 40],
  1498. ['#ff2', 60, 80],
  1499. ]; _i < _a.length; _i++) {
  1500. var _b = _a[_i], color = _b[0], x = _b[1], y = _b[2];
  1501. context.fillStyle = color;
  1502. context.beginPath();
  1503. context.arc(x, y, 40, 0, Math.PI * 2, true);
  1504. context.closePath();
  1505. context.fill();
  1506. }
  1507. // Canvas winding
  1508. // https://web.archive.org/web/20130913061632/http://blogs.adobe.com/webplatform/2013/01/30/winding-rules-in-canvas/
  1509. // http://jsfiddle.net/NDYV8/19/
  1510. context.fillStyle = '#f9c';
  1511. context.arc(60, 60, 60, 0, Math.PI * 2, true);
  1512. context.arc(60, 60, 20, 0, Math.PI * 2, true);
  1513. context.fill('evenodd');
  1514. }
  1515. function canvasToString(canvas) {
  1516. return canvas.toDataURL();
  1517. }
  1518. /**
  1519. * Checks if the current browser is known for applying anti-fingerprinting measures in all or some critical modes
  1520. */
  1521. function doesBrowserPerformAntifingerprinting() {
  1522. // Safari 17
  1523. return isWebKit() && isWebKit616OrNewer() && isSafariWebKit();
  1524. }
  1525. /**
  1526. * This is a crude and primitive touch screen detection. It's not possible to currently reliably detect the availability
  1527. * of a touch screen with a JS, without actually subscribing to a touch event.
  1528. *
  1529. * @see http://www.stucox.com/blog/you-cant-detect-a-touchscreen/
  1530. * @see https://github.com/Modernizr/Modernizr/issues/548
  1531. */
  1532. function getTouchSupport() {
  1533. var n = navigator;
  1534. var maxTouchPoints = 0;
  1535. var touchEvent;
  1536. if (n.maxTouchPoints !== undefined) {
  1537. maxTouchPoints = toInt(n.maxTouchPoints);
  1538. }
  1539. else if (n.msMaxTouchPoints !== undefined) {
  1540. maxTouchPoints = n.msMaxTouchPoints;
  1541. }
  1542. try {
  1543. document.createEvent('TouchEvent');
  1544. touchEvent = true;
  1545. }
  1546. catch (_a) {
  1547. touchEvent = false;
  1548. }
  1549. var touchStart = 'ontouchstart' in window;
  1550. return {
  1551. maxTouchPoints: maxTouchPoints,
  1552. touchEvent: touchEvent,
  1553. touchStart: touchStart,
  1554. };
  1555. }
  1556. function getOsCpu() {
  1557. return navigator.oscpu;
  1558. }
  1559. function getLanguages() {
  1560. var n = navigator;
  1561. var result = [];
  1562. var language = n.language || n.userLanguage || n.browserLanguage || n.systemLanguage;
  1563. if (language !== undefined) {
  1564. result.push([language]);
  1565. }
  1566. if (Array.isArray(n.languages)) {
  1567. // Starting from Chromium 86, there is only a single value in `navigator.language` in Incognito mode:
  1568. // the value of `navigator.language`. Therefore the value is ignored in this browser.
  1569. if (!(isChromium() && isChromium86OrNewer())) {
  1570. result.push(n.languages);
  1571. }
  1572. }
  1573. else if (typeof n.languages === 'string') {
  1574. var languages = n.languages;
  1575. if (languages) {
  1576. result.push(languages.split(','));
  1577. }
  1578. }
  1579. return result;
  1580. }
  1581. function getColorDepth() {
  1582. return window.screen.colorDepth;
  1583. }
  1584. function getDeviceMemory() {
  1585. // `navigator.deviceMemory` is a string containing a number in some unidentified cases
  1586. return replaceNaN(toFloat(navigator.deviceMemory), undefined);
  1587. }
  1588. /**
  1589. * A version of the entropy source with stabilization to make it suitable for static fingerprinting.
  1590. * The window resolution is always the document size in private mode of Safari 17,
  1591. * so the window resolution is not used in Safari 17.
  1592. */
  1593. function getScreenResolution() {
  1594. if (isWebKit() && isWebKit616OrNewer() && isSafariWebKit()) {
  1595. return undefined;
  1596. }
  1597. return getUnstableScreenResolution();
  1598. }
  1599. /**
  1600. * A version of the entropy source without stabilization.
  1601. *
  1602. * Warning for package users:
  1603. * This function is out of Semantic Versioning, i.e. can change unexpectedly. Usage is at your own risk.
  1604. */
  1605. function getUnstableScreenResolution() {
  1606. var s = screen;
  1607. // Some browsers return screen resolution as strings, e.g. "1200", instead of a number, e.g. 1200.
  1608. // I suspect it's done by certain plugins that randomize browser properties to prevent fingerprinting.
  1609. // Some browsers even return screen resolution as not numbers.
  1610. var parseDimension = function (value) { return replaceNaN(toInt(value), null); };
  1611. var dimensions = [parseDimension(s.width), parseDimension(s.height)];
  1612. dimensions.sort().reverse();
  1613. return dimensions;
  1614. }
  1615. var screenFrameCheckInterval = 2500;
  1616. var roundingPrecision = 10;
  1617. // The type is readonly to protect from unwanted mutations
  1618. var screenFrameBackup;
  1619. var screenFrameSizeTimeoutId;
  1620. /**
  1621. * Starts watching the screen frame size. When a non-zero size appears, the size is saved and the watch is stopped.
  1622. * Later, when `getScreenFrame` runs, it will return the saved non-zero size if the current size is null.
  1623. *
  1624. * This trick is required to mitigate the fact that the screen frame turns null in some cases.
  1625. * See more on this at https://github.com/fingerprintjs/fingerprintjs/issues/568
  1626. */
  1627. function watchScreenFrame() {
  1628. if (screenFrameSizeTimeoutId !== undefined) {
  1629. return;
  1630. }
  1631. var checkScreenFrame = function () {
  1632. var frameSize = getCurrentScreenFrame();
  1633. if (isFrameSizeNull(frameSize)) {
  1634. screenFrameSizeTimeoutId = setTimeout(checkScreenFrame, screenFrameCheckInterval);
  1635. }
  1636. else {
  1637. screenFrameBackup = frameSize;
  1638. screenFrameSizeTimeoutId = undefined;
  1639. }
  1640. };
  1641. checkScreenFrame();
  1642. }
  1643. /**
  1644. * A version of the entropy source without stabilization.
  1645. *
  1646. * Warning for package users:
  1647. * This function is out of Semantic Versioning, i.e. can change unexpectedly. Usage is at your own risk.
  1648. */
  1649. function getUnstableScreenFrame() {
  1650. var _this = this;
  1651. watchScreenFrame();
  1652. return function () { return tslib.__awaiter(_this, void 0, void 0, function () {
  1653. var frameSize;
  1654. return tslib.__generator(this, function (_a) {
  1655. switch (_a.label) {
  1656. case 0:
  1657. frameSize = getCurrentScreenFrame();
  1658. if (!isFrameSizeNull(frameSize)) return [3 /*break*/, 2];
  1659. if (screenFrameBackup) {
  1660. return [2 /*return*/, tslib.__spreadArray([], screenFrameBackup, true)];
  1661. }
  1662. if (!getFullscreenElement()) return [3 /*break*/, 2];
  1663. // Some browsers set the screen frame to zero when programmatic fullscreen is on.
  1664. // There is a chance of getting a non-zero frame after exiting the fullscreen.
  1665. // See more on this at https://github.com/fingerprintjs/fingerprintjs/issues/568
  1666. return [4 /*yield*/, exitFullscreen()];
  1667. case 1:
  1668. // Some browsers set the screen frame to zero when programmatic fullscreen is on.
  1669. // There is a chance of getting a non-zero frame after exiting the fullscreen.
  1670. // See more on this at https://github.com/fingerprintjs/fingerprintjs/issues/568
  1671. _a.sent();
  1672. frameSize = getCurrentScreenFrame();
  1673. _a.label = 2;
  1674. case 2:
  1675. if (!isFrameSizeNull(frameSize)) {
  1676. screenFrameBackup = frameSize;
  1677. }
  1678. return [2 /*return*/, frameSize];
  1679. }
  1680. });
  1681. }); };
  1682. }
  1683. /**
  1684. * A version of the entropy source with stabilization to make it suitable for static fingerprinting.
  1685. *
  1686. * Sometimes the available screen resolution changes a bit, e.g. 1900x1440 → 1900x1439. A possible reason: macOS Dock
  1687. * shrinks to fit more icons when there is too little space. The rounding is used to mitigate the difference.
  1688. *
  1689. * The frame width is always 0 in private mode of Safari 17, so the frame is not used in Safari 17.
  1690. */
  1691. function getScreenFrame() {
  1692. var _this = this;
  1693. if (isWebKit() && isWebKit616OrNewer() && isSafariWebKit()) {
  1694. return function () { return Promise.resolve(undefined); };
  1695. }
  1696. var screenFrameGetter = getUnstableScreenFrame();
  1697. return function () { return tslib.__awaiter(_this, void 0, void 0, function () {
  1698. var frameSize, processSize;
  1699. return tslib.__generator(this, function (_a) {
  1700. switch (_a.label) {
  1701. case 0: return [4 /*yield*/, screenFrameGetter()];
  1702. case 1:
  1703. frameSize = _a.sent();
  1704. processSize = function (sideSize) { return (sideSize === null ? null : round(sideSize, roundingPrecision)); };
  1705. // It might look like I don't know about `for` and `map`.
  1706. // In fact, such code is used to avoid TypeScript issues without using `as`.
  1707. return [2 /*return*/, [processSize(frameSize[0]), processSize(frameSize[1]), processSize(frameSize[2]), processSize(frameSize[3])]];
  1708. }
  1709. });
  1710. }); };
  1711. }
  1712. function getCurrentScreenFrame() {
  1713. var s = screen;
  1714. // Some browsers return screen resolution as strings, e.g. "1200", instead of a number, e.g. 1200.
  1715. // I suspect it's done by certain plugins that randomize browser properties to prevent fingerprinting.
  1716. //
  1717. // Some browsers (IE, Edge ≤18) don't provide `screen.availLeft` and `screen.availTop`. The property values are
  1718. // replaced with 0 in such cases to not lose the entropy from `screen.availWidth` and `screen.availHeight`.
  1719. return [
  1720. replaceNaN(toFloat(s.availTop), null),
  1721. replaceNaN(toFloat(s.width) - toFloat(s.availWidth) - replaceNaN(toFloat(s.availLeft), 0), null),
  1722. replaceNaN(toFloat(s.height) - toFloat(s.availHeight) - replaceNaN(toFloat(s.availTop), 0), null),
  1723. replaceNaN(toFloat(s.availLeft), null),
  1724. ];
  1725. }
  1726. function isFrameSizeNull(frameSize) {
  1727. for (var i = 0; i < 4; ++i) {
  1728. if (frameSize[i]) {
  1729. return false;
  1730. }
  1731. }
  1732. return true;
  1733. }
  1734. function getHardwareConcurrency() {
  1735. // sometimes hardware concurrency is a string
  1736. return replaceNaN(toInt(navigator.hardwareConcurrency), undefined);
  1737. }
  1738. function getTimezone() {
  1739. var _a;
  1740. var DateTimeFormat = (_a = window.Intl) === null || _a === void 0 ? void 0 : _a.DateTimeFormat;
  1741. if (DateTimeFormat) {
  1742. var timezone = new DateTimeFormat().resolvedOptions().timeZone;
  1743. if (timezone) {
  1744. return timezone;
  1745. }
  1746. }
  1747. // For browsers that don't support timezone names
  1748. // The minus is intentional because the JS offset is opposite to the real offset
  1749. var offset = -getTimezoneOffset();
  1750. return "UTC".concat(offset >= 0 ? '+' : '').concat(offset);
  1751. }
  1752. function getTimezoneOffset() {
  1753. var currentYear = new Date().getFullYear();
  1754. // The timezone offset may change over time due to daylight saving time (DST) shifts.
  1755. // The non-DST timezone offset is used as the result timezone offset.
  1756. // Since the DST season differs in the northern and the southern hemispheres,
  1757. // both January and July timezones offsets are considered.
  1758. return Math.max(
  1759. // `getTimezoneOffset` returns a number as a string in some unidentified cases
  1760. toFloat(new Date(currentYear, 0, 1).getTimezoneOffset()), toFloat(new Date(currentYear, 6, 1).getTimezoneOffset()));
  1761. }
  1762. function getSessionStorage() {
  1763. try {
  1764. return !!window.sessionStorage;
  1765. }
  1766. catch (error) {
  1767. /* SecurityError when referencing it means it exists */
  1768. return true;
  1769. }
  1770. }
  1771. // https://bugzilla.mozilla.org/show_bug.cgi?id=781447
  1772. function getLocalStorage() {
  1773. try {
  1774. return !!window.localStorage;
  1775. }
  1776. catch (e) {
  1777. /* SecurityError when referencing it means it exists */
  1778. return true;
  1779. }
  1780. }
  1781. function getIndexedDB() {
  1782. // IE and Edge don't allow accessing indexedDB in private mode, therefore IE and Edge will have different
  1783. // visitor identifier in normal and private modes.
  1784. if (isTrident() || isEdgeHTML()) {
  1785. return undefined;
  1786. }
  1787. try {
  1788. return !!window.indexedDB;
  1789. }
  1790. catch (e) {
  1791. /* SecurityError when referencing it means it exists */
  1792. return true;
  1793. }
  1794. }
  1795. function getOpenDatabase() {
  1796. return !!window.openDatabase;
  1797. }
  1798. function getCpuClass() {
  1799. return navigator.cpuClass;
  1800. }
  1801. function getPlatform() {
  1802. // Android Chrome 86 and 87 and Android Firefox 80 and 84 don't mock the platform value when desktop mode is requested
  1803. var platform = navigator.platform;
  1804. // iOS mocks the platform value when desktop version is requested: https://github.com/fingerprintjs/fingerprintjs/issues/514
  1805. // iPad uses desktop mode by default since iOS 13
  1806. // The value is 'MacIntel' on M1 Macs
  1807. // The value is 'iPhone' on iPod Touch
  1808. if (platform === 'MacIntel') {
  1809. if (isWebKit() && !isDesktopWebKit()) {
  1810. return isIPad() ? 'iPad' : 'iPhone';
  1811. }
  1812. }
  1813. return platform;
  1814. }
  1815. function getVendor() {
  1816. return navigator.vendor || '';
  1817. }
  1818. /**
  1819. * Checks for browser-specific (not engine specific) global variables to tell browsers with the same engine apart.
  1820. * Only somewhat popular browsers are considered.
  1821. */
  1822. function getVendorFlavors() {
  1823. var flavors = [];
  1824. for (var _i = 0, _a = [
  1825. // Blink and some browsers on iOS
  1826. 'chrome',
  1827. // Safari on macOS
  1828. 'safari',
  1829. // Chrome on iOS (checked in 85 on 13 and 87 on 14)
  1830. '__crWeb',
  1831. '__gCrWeb',
  1832. // Yandex Browser on iOS, macOS and Android (checked in 21.2 on iOS 14, macOS and Android)
  1833. 'yandex',
  1834. // Yandex Browser on iOS (checked in 21.2 on 14)
  1835. '__yb',
  1836. '__ybro',
  1837. // Firefox on iOS (checked in 32 on 14)
  1838. '__firefox__',
  1839. // Edge on iOS (checked in 46 on 14)
  1840. '__edgeTrackingPreventionStatistics',
  1841. 'webkit',
  1842. // Opera Touch on iOS (checked in 2.6 on 14)
  1843. 'oprt',
  1844. // Samsung Internet on Android (checked in 11.1)
  1845. 'samsungAr',
  1846. // UC Browser on Android (checked in 12.10 and 13.0)
  1847. 'ucweb',
  1848. 'UCShellJava',
  1849. // Puffin on Android (checked in 9.0)
  1850. 'puffinDevice',
  1851. // UC on iOS and Opera on Android have no specific global variables
  1852. // Edge for Android isn't checked
  1853. ]; _i < _a.length; _i++) {
  1854. var key = _a[_i];
  1855. var value = window[key];
  1856. if (value && typeof value === 'object') {
  1857. flavors.push(key);
  1858. }
  1859. }
  1860. return flavors.sort();
  1861. }
  1862. /**
  1863. * navigator.cookieEnabled cannot detect custom or nuanced cookie blocking configurations. For example, when blocking
  1864. * cookies via the Advanced Privacy Settings in IE9, it always returns true. And there have been issues in the past with
  1865. * site-specific exceptions. Don't rely on it.
  1866. *
  1867. * @see https://github.com/Modernizr/Modernizr/blob/master/feature-detects/cookies.js Taken from here
  1868. */
  1869. function areCookiesEnabled() {
  1870. var d = document;
  1871. // Taken from here: https://github.com/Modernizr/Modernizr/blob/master/feature-detects/cookies.js
  1872. // navigator.cookieEnabled cannot detect custom or nuanced cookie blocking configurations. For example, when blocking
  1873. // cookies via the Advanced Privacy Settings in IE9, it always returns true. And there have been issues in the past
  1874. // with site-specific exceptions. Don't rely on it.
  1875. // try..catch because some in situations `document.cookie` is exposed but throws a
  1876. // SecurityError if you try to access it; e.g. documents created from data URIs
  1877. // or in sandboxed iframes (depending on flags/context)
  1878. try {
  1879. // Create cookie
  1880. d.cookie = 'cookietest=1; SameSite=Strict;';
  1881. var result = d.cookie.indexOf('cookietest=') !== -1;
  1882. // Delete cookie
  1883. d.cookie = 'cookietest=1; SameSite=Strict; expires=Thu, 01-Jan-1970 00:00:01 GMT';
  1884. return result;
  1885. }
  1886. catch (e) {
  1887. return false;
  1888. }
  1889. }
  1890. /**
  1891. * Only single element selector are supported (no operators like space, +, >, etc).
  1892. * `embed` and `position: fixed;` will be considered as blocked anyway because it always has no offsetParent.
  1893. * Avoid `iframe` and anything with `[src=]` because they produce excess HTTP requests.
  1894. *
  1895. * The "inappropriate" selectors are obfuscated. See https://github.com/fingerprintjs/fingerprintjs/issues/734.
  1896. * A function is used instead of a plain object to help tree-shaking.
  1897. *
  1898. * The function code is generated automatically. See docs/content_blockers.md to learn how to make the list.
  1899. */
  1900. function getFilters() {
  1901. var fromB64 = atob; // Just for better minification
  1902. return {
  1903. abpIndo: [
  1904. '#Iklan-Melayang',
  1905. '#Kolom-Iklan-728',
  1906. '#SidebarIklan-wrapper',
  1907. '[title="ALIENBOLA" i]',
  1908. fromB64('I0JveC1CYW5uZXItYWRz'),
  1909. ],
  1910. abpvn: ['.quangcao', '#mobileCatfish', fromB64('LmNsb3NlLWFkcw=='), '[id^="bn_bottom_fixed_"]', '#pmadv'],
  1911. adBlockFinland: [
  1912. '.mainostila',
  1913. fromB64('LnNwb25zb3JpdA=='),
  1914. '.ylamainos',
  1915. fromB64('YVtocmVmKj0iL2NsaWNrdGhyZ2guYXNwPyJd'),
  1916. fromB64('YVtocmVmXj0iaHR0cHM6Ly9hcHAucmVhZHBlYWsuY29tL2FkcyJd'),
  1917. ],
  1918. adBlockPersian: [
  1919. '#navbar_notice_50',
  1920. '.kadr',
  1921. 'TABLE[width="140px"]',
  1922. '#divAgahi',
  1923. fromB64('YVtocmVmXj0iaHR0cDovL2cxLnYuZndtcm0ubmV0L2FkLyJd'),
  1924. ],
  1925. adBlockWarningRemoval: [
  1926. '#adblock-honeypot',
  1927. '.adblocker-root',
  1928. '.wp_adblock_detect',
  1929. fromB64('LmhlYWRlci1ibG9ja2VkLWFk'),
  1930. fromB64('I2FkX2Jsb2NrZXI='),
  1931. ],
  1932. adGuardAnnoyances: [
  1933. '.hs-sosyal',
  1934. '#cookieconsentdiv',
  1935. 'div[class^="app_gdpr"]',
  1936. '.as-oil',
  1937. '[data-cypress="soft-push-notification-modal"]',
  1938. ],
  1939. adGuardBase: [
  1940. '.BetterJsPopOverlay',
  1941. fromB64('I2FkXzMwMFgyNTA='),
  1942. fromB64('I2Jhbm5lcmZsb2F0MjI='),
  1943. fromB64('I2NhbXBhaWduLWJhbm5lcg=='),
  1944. fromB64('I0FkLUNvbnRlbnQ='),
  1945. ],
  1946. adGuardChinese: [
  1947. fromB64('LlppX2FkX2FfSA=='),
  1948. fromB64('YVtocmVmKj0iLmh0aGJldDM0LmNvbSJd'),
  1949. '#widget-quan',
  1950. fromB64('YVtocmVmKj0iLzg0OTkyMDIwLnh5eiJd'),
  1951. fromB64('YVtocmVmKj0iLjE5NTZobC5jb20vIl0='),
  1952. ],
  1953. adGuardFrench: [
  1954. '#pavePub',
  1955. fromB64('LmFkLWRlc2t0b3AtcmVjdGFuZ2xl'),
  1956. '.mobile_adhesion',
  1957. '.widgetadv',
  1958. fromB64('LmFkc19iYW4='),
  1959. ],
  1960. adGuardGerman: ['aside[data-portal-id="leaderboard"]'],
  1961. adGuardJapanese: [
  1962. '#kauli_yad_1',
  1963. fromB64('YVtocmVmXj0iaHR0cDovL2FkMi50cmFmZmljZ2F0ZS5uZXQvIl0='),
  1964. fromB64('Ll9wb3BJbl9pbmZpbml0ZV9hZA=='),
  1965. fromB64('LmFkZ29vZ2xl'),
  1966. fromB64('Ll9faXNib29zdFJldHVybkFk'),
  1967. ],
  1968. adGuardMobile: [
  1969. fromB64('YW1wLWF1dG8tYWRz'),
  1970. fromB64('LmFtcF9hZA=='),
  1971. 'amp-embed[type="24smi"]',
  1972. '#mgid_iframe1',
  1973. fromB64('I2FkX2ludmlld19hcmVh'),
  1974. ],
  1975. adGuardRussian: [
  1976. fromB64('YVtocmVmXj0iaHR0cHM6Ly9hZC5sZXRtZWFkcy5jb20vIl0='),
  1977. fromB64('LnJlY2xhbWE='),
  1978. 'div[id^="smi2adblock"]',
  1979. fromB64('ZGl2W2lkXj0iQWRGb3hfYmFubmVyXyJd'),
  1980. '#psyduckpockeball',
  1981. ],
  1982. adGuardSocial: [
  1983. fromB64('YVtocmVmXj0iLy93d3cuc3R1bWJsZXVwb24uY29tL3N1Ym1pdD91cmw9Il0='),
  1984. fromB64('YVtocmVmXj0iLy90ZWxlZ3JhbS5tZS9zaGFyZS91cmw/Il0='),
  1985. '.etsy-tweet',
  1986. '#inlineShare',
  1987. '.popup-social',
  1988. ],
  1989. adGuardSpanishPortuguese: ['#barraPublicidade', '#Publicidade', '#publiEspecial', '#queTooltip', '.cnt-publi'],
  1990. adGuardTrackingProtection: [
  1991. '#qoo-counter',
  1992. fromB64('YVtocmVmXj0iaHR0cDovL2NsaWNrLmhvdGxvZy5ydS8iXQ=='),
  1993. fromB64('YVtocmVmXj0iaHR0cDovL2hpdGNvdW50ZXIucnUvdG9wL3N0YXQucGhwIl0='),
  1994. fromB64('YVtocmVmXj0iaHR0cDovL3RvcC5tYWlsLnJ1L2p1bXAiXQ=='),
  1995. '#top100counter',
  1996. ],
  1997. adGuardTurkish: [
  1998. '#backkapat',
  1999. fromB64('I3Jla2xhbWk='),
  2000. fromB64('YVtocmVmXj0iaHR0cDovL2Fkc2Vydi5vbnRlay5jb20udHIvIl0='),
  2001. fromB64('YVtocmVmXj0iaHR0cDovL2l6bGVuemkuY29tL2NhbXBhaWduLyJd'),
  2002. fromB64('YVtocmVmXj0iaHR0cDovL3d3dy5pbnN0YWxsYWRzLm5ldC8iXQ=='),
  2003. ],
  2004. bulgarian: [fromB64('dGQjZnJlZW5ldF90YWJsZV9hZHM='), '#ea_intext_div', '.lapni-pop-over', '#xenium_hot_offers'],
  2005. easyList: [
  2006. '.yb-floorad',
  2007. fromB64('LndpZGdldF9wb19hZHNfd2lkZ2V0'),
  2008. fromB64('LnRyYWZmaWNqdW5reS1hZA=='),
  2009. '.textad_headline',
  2010. fromB64('LnNwb25zb3JlZC10ZXh0LWxpbmtz'),
  2011. ],
  2012. easyListChina: [
  2013. fromB64('LmFwcGd1aWRlLXdyYXBbb25jbGljayo9ImJjZWJvcy5jb20iXQ=='),
  2014. fromB64('LmZyb250cGFnZUFkdk0='),
  2015. '#taotaole',
  2016. '#aafoot.top_box',
  2017. '.cfa_popup',
  2018. ],
  2019. easyListCookie: [
  2020. '.ezmob-footer',
  2021. '.cc-CookieWarning',
  2022. '[data-cookie-number]',
  2023. fromB64('LmF3LWNvb2tpZS1iYW5uZXI='),
  2024. '.sygnal24-gdpr-modal-wrap',
  2025. ],
  2026. easyListCzechSlovak: [
  2027. '#onlajny-stickers',
  2028. fromB64('I3Jla2xhbW5pLWJveA=='),
  2029. fromB64('LnJla2xhbWEtbWVnYWJvYXJk'),
  2030. '.sklik',
  2031. fromB64('W2lkXj0ic2tsaWtSZWtsYW1hIl0='),
  2032. ],
  2033. easyListDutch: [
  2034. fromB64('I2FkdmVydGVudGll'),
  2035. fromB64('I3ZpcEFkbWFya3RCYW5uZXJCbG9jaw=='),
  2036. '.adstekst',
  2037. fromB64('YVtocmVmXj0iaHR0cHM6Ly94bHR1YmUubmwvY2xpY2svIl0='),
  2038. '#semilo-lrectangle',
  2039. ],
  2040. easyListGermany: [
  2041. '#SSpotIMPopSlider',
  2042. fromB64('LnNwb25zb3JsaW5rZ3J1ZW4='),
  2043. fromB64('I3dlcmJ1bmdza3k='),
  2044. fromB64('I3Jla2xhbWUtcmVjaHRzLW1pdHRl'),
  2045. fromB64('YVtocmVmXj0iaHR0cHM6Ly9iZDc0Mi5jb20vIl0='),
  2046. ],
  2047. easyListItaly: [
  2048. fromB64('LmJveF9hZHZfYW5udW5jaQ=='),
  2049. '.sb-box-pubbliredazionale',
  2050. fromB64('YVtocmVmXj0iaHR0cDovL2FmZmlsaWF6aW9uaWFkcy5zbmFpLml0LyJd'),
  2051. fromB64('YVtocmVmXj0iaHR0cHM6Ly9hZHNlcnZlci5odG1sLml0LyJd'),
  2052. fromB64('YVtocmVmXj0iaHR0cHM6Ly9hZmZpbGlhemlvbmlhZHMuc25haS5pdC8iXQ=='),
  2053. ],
  2054. easyListLithuania: [
  2055. fromB64('LnJla2xhbW9zX3RhcnBhcw=='),
  2056. fromB64('LnJla2xhbW9zX251b3JvZG9z'),
  2057. fromB64('aW1nW2FsdD0iUmVrbGFtaW5pcyBza3lkZWxpcyJd'),
  2058. fromB64('aW1nW2FsdD0iRGVkaWt1b3RpLmx0IHNlcnZlcmlhaSJd'),
  2059. fromB64('aW1nW2FsdD0iSG9zdGluZ2FzIFNlcnZlcmlhaS5sdCJd'),
  2060. ],
  2061. estonian: [fromB64('QVtocmVmKj0iaHR0cDovL3BheTRyZXN1bHRzMjQuZXUiXQ==')],
  2062. fanboyAnnoyances: ['#ac-lre-player', '.navigate-to-top', '#subscribe_popup', '.newsletter_holder', '#back-top'],
  2063. fanboyAntiFacebook: ['.util-bar-module-firefly-visible'],
  2064. fanboyEnhancedTrackers: [
  2065. '.open.pushModal',
  2066. '#issuem-leaky-paywall-articles-zero-remaining-nag',
  2067. '#sovrn_container',
  2068. 'div[class$="-hide"][zoompage-fontsize][style="display: block;"]',
  2069. '.BlockNag__Card',
  2070. ],
  2071. fanboySocial: ['#FollowUs', '#meteored_share', '#social_follow', '.article-sharer', '.community__social-desc'],
  2072. frellwitSwedish: [
  2073. fromB64('YVtocmVmKj0iY2FzaW5vcHJvLnNlIl1bdGFyZ2V0PSJfYmxhbmsiXQ=='),
  2074. fromB64('YVtocmVmKj0iZG9rdG9yLXNlLm9uZWxpbmsubWUiXQ=='),
  2075. 'article.category-samarbete',
  2076. fromB64('ZGl2LmhvbGlkQWRz'),
  2077. 'ul.adsmodern',
  2078. ],
  2079. greekAdBlock: [
  2080. fromB64('QVtocmVmKj0iYWRtYW4ub3RlbmV0LmdyL2NsaWNrPyJd'),
  2081. fromB64('QVtocmVmKj0iaHR0cDovL2F4aWFiYW5uZXJzLmV4b2R1cy5nci8iXQ=='),
  2082. fromB64('QVtocmVmKj0iaHR0cDovL2ludGVyYWN0aXZlLmZvcnRobmV0LmdyL2NsaWNrPyJd'),
  2083. 'DIV.agores300',
  2084. 'TABLE.advright',
  2085. ],
  2086. hungarian: [
  2087. '#cemp_doboz',
  2088. '.optimonk-iframe-container',
  2089. fromB64('LmFkX19tYWlu'),
  2090. fromB64('W2NsYXNzKj0iR29vZ2xlQWRzIl0='),
  2091. '#hirdetesek_box',
  2092. ],
  2093. iDontCareAboutCookies: [
  2094. '.alert-info[data-block-track*="CookieNotice"]',
  2095. '.ModuleTemplateCookieIndicator',
  2096. '.o--cookies--container',
  2097. '#cookies-policy-sticky',
  2098. '#stickyCookieBar',
  2099. ],
  2100. icelandicAbp: [fromB64('QVtocmVmXj0iL2ZyYW1ld29yay9yZXNvdXJjZXMvZm9ybXMvYWRzLmFzcHgiXQ==')],
  2101. latvian: [
  2102. fromB64('YVtocmVmPSJodHRwOi8vd3d3LnNhbGlkemluaS5sdi8iXVtzdHlsZT0iZGlzcGxheTogYmxvY2s7IHdpZHRoOiAxMjBweDsgaGVpZ2h0O' +
  2103. 'iA0MHB4OyBvdmVyZmxvdzogaGlkZGVuOyBwb3NpdGlvbjogcmVsYXRpdmU7Il0='),
  2104. fromB64('YVtocmVmPSJodHRwOi8vd3d3LnNhbGlkemluaS5sdi8iXVtzdHlsZT0iZGlzcGxheTogYmxvY2s7IHdpZHRoOiA4OHB4OyBoZWlnaHQ6I' +
  2105. 'DMxcHg7IG92ZXJmbG93OiBoaWRkZW47IHBvc2l0aW9uOiByZWxhdGl2ZTsiXQ=='),
  2106. ],
  2107. listKr: [
  2108. fromB64('YVtocmVmKj0iLy9hZC5wbGFuYnBsdXMuY28ua3IvIl0='),
  2109. fromB64('I2xpdmVyZUFkV3JhcHBlcg=='),
  2110. fromB64('YVtocmVmKj0iLy9hZHYuaW1hZHJlcC5jby5rci8iXQ=='),
  2111. fromB64('aW5zLmZhc3R2aWV3LWFk'),
  2112. '.revenue_unit_item.dable',
  2113. ],
  2114. listeAr: [
  2115. fromB64('LmdlbWluaUxCMUFk'),
  2116. '.right-and-left-sponsers',
  2117. fromB64('YVtocmVmKj0iLmFmbGFtLmluZm8iXQ=='),
  2118. fromB64('YVtocmVmKj0iYm9vcmFxLm9yZyJd'),
  2119. fromB64('YVtocmVmKj0iZHViaXp6bGUuY29tL2FyLz91dG1fc291cmNlPSJd'),
  2120. ],
  2121. listeFr: [
  2122. fromB64('YVtocmVmXj0iaHR0cDovL3Byb21vLnZhZG9yLmNvbS8iXQ=='),
  2123. fromB64('I2FkY29udGFpbmVyX3JlY2hlcmNoZQ=='),
  2124. fromB64('YVtocmVmKj0id2Vib3JhbWEuZnIvZmNnaS1iaW4vIl0='),
  2125. '.site-pub-interstitiel',
  2126. 'div[id^="crt-"][data-criteo-id]',
  2127. ],
  2128. officialPolish: [
  2129. '#ceneo-placeholder-ceneo-12',
  2130. fromB64('W2hyZWZePSJodHRwczovL2FmZi5zZW5kaHViLnBsLyJd'),
  2131. fromB64('YVtocmVmXj0iaHR0cDovL2Fkdm1hbmFnZXIudGVjaGZ1bi5wbC9yZWRpcmVjdC8iXQ=='),
  2132. fromB64('YVtocmVmXj0iaHR0cDovL3d3dy50cml6ZXIucGwvP3V0bV9zb3VyY2UiXQ=='),
  2133. fromB64('ZGl2I3NrYXBpZWNfYWQ='),
  2134. ],
  2135. ro: [
  2136. fromB64('YVtocmVmXj0iLy9hZmZ0cmsuYWx0ZXgucm8vQ291bnRlci9DbGljayJd'),
  2137. fromB64('YVtocmVmXj0iaHR0cHM6Ly9ibGFja2ZyaWRheXNhbGVzLnJvL3Ryay9zaG9wLyJd'),
  2138. fromB64('YVtocmVmXj0iaHR0cHM6Ly9ldmVudC4ycGVyZm9ybWFudC5jb20vZXZlbnRzL2NsaWNrIl0='),
  2139. fromB64('YVtocmVmXj0iaHR0cHM6Ly9sLnByb2ZpdHNoYXJlLnJvLyJd'),
  2140. 'a[href^="/url/"]',
  2141. ],
  2142. ruAd: [
  2143. fromB64('YVtocmVmKj0iLy9mZWJyYXJlLnJ1LyJd'),
  2144. fromB64('YVtocmVmKj0iLy91dGltZy5ydS8iXQ=='),
  2145. fromB64('YVtocmVmKj0iOi8vY2hpa2lkaWtpLnJ1Il0='),
  2146. '#pgeldiz',
  2147. '.yandex-rtb-block',
  2148. ],
  2149. thaiAds: [
  2150. 'a[href*=macau-uta-popup]',
  2151. fromB64('I2Fkcy1nb29nbGUtbWlkZGxlX3JlY3RhbmdsZS1ncm91cA=='),
  2152. fromB64('LmFkczMwMHM='),
  2153. '.bumq',
  2154. '.img-kosana',
  2155. ],
  2156. webAnnoyancesUltralist: [
  2157. '#mod-social-share-2',
  2158. '#social-tools',
  2159. fromB64('LmN0cGwtZnVsbGJhbm5lcg=='),
  2160. '.zergnet-recommend',
  2161. '.yt.btn-link.btn-md.btn',
  2162. ],
  2163. };
  2164. }
  2165. /**
  2166. * The order of the returned array means nothing (it's always sorted alphabetically).
  2167. *
  2168. * Notice that the source is slightly unstable.
  2169. * Safari provides a 2-taps way to disable all content blockers on a page temporarily.
  2170. * Also content blockers can be disabled permanently for a domain, but it requires 4 taps.
  2171. * So empty array shouldn't be treated as "no blockers", it should be treated as "no signal".
  2172. * If you are a website owner, don't make your visitors want to disable content blockers.
  2173. */
  2174. function getDomBlockers(_a) {
  2175. var _b = _a === void 0 ? {} : _a, debug = _b.debug;
  2176. return tslib.__awaiter(this, void 0, void 0, function () {
  2177. var filters, filterNames, allSelectors, blockedSelectors, activeBlockers;
  2178. var _c;
  2179. return tslib.__generator(this, function (_d) {
  2180. switch (_d.label) {
  2181. case 0:
  2182. if (!isApplicable()) {
  2183. return [2 /*return*/, undefined];
  2184. }
  2185. filters = getFilters();
  2186. filterNames = Object.keys(filters);
  2187. allSelectors = (_c = []).concat.apply(_c, filterNames.map(function (filterName) { return filters[filterName]; }));
  2188. return [4 /*yield*/, getBlockedSelectors(allSelectors)];
  2189. case 1:
  2190. blockedSelectors = _d.sent();
  2191. if (debug) {
  2192. printDebug(filters, blockedSelectors);
  2193. }
  2194. activeBlockers = filterNames.filter(function (filterName) {
  2195. var selectors = filters[filterName];
  2196. var blockedCount = countTruthy(selectors.map(function (selector) { return blockedSelectors[selector]; }));
  2197. return blockedCount > selectors.length * 0.6;
  2198. });
  2199. activeBlockers.sort();
  2200. return [2 /*return*/, activeBlockers];
  2201. }
  2202. });
  2203. });
  2204. }
  2205. function isApplicable() {
  2206. // Safari (desktop and mobile) and all Android browsers keep content blockers in both regular and private mode
  2207. return isWebKit() || isAndroid();
  2208. }
  2209. function getBlockedSelectors(selectors) {
  2210. var _a;
  2211. return tslib.__awaiter(this, void 0, void 0, function () {
  2212. var d, root, elements, blockedSelectors, i, element, holder, i;
  2213. return tslib.__generator(this, function (_b) {
  2214. switch (_b.label) {
  2215. case 0:
  2216. d = document;
  2217. root = d.createElement('div');
  2218. elements = new Array(selectors.length);
  2219. blockedSelectors = {} // Set() isn't used just in case somebody need older browser support
  2220. ;
  2221. forceShow(root);
  2222. // First create all elements that can be blocked. If the DOM steps below are done in a single cycle,
  2223. // browser will alternate tree modification and layout reading, that is very slow.
  2224. for (i = 0; i < selectors.length; ++i) {
  2225. element = selectorToElement(selectors[i]);
  2226. if (element.tagName === 'DIALOG') {
  2227. element.show();
  2228. }
  2229. holder = d.createElement('div') // Protects from unwanted effects of `+` and `~` selectors of filters
  2230. ;
  2231. forceShow(holder);
  2232. holder.appendChild(element);
  2233. root.appendChild(holder);
  2234. elements[i] = element;
  2235. }
  2236. _b.label = 1;
  2237. case 1:
  2238. if (!!d.body) return [3 /*break*/, 3];
  2239. return [4 /*yield*/, wait(50)];
  2240. case 2:
  2241. _b.sent();
  2242. return [3 /*break*/, 1];
  2243. case 3:
  2244. d.body.appendChild(root);
  2245. try {
  2246. // Then check which of the elements are blocked
  2247. for (i = 0; i < selectors.length; ++i) {
  2248. if (!elements[i].offsetParent) {
  2249. blockedSelectors[selectors[i]] = true;
  2250. }
  2251. }
  2252. }
  2253. finally {
  2254. // Then remove the elements
  2255. (_a = root.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(root);
  2256. }
  2257. return [2 /*return*/, blockedSelectors];
  2258. }
  2259. });
  2260. });
  2261. }
  2262. function forceShow(element) {
  2263. element.style.setProperty('visibility', 'hidden', 'important');
  2264. element.style.setProperty('display', 'block', 'important');
  2265. }
  2266. function printDebug(filters, blockedSelectors) {
  2267. var message = 'DOM blockers debug:\n```';
  2268. for (var _i = 0, _a = Object.keys(filters); _i < _a.length; _i++) {
  2269. var filterName = _a[_i];
  2270. message += "\n".concat(filterName, ":");
  2271. for (var _b = 0, _c = filters[filterName]; _b < _c.length; _b++) {
  2272. var selector = _c[_b];
  2273. message += "\n ".concat(blockedSelectors[selector] ? '🚫' : '➡️', " ").concat(selector);
  2274. }
  2275. }
  2276. // console.log is ok here because it's under a debug clause
  2277. // eslint-disable-next-line no-console
  2278. console.log("".concat(message, "\n```"));
  2279. }
  2280. /**
  2281. * @see https://developer.mozilla.org/en-US/docs/Web/CSS/@media/color-gamut
  2282. */
  2283. function getColorGamut() {
  2284. // rec2020 includes p3 and p3 includes srgb
  2285. for (var _i = 0, _a = ['rec2020', 'p3', 'srgb']; _i < _a.length; _i++) {
  2286. var gamut = _a[_i];
  2287. if (matchMedia("(color-gamut: ".concat(gamut, ")")).matches) {
  2288. return gamut;
  2289. }
  2290. }
  2291. return undefined;
  2292. }
  2293. /**
  2294. * @see https://developer.mozilla.org/en-US/docs/Web/CSS/@media/inverted-colors
  2295. */
  2296. function areColorsInverted() {
  2297. if (doesMatch$5('inverted')) {
  2298. return true;
  2299. }
  2300. if (doesMatch$5('none')) {
  2301. return false;
  2302. }
  2303. return undefined;
  2304. }
  2305. function doesMatch$5(value) {
  2306. return matchMedia("(inverted-colors: ".concat(value, ")")).matches;
  2307. }
  2308. /**
  2309. * @see https://developer.mozilla.org/en-US/docs/Web/CSS/@media/forced-colors
  2310. */
  2311. function areColorsForced() {
  2312. if (doesMatch$4('active')) {
  2313. return true;
  2314. }
  2315. if (doesMatch$4('none')) {
  2316. return false;
  2317. }
  2318. return undefined;
  2319. }
  2320. function doesMatch$4(value) {
  2321. return matchMedia("(forced-colors: ".concat(value, ")")).matches;
  2322. }
  2323. var maxValueToCheck = 100;
  2324. /**
  2325. * If the display is monochrome (e.g. black&white), the value will be ≥0 and will mean the number of bits per pixel.
  2326. * If the display is not monochrome, the returned value will be 0.
  2327. * If the browser doesn't support this feature, the returned value will be undefined.
  2328. *
  2329. * @see https://developer.mozilla.org/en-US/docs/Web/CSS/@media/monochrome
  2330. */
  2331. function getMonochromeDepth() {
  2332. if (!matchMedia('(min-monochrome: 0)').matches) {
  2333. // The media feature isn't supported by the browser
  2334. return undefined;
  2335. }
  2336. // A variation of binary search algorithm can be used here.
  2337. // But since expected values are very small (≤10), there is no sense in adding the complexity.
  2338. for (var i = 0; i <= maxValueToCheck; ++i) {
  2339. if (matchMedia("(max-monochrome: ".concat(i, ")")).matches) {
  2340. return i;
  2341. }
  2342. }
  2343. throw new Error('Too high value');
  2344. }
  2345. /**
  2346. * @see https://www.w3.org/TR/mediaqueries-5/#prefers-contrast
  2347. * @see https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-contrast
  2348. */
  2349. function getContrastPreference() {
  2350. if (doesMatch$3('no-preference')) {
  2351. return 0 /* ContrastPreference.None */;
  2352. }
  2353. // The sources contradict on the keywords. Probably 'high' and 'low' will never be implemented.
  2354. // Need to check it when all browsers implement the feature.
  2355. if (doesMatch$3('high') || doesMatch$3('more')) {
  2356. return 1 /* ContrastPreference.More */;
  2357. }
  2358. if (doesMatch$3('low') || doesMatch$3('less')) {
  2359. return -1 /* ContrastPreference.Less */;
  2360. }
  2361. if (doesMatch$3('forced')) {
  2362. return 10 /* ContrastPreference.ForcedColors */;
  2363. }
  2364. return undefined;
  2365. }
  2366. function doesMatch$3(value) {
  2367. return matchMedia("(prefers-contrast: ".concat(value, ")")).matches;
  2368. }
  2369. /**
  2370. * @see https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-motion
  2371. */
  2372. function isMotionReduced() {
  2373. if (doesMatch$2('reduce')) {
  2374. return true;
  2375. }
  2376. if (doesMatch$2('no-preference')) {
  2377. return false;
  2378. }
  2379. return undefined;
  2380. }
  2381. function doesMatch$2(value) {
  2382. return matchMedia("(prefers-reduced-motion: ".concat(value, ")")).matches;
  2383. }
  2384. /**
  2385. * @see https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-transparency
  2386. */
  2387. function isTransparencyReduced() {
  2388. if (doesMatch$1('reduce')) {
  2389. return true;
  2390. }
  2391. if (doesMatch$1('no-preference')) {
  2392. return false;
  2393. }
  2394. return undefined;
  2395. }
  2396. function doesMatch$1(value) {
  2397. return matchMedia("(prefers-reduced-transparency: ".concat(value, ")")).matches;
  2398. }
  2399. /**
  2400. * @see https://www.w3.org/TR/mediaqueries-5/#dynamic-range
  2401. */
  2402. function isHDR() {
  2403. if (doesMatch('high')) {
  2404. return true;
  2405. }
  2406. if (doesMatch('standard')) {
  2407. return false;
  2408. }
  2409. return undefined;
  2410. }
  2411. function doesMatch(value) {
  2412. return matchMedia("(dynamic-range: ".concat(value, ")")).matches;
  2413. }
  2414. var M = Math; // To reduce the minified code size
  2415. var fallbackFn = function () { return 0; };
  2416. /**
  2417. * @see https://gitlab.torproject.org/legacy/trac/-/issues/13018
  2418. * @see https://bugzilla.mozilla.org/show_bug.cgi?id=531915
  2419. */
  2420. function getMathFingerprint() {
  2421. // Native operations
  2422. var acos = M.acos || fallbackFn;
  2423. var acosh = M.acosh || fallbackFn;
  2424. var asin = M.asin || fallbackFn;
  2425. var asinh = M.asinh || fallbackFn;
  2426. var atanh = M.atanh || fallbackFn;
  2427. var atan = M.atan || fallbackFn;
  2428. var sin = M.sin || fallbackFn;
  2429. var sinh = M.sinh || fallbackFn;
  2430. var cos = M.cos || fallbackFn;
  2431. var cosh = M.cosh || fallbackFn;
  2432. var tan = M.tan || fallbackFn;
  2433. var tanh = M.tanh || fallbackFn;
  2434. var exp = M.exp || fallbackFn;
  2435. var expm1 = M.expm1 || fallbackFn;
  2436. var log1p = M.log1p || fallbackFn;
  2437. // Operation polyfills
  2438. var powPI = function (value) { return M.pow(M.PI, value); };
  2439. var acoshPf = function (value) { return M.log(value + M.sqrt(value * value - 1)); };
  2440. var asinhPf = function (value) { return M.log(value + M.sqrt(value * value + 1)); };
  2441. var atanhPf = function (value) { return M.log((1 + value) / (1 - value)) / 2; };
  2442. var sinhPf = function (value) { return M.exp(value) - 1 / M.exp(value) / 2; };
  2443. var coshPf = function (value) { return (M.exp(value) + 1 / M.exp(value)) / 2; };
  2444. var expm1Pf = function (value) { return M.exp(value) - 1; };
  2445. var tanhPf = function (value) { return (M.exp(2 * value) - 1) / (M.exp(2 * value) + 1); };
  2446. var log1pPf = function (value) { return M.log(1 + value); };
  2447. // Note: constant values are empirical
  2448. return {
  2449. acos: acos(0.123124234234234242),
  2450. acosh: acosh(1e308),
  2451. acoshPf: acoshPf(1e154),
  2452. asin: asin(0.123124234234234242),
  2453. asinh: asinh(1),
  2454. asinhPf: asinhPf(1),
  2455. atanh: atanh(0.5),
  2456. atanhPf: atanhPf(0.5),
  2457. atan: atan(0.5),
  2458. sin: sin(-1e300),
  2459. sinh: sinh(1),
  2460. sinhPf: sinhPf(1),
  2461. cos: cos(10.000000000123),
  2462. cosh: cosh(1),
  2463. coshPf: coshPf(1),
  2464. tan: tan(-1e300),
  2465. tanh: tanh(1),
  2466. tanhPf: tanhPf(1),
  2467. exp: exp(1),
  2468. expm1: expm1(1),
  2469. expm1Pf: expm1Pf(1),
  2470. log1p: log1p(10),
  2471. log1pPf: log1pPf(10),
  2472. powPI: powPI(-100),
  2473. };
  2474. }
  2475. /**
  2476. * We use m or w because these two characters take up the maximum width.
  2477. * Also there are a couple of ligatures.
  2478. */
  2479. var defaultText = 'mmMwWLliI0fiflO&1';
  2480. /**
  2481. * Settings of text blocks to measure. The keys are random but persistent words.
  2482. */
  2483. var presets = {
  2484. /**
  2485. * The default font. User can change it in desktop Chrome, desktop Firefox, IE 11,
  2486. * Android Chrome (but only when the size is ≥ than the default) and Android Firefox.
  2487. */
  2488. default: [],
  2489. /** OS font on macOS. User can change its size and weight. Applies after Safari restart. */
  2490. apple: [{ font: '-apple-system-body' }],
  2491. /** User can change it in desktop Chrome and desktop Firefox. */
  2492. serif: [{ fontFamily: 'serif' }],
  2493. /** User can change it in desktop Chrome and desktop Firefox. */
  2494. sans: [{ fontFamily: 'sans-serif' }],
  2495. /** User can change it in desktop Chrome and desktop Firefox. */
  2496. mono: [{ fontFamily: 'monospace' }],
  2497. /**
  2498. * Check the smallest allowed font size. User can change it in desktop Chrome, desktop Firefox and desktop Safari.
  2499. * The height can be 0 in Chrome on a retina display.
  2500. */
  2501. min: [{ fontSize: '1px' }],
  2502. /** Tells one OS from another in desktop Chrome. */
  2503. system: [{ fontFamily: 'system-ui' }],
  2504. };
  2505. /**
  2506. * The result is a dictionary of the width of the text samples.
  2507. * Heights aren't included because they give no extra entropy and are unstable.
  2508. *
  2509. * The result is very stable in IE 11, Edge 18 and Safari 14.
  2510. * The result changes when the OS pixel density changes in Chromium 87. The real pixel density is required to solve,
  2511. * but seems like it's impossible: https://stackoverflow.com/q/1713771/1118709.
  2512. * The "min" and the "mono" (only on Windows) value may change when the page is zoomed in Firefox 87.
  2513. */
  2514. function getFontPreferences() {
  2515. return withNaturalFonts(function (document, container) {
  2516. var elements = {};
  2517. var sizes = {};
  2518. // First create all elements to measure. If the DOM steps below are done in a single cycle,
  2519. // browser will alternate tree modification and layout reading, that is very slow.
  2520. for (var _i = 0, _a = Object.keys(presets); _i < _a.length; _i++) {
  2521. var key = _a[_i];
  2522. var _b = presets[key], _c = _b[0], style = _c === void 0 ? {} : _c, _d = _b[1], text = _d === void 0 ? defaultText : _d;
  2523. var element = document.createElement('span');
  2524. element.textContent = text;
  2525. element.style.whiteSpace = 'nowrap';
  2526. for (var _e = 0, _f = Object.keys(style); _e < _f.length; _e++) {
  2527. var name_1 = _f[_e];
  2528. var value = style[name_1];
  2529. if (value !== undefined) {
  2530. element.style[name_1] = value;
  2531. }
  2532. }
  2533. elements[key] = element;
  2534. container.append(document.createElement('br'), element);
  2535. }
  2536. // Then measure the created elements
  2537. for (var _g = 0, _h = Object.keys(presets); _g < _h.length; _g++) {
  2538. var key = _h[_g];
  2539. sizes[key] = elements[key].getBoundingClientRect().width;
  2540. }
  2541. return sizes;
  2542. });
  2543. }
  2544. /**
  2545. * Creates a DOM environment that provides the most natural font available, including Android OS font.
  2546. * Measurements of the elements are zoom-independent.
  2547. * Don't put a content to measure inside an absolutely positioned element.
  2548. */
  2549. function withNaturalFonts(action, containerWidthPx) {
  2550. if (containerWidthPx === void 0) { containerWidthPx = 4000; }
  2551. /*
  2552. * Requirements for Android Chrome to apply the system font size to a text inside an iframe:
  2553. * - The iframe mustn't have a `display: none;` style;
  2554. * - The text mustn't be positioned absolutely;
  2555. * - The text block must be wide enough.
  2556. * 2560px on some devices in portrait orientation for the biggest font size option (32px);
  2557. * - There must be much enough text to form a few lines (I don't know the exact numbers);
  2558. * - The text must have the `text-size-adjust: none` style. Otherwise the text will scale in "Desktop site" mode;
  2559. *
  2560. * Requirements for Android Firefox to apply the system font size to a text inside an iframe:
  2561. * - The iframe document must have a header: `<meta name="viewport" content="width=device-width, initial-scale=1" />`.
  2562. * The only way to set it is to use the `srcdoc` attribute of the iframe;
  2563. * - The iframe content must get loaded before adding extra content with JavaScript;
  2564. *
  2565. * https://example.com as the iframe target always inherits Android font settings so it can be used as a reference.
  2566. *
  2567. * Observations on how page zoom affects the measurements:
  2568. * - macOS Safari 11.1, 12.1, 13.1, 14.0: zoom reset + offsetWidth = 100% reliable;
  2569. * - macOS Safari 11.1, 12.1, 13.1, 14.0: zoom reset + getBoundingClientRect = 100% reliable;
  2570. * - macOS Safari 14.0: offsetWidth = 5% fluctuation;
  2571. * - macOS Safari 14.0: getBoundingClientRect = 5% fluctuation;
  2572. * - iOS Safari 9, 10, 11.0, 12.0: haven't found a way to zoom a page (pinch doesn't change layout);
  2573. * - iOS Safari 13.1, 14.0: zoom reset + offsetWidth = 100% reliable;
  2574. * - iOS Safari 13.1, 14.0: zoom reset + getBoundingClientRect = 100% reliable;
  2575. * - iOS Safari 14.0: offsetWidth = 100% reliable;
  2576. * - iOS Safari 14.0: getBoundingClientRect = 100% reliable;
  2577. * - Chrome 42, 65, 80, 87: zoom 1/devicePixelRatio + offsetWidth = 1px fluctuation;
  2578. * - Chrome 42, 65, 80, 87: zoom 1/devicePixelRatio + getBoundingClientRect = 100% reliable;
  2579. * - Chrome 87: offsetWidth = 1px fluctuation;
  2580. * - Chrome 87: getBoundingClientRect = 0.7px fluctuation;
  2581. * - Firefox 48, 51: offsetWidth = 10% fluctuation;
  2582. * - Firefox 48, 51: getBoundingClientRect = 10% fluctuation;
  2583. * - Firefox 52, 53, 57, 62, 66, 67, 68, 71, 75, 80, 84: offsetWidth = width 100% reliable, height 10% fluctuation;
  2584. * - Firefox 52, 53, 57, 62, 66, 67, 68, 71, 75, 80, 84: getBoundingClientRect = width 100% reliable, height 10%
  2585. * fluctuation;
  2586. * - Android Chrome 86: haven't found a way to zoom a page (pinch doesn't change layout);
  2587. * - Android Firefox 84: font size in accessibility settings changes all the CSS sizes, but offsetWidth and
  2588. * getBoundingClientRect keep measuring with regular units, so the size reflects the font size setting and doesn't
  2589. * fluctuate;
  2590. * - IE 11, Edge 18: zoom 1/devicePixelRatio + offsetWidth = 100% reliable;
  2591. * - IE 11, Edge 18: zoom 1/devicePixelRatio + getBoundingClientRect = reflects the zoom level;
  2592. * - IE 11, Edge 18: offsetWidth = 100% reliable;
  2593. * - IE 11, Edge 18: getBoundingClientRect = 100% reliable;
  2594. */
  2595. return withIframe(function (_, iframeWindow) {
  2596. var iframeDocument = iframeWindow.document;
  2597. var iframeBody = iframeDocument.body;
  2598. var bodyStyle = iframeBody.style;
  2599. bodyStyle.width = "".concat(containerWidthPx, "px");
  2600. bodyStyle.webkitTextSizeAdjust = bodyStyle.textSizeAdjust = 'none';
  2601. // See the big comment above
  2602. if (isChromium()) {
  2603. iframeBody.style.zoom = "".concat(1 / iframeWindow.devicePixelRatio);
  2604. }
  2605. else if (isWebKit()) {
  2606. iframeBody.style.zoom = 'reset';
  2607. }
  2608. // See the big comment above
  2609. var linesOfText = iframeDocument.createElement('div');
  2610. linesOfText.textContent = tslib.__spreadArray([], Array((containerWidthPx / 20) << 0), true).map(function () { return 'word'; }).join(' ');
  2611. iframeBody.appendChild(linesOfText);
  2612. return action(iframeDocument, iframeBody);
  2613. }, '<!doctype html><html><head><meta name="viewport" content="width=device-width, initial-scale=1">');
  2614. }
  2615. function isPdfViewerEnabled() {
  2616. return navigator.pdfViewerEnabled;
  2617. }
  2618. /**
  2619. * Unlike most other architectures, on x86/x86-64 when floating-point instructions
  2620. * have no NaN arguments, but produce NaN output, the output NaN has sign bit set.
  2621. * We use it to distinguish x86/x86-64 from other architectures, by doing subtraction
  2622. * of two infinities (must produce NaN per IEEE 754 standard).
  2623. *
  2624. * See https://codebrowser.bddppq.com/pytorch/pytorch/third_party/XNNPACK/src/init.c.html#79
  2625. */
  2626. function getArchitecture() {
  2627. var f = new Float32Array(1);
  2628. var u8 = new Uint8Array(f.buffer);
  2629. f[0] = Infinity;
  2630. f[0] = f[0] - f[0];
  2631. return u8[3];
  2632. }
  2633. /**
  2634. * The return type is a union instead of the enum, because it's too challenging to embed the const enum into another
  2635. * project. Turning it into a union is a simple and an elegant solution.
  2636. */
  2637. function getApplePayState() {
  2638. var ApplePaySession = window.ApplePaySession;
  2639. if (typeof (ApplePaySession === null || ApplePaySession === void 0 ? void 0 : ApplePaySession.canMakePayments) !== 'function') {
  2640. return -1 /* ApplePayState.NoAPI */;
  2641. }
  2642. if (willPrintConsoleError()) {
  2643. return -3 /* ApplePayState.NotAvailableInFrame */;
  2644. }
  2645. try {
  2646. return ApplePaySession.canMakePayments() ? 1 /* ApplePayState.Enabled */ : 0 /* ApplePayState.Disabled */;
  2647. }
  2648. catch (error) {
  2649. return getStateFromError(error);
  2650. }
  2651. }
  2652. /**
  2653. * Starting from Safari 15 calling `ApplePaySession.canMakePayments()` produces this error message when FingerprintJS
  2654. * runs in an iframe with a cross-origin parent page, and the iframe on that page has no allow="payment *" attribute:
  2655. * Feature policy 'Payment' check failed for element with origin 'https://example.com' and allow attribute ''.
  2656. * This function checks whether the error message is expected.
  2657. *
  2658. * We check for cross-origin parents, which is prone to false-positive results. Instead, we should check for allowed
  2659. * feature/permission, but we can't because none of these API works in Safari yet:
  2660. * navigator.permissions.query({ name: ‘payment' })
  2661. * navigator.permissions.query({ name: ‘payment-handler' })
  2662. * document.featurePolicy
  2663. */
  2664. var willPrintConsoleError = isAnyParentCrossOrigin;
  2665. function getStateFromError(error) {
  2666. // See full expected error messages in the test
  2667. if (error instanceof Error && error.name === 'InvalidAccessError' && /\bfrom\b.*\binsecure\b/i.test(error.message)) {
  2668. return -2 /* ApplePayState.NotAvailableInInsecureContext */;
  2669. }
  2670. throw error;
  2671. }
  2672. /**
  2673. * Checks whether the Safari's Privacy Preserving Ad Measurement setting is on.
  2674. * The setting is on when the value is not undefined.
  2675. * A.k.a. private click measurement, privacy-preserving ad attribution.
  2676. *
  2677. * Unfortunately, it doesn't work in mobile Safari.
  2678. * Probably, it will start working in mobile Safari or stop working in desktop Safari later.
  2679. * We've found no way to detect the setting state in mobile Safari. Help wanted.
  2680. *
  2681. * @see https://webkit.org/blog/11529/introducing-private-click-measurement-pcm/
  2682. * @see https://developer.apple.com/videos/play/wwdc2021/10033
  2683. */
  2684. function getPrivateClickMeasurement() {
  2685. var _a;
  2686. var link = document.createElement('a');
  2687. var sourceId = (_a = link.attributionSourceId) !== null && _a !== void 0 ? _a : link.attributionsourceid;
  2688. return sourceId === undefined ? undefined : String(sourceId);
  2689. }
  2690. /** WebGl context is not available */
  2691. var STATUS_NO_GL_CONTEXT = -1;
  2692. /** WebGL context `getParameter` method is not a function */
  2693. var STATUS_GET_PARAMETER_NOT_A_FUNCTION = -2;
  2694. var validContextParameters = new Set([
  2695. 10752, 2849, 2884, 2885, 2886, 2928, 2929, 2930, 2931, 2932, 2960, 2961, 2962, 2963, 2964, 2965, 2966, 2967, 2968,
  2696. 2978, 3024, 3042, 3088, 3089, 3106, 3107, 32773, 32777, 32777, 32823, 32824, 32936, 32937, 32938, 32939, 32968, 32969,
  2697. 32970, 32971, 3317, 33170, 3333, 3379, 3386, 33901, 33902, 34016, 34024, 34076, 3408, 3410, 3411, 3412, 3413, 3414,
  2698. 3415, 34467, 34816, 34817, 34818, 34819, 34877, 34921, 34930, 35660, 35661, 35724, 35738, 35739, 36003, 36004, 36005,
  2699. 36347, 36348, 36349, 37440, 37441, 37443, 7936, 7937, 7938,
  2700. // SAMPLE_ALPHA_TO_COVERAGE (32926) and SAMPLE_COVERAGE (32928) are excluded because they trigger a console warning
  2701. // in IE, Chrome ≤ 59 and Safari ≤ 13 and give no entropy.
  2702. ]);
  2703. var validExtensionParams = new Set([
  2704. 34047,
  2705. 35723,
  2706. 36063,
  2707. 34852,
  2708. 34853,
  2709. 34854,
  2710. 34229,
  2711. 36392,
  2712. 36795,
  2713. 38449, // MAX_VIEWS_OVR
  2714. ]);
  2715. var shaderTypes = ['FRAGMENT_SHADER', 'VERTEX_SHADER'];
  2716. var precisionTypes = ['LOW_FLOAT', 'MEDIUM_FLOAT', 'HIGH_FLOAT', 'LOW_INT', 'MEDIUM_INT', 'HIGH_INT'];
  2717. var rendererInfoExtensionName = 'WEBGL_debug_renderer_info';
  2718. var polygonModeExtensionName = 'WEBGL_polygon_mode';
  2719. /**
  2720. * Gets the basic and simple WebGL parameters
  2721. */
  2722. function getWebGlBasics(_a) {
  2723. var _b, _c, _d, _e, _f, _g;
  2724. var cache = _a.cache;
  2725. var gl = getWebGLContext(cache);
  2726. if (!gl) {
  2727. return STATUS_NO_GL_CONTEXT;
  2728. }
  2729. if (!isValidParameterGetter(gl)) {
  2730. return STATUS_GET_PARAMETER_NOT_A_FUNCTION;
  2731. }
  2732. var debugExtension = shouldAvoidDebugRendererInfo() ? null : gl.getExtension(rendererInfoExtensionName);
  2733. return {
  2734. version: ((_b = gl.getParameter(gl.VERSION)) === null || _b === void 0 ? void 0 : _b.toString()) || '',
  2735. vendor: ((_c = gl.getParameter(gl.VENDOR)) === null || _c === void 0 ? void 0 : _c.toString()) || '',
  2736. vendorUnmasked: debugExtension ? (_d = gl.getParameter(debugExtension.UNMASKED_VENDOR_WEBGL)) === null || _d === void 0 ? void 0 : _d.toString() : '',
  2737. renderer: ((_e = gl.getParameter(gl.RENDERER)) === null || _e === void 0 ? void 0 : _e.toString()) || '',
  2738. rendererUnmasked: debugExtension ? (_f = gl.getParameter(debugExtension.UNMASKED_RENDERER_WEBGL)) === null || _f === void 0 ? void 0 : _f.toString() : '',
  2739. shadingLanguageVersion: ((_g = gl.getParameter(gl.SHADING_LANGUAGE_VERSION)) === null || _g === void 0 ? void 0 : _g.toString()) || '',
  2740. };
  2741. }
  2742. /**
  2743. * Gets the advanced and massive WebGL parameters and extensions
  2744. */
  2745. function getWebGlExtensions(_a) {
  2746. var cache = _a.cache;
  2747. var gl = getWebGLContext(cache);
  2748. if (!gl) {
  2749. return STATUS_NO_GL_CONTEXT;
  2750. }
  2751. if (!isValidParameterGetter(gl)) {
  2752. return STATUS_GET_PARAMETER_NOT_A_FUNCTION;
  2753. }
  2754. var extensions = gl.getSupportedExtensions();
  2755. var contextAttributes = gl.getContextAttributes();
  2756. var unsupportedExtensions = [];
  2757. // Features
  2758. var attributes = [];
  2759. var parameters = [];
  2760. var extensionParameters = [];
  2761. var shaderPrecisions = [];
  2762. // Context attributes
  2763. if (contextAttributes) {
  2764. for (var _i = 0, _b = Object.keys(contextAttributes); _i < _b.length; _i++) {
  2765. var attributeName = _b[_i];
  2766. attributes.push("".concat(attributeName, "=").concat(contextAttributes[attributeName]));
  2767. }
  2768. }
  2769. // Context parameters
  2770. var constants = getConstantsFromPrototype(gl);
  2771. for (var _c = 0, constants_1 = constants; _c < constants_1.length; _c++) {
  2772. var constant = constants_1[_c];
  2773. var code = gl[constant];
  2774. parameters.push("".concat(constant, "=").concat(code).concat(validContextParameters.has(code) ? "=".concat(gl.getParameter(code)) : ''));
  2775. }
  2776. // Extension parameters
  2777. if (extensions) {
  2778. for (var _d = 0, extensions_1 = extensions; _d < extensions_1.length; _d++) {
  2779. var name_1 = extensions_1[_d];
  2780. if ((name_1 === rendererInfoExtensionName && shouldAvoidDebugRendererInfo()) ||
  2781. (name_1 === polygonModeExtensionName && shouldAvoidPolygonModeExtensions())) {
  2782. continue;
  2783. }
  2784. var extension = gl.getExtension(name_1);
  2785. if (!extension) {
  2786. unsupportedExtensions.push(name_1);
  2787. continue;
  2788. }
  2789. for (var _e = 0, _f = getConstantsFromPrototype(extension); _e < _f.length; _e++) {
  2790. var constant = _f[_e];
  2791. var code = extension[constant];
  2792. extensionParameters.push("".concat(constant, "=").concat(code).concat(validExtensionParams.has(code) ? "=".concat(gl.getParameter(code)) : ''));
  2793. }
  2794. }
  2795. }
  2796. // Shader precision
  2797. for (var _g = 0, shaderTypes_1 = shaderTypes; _g < shaderTypes_1.length; _g++) {
  2798. var shaderType = shaderTypes_1[_g];
  2799. for (var _h = 0, precisionTypes_1 = precisionTypes; _h < precisionTypes_1.length; _h++) {
  2800. var precisionType = precisionTypes_1[_h];
  2801. var shaderPrecision = getShaderPrecision(gl, shaderType, precisionType);
  2802. shaderPrecisions.push("".concat(shaderType, ".").concat(precisionType, "=").concat(shaderPrecision.join(',')));
  2803. }
  2804. }
  2805. // Postprocess
  2806. extensionParameters.sort();
  2807. parameters.sort();
  2808. return {
  2809. contextAttributes: attributes,
  2810. parameters: parameters,
  2811. shaderPrecisions: shaderPrecisions,
  2812. extensions: extensions,
  2813. extensionParameters: extensionParameters,
  2814. unsupportedExtensions: unsupportedExtensions,
  2815. };
  2816. }
  2817. /**
  2818. * This function usually takes the most time to execute in all the sources, therefore we cache its result.
  2819. *
  2820. * Warning for package users:
  2821. * This function is out of Semantic Versioning, i.e. can change unexpectedly. Usage is at your own risk.
  2822. */
  2823. function getWebGLContext(cache) {
  2824. if (cache.webgl) {
  2825. return cache.webgl.context;
  2826. }
  2827. var canvas = document.createElement('canvas');
  2828. var context;
  2829. canvas.addEventListener('webglCreateContextError', function () { return (context = undefined); });
  2830. for (var _i = 0, _a = ['webgl', 'experimental-webgl']; _i < _a.length; _i++) {
  2831. var type = _a[_i];
  2832. try {
  2833. context = canvas.getContext(type);
  2834. }
  2835. catch (_b) {
  2836. // Ok, continue
  2837. }
  2838. if (context) {
  2839. break;
  2840. }
  2841. }
  2842. cache.webgl = { context: context };
  2843. return context;
  2844. }
  2845. /**
  2846. * https://developer.mozilla.org/en-US/docs/Web/API/WebGLShaderPrecisionFormat
  2847. * https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/getShaderPrecisionFormat
  2848. * https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.12
  2849. */
  2850. function getShaderPrecision(gl, shaderType, precisionType) {
  2851. var shaderPrecision = gl.getShaderPrecisionFormat(gl[shaderType], gl[precisionType]);
  2852. return shaderPrecision ? [shaderPrecision.rangeMin, shaderPrecision.rangeMax, shaderPrecision.precision] : [];
  2853. }
  2854. function getConstantsFromPrototype(obj) {
  2855. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  2856. var keys = Object.keys(obj.__proto__);
  2857. return keys.filter(isConstantLike);
  2858. }
  2859. function isConstantLike(key) {
  2860. return typeof key === 'string' && !key.match(/[^A-Z0-9_x]/);
  2861. }
  2862. /**
  2863. * Some browsers print a console warning when the WEBGL_debug_renderer_info extension is requested.
  2864. * JS Agent aims to avoid printing messages to console, so we avoid this extension in that browsers.
  2865. */
  2866. function shouldAvoidDebugRendererInfo() {
  2867. return isGecko();
  2868. }
  2869. /**
  2870. * Some browsers print a console warning when the WEBGL_polygon_mode extension is requested.
  2871. * JS Agent aims to avoid printing messages to console, so we avoid this extension in that browsers.
  2872. */
  2873. function shouldAvoidPolygonModeExtensions() {
  2874. return isChromium() || isWebKit();
  2875. }
  2876. /**
  2877. * Some unknown browsers have no `getParameter` method
  2878. */
  2879. function isValidParameterGetter(gl) {
  2880. return typeof gl.getParameter === 'function';
  2881. }
  2882. function getAudioContextBaseLatency() {
  2883. // The signal emits warning in Chrome and Firefox, therefore it is enabled on Safari where it doesn't produce warning
  2884. // and on Android where it's less visible
  2885. var isAllowedPlatform = isAndroid() || isWebKit();
  2886. if (!isAllowedPlatform) {
  2887. return -2 /* SpecialFingerprint.Disabled */;
  2888. }
  2889. if (!window.AudioContext) {
  2890. return -1 /* SpecialFingerprint.NotSupported */;
  2891. }
  2892. var latency = new AudioContext().baseLatency;
  2893. if (latency === null || latency === undefined) {
  2894. return -1 /* SpecialFingerprint.NotSupported */;
  2895. }
  2896. if (!isFinite(latency)) {
  2897. return -3 /* SpecialFingerprint.NotFinite */;
  2898. }
  2899. return latency;
  2900. }
  2901. /**
  2902. * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/resolvedOptions
  2903. *
  2904. * The return type is a union instead of a const enum due to the difficulty of embedding const enums in other projects.
  2905. * This makes integration simpler and more elegant.
  2906. */
  2907. function getDateTimeLocale() {
  2908. if (!window.Intl) {
  2909. return -1 /* Status.IntlAPINotSupported */;
  2910. }
  2911. var DateTimeFormat = window.Intl.DateTimeFormat;
  2912. if (!DateTimeFormat) {
  2913. return -2 /* Status.DateTimeFormatNotSupported */;
  2914. }
  2915. var locale = DateTimeFormat().resolvedOptions().locale;
  2916. if (!locale && locale !== '') {
  2917. return -3 /* Status.LocaleNotAvailable */;
  2918. }
  2919. return locale;
  2920. }
  2921. /**
  2922. * The list of entropy sources used to make visitor identifiers.
  2923. *
  2924. * This value isn't restricted by Semantic Versioning, i.e. it may be changed without bumping minor or major version of
  2925. * this package.
  2926. *
  2927. * Note: Rollup and Webpack are smart enough to remove unused properties of this object during tree-shaking, so there is
  2928. * no need to export the sources individually.
  2929. */
  2930. var sources = {
  2931. // READ FIRST:
  2932. // See https://github.com/fingerprintjs/fingerprintjs/blob/master/contributing.md#how-to-add-an-entropy-source
  2933. // to learn how entropy source works and how to make your own.
  2934. // The sources run in this exact order.
  2935. // The asynchronous sources are at the start to run in parallel with other sources.
  2936. fonts: getFonts,
  2937. domBlockers: getDomBlockers,
  2938. fontPreferences: getFontPreferences,
  2939. audio: getAudioFingerprint,
  2940. screenFrame: getScreenFrame,
  2941. canvas: getCanvasFingerprint,
  2942. osCpu: getOsCpu,
  2943. languages: getLanguages,
  2944. colorDepth: getColorDepth,
  2945. deviceMemory: getDeviceMemory,
  2946. screenResolution: getScreenResolution,
  2947. hardwareConcurrency: getHardwareConcurrency,
  2948. timezone: getTimezone,
  2949. sessionStorage: getSessionStorage,
  2950. localStorage: getLocalStorage,
  2951. indexedDB: getIndexedDB,
  2952. openDatabase: getOpenDatabase,
  2953. cpuClass: getCpuClass,
  2954. platform: getPlatform,
  2955. plugins: getPlugins,
  2956. touchSupport: getTouchSupport,
  2957. vendor: getVendor,
  2958. vendorFlavors: getVendorFlavors,
  2959. cookiesEnabled: areCookiesEnabled,
  2960. colorGamut: getColorGamut,
  2961. invertedColors: areColorsInverted,
  2962. forcedColors: areColorsForced,
  2963. monochrome: getMonochromeDepth,
  2964. contrast: getContrastPreference,
  2965. reducedMotion: isMotionReduced,
  2966. reducedTransparency: isTransparencyReduced,
  2967. hdr: isHDR,
  2968. math: getMathFingerprint,
  2969. pdfViewerEnabled: isPdfViewerEnabled,
  2970. architecture: getArchitecture,
  2971. applePay: getApplePayState,
  2972. privateClickMeasurement: getPrivateClickMeasurement,
  2973. audioBaseLatency: getAudioContextBaseLatency,
  2974. dateTimeLocale: getDateTimeLocale,
  2975. // Some sources can affect other sources (e.g. WebGL can affect canvas), so it's important to run these sources
  2976. // after other sources.
  2977. webGlBasics: getWebGlBasics,
  2978. webGlExtensions: getWebGlExtensions,
  2979. };
  2980. /**
  2981. * Loads the built-in entropy sources.
  2982. * Returns a function that collects the entropy components to make the visitor identifier.
  2983. */
  2984. function loadBuiltinSources(options) {
  2985. return loadSources(sources, options, []);
  2986. }
  2987. var commentTemplate = '$ if upgrade to Pro: https://fpjs.dev/pro';
  2988. function getConfidence(components) {
  2989. var openConfidenceScore = getOpenConfidenceScore(components);
  2990. var proConfidenceScore = deriveProConfidenceScore(openConfidenceScore);
  2991. return { score: openConfidenceScore, comment: commentTemplate.replace(/\$/g, "".concat(proConfidenceScore)) };
  2992. }
  2993. function getOpenConfidenceScore(components) {
  2994. // In order to calculate the true probability of the visitor identifier being correct, we need to know the number of
  2995. // website visitors (the higher the number, the less the probability because the fingerprint entropy is limited).
  2996. // JS agent doesn't know the number of visitors, so we can only do an approximate assessment.
  2997. if (isAndroid()) {
  2998. return 0.4;
  2999. }
  3000. // Safari (mobile and desktop)
  3001. if (isWebKit()) {
  3002. return isDesktopWebKit() && !(isWebKit616OrNewer() && isSafariWebKit()) ? 0.5 : 0.3;
  3003. }
  3004. var platform = 'value' in components.platform ? components.platform.value : '';
  3005. // Windows
  3006. if (/^Win/.test(platform)) {
  3007. // The score is greater than on macOS because of the higher variety of devices running Windows.
  3008. // Chrome provides more entropy than Firefox according too
  3009. // https://netmarketshare.com/browser-market-share.aspx?options=%7B%22filter%22%3A%7B%22%24and%22%3A%5B%7B%22platform%22%3A%7B%22%24in%22%3A%5B%22Windows%22%5D%7D%7D%5D%7D%2C%22dateLabel%22%3A%22Trend%22%2C%22attributes%22%3A%22share%22%2C%22group%22%3A%22browser%22%2C%22sort%22%3A%7B%22share%22%3A-1%7D%2C%22id%22%3A%22browsersDesktop%22%2C%22dateInterval%22%3A%22Monthly%22%2C%22dateStart%22%3A%222019-11%22%2C%22dateEnd%22%3A%222020-10%22%2C%22segments%22%3A%22-1000%22%7D
  3010. // So we assign the same score to them.
  3011. return 0.6;
  3012. }
  3013. // macOS
  3014. if (/^Mac/.test(platform)) {
  3015. // Chrome provides more entropy than Safari and Safari provides more entropy than Firefox.
  3016. // Chrome is more popular than Safari and Safari is more popular than Firefox according to
  3017. // https://netmarketshare.com/browser-market-share.aspx?options=%7B%22filter%22%3A%7B%22%24and%22%3A%5B%7B%22platform%22%3A%7B%22%24in%22%3A%5B%22Mac%20OS%22%5D%7D%7D%5D%7D%2C%22dateLabel%22%3A%22Trend%22%2C%22attributes%22%3A%22share%22%2C%22group%22%3A%22browser%22%2C%22sort%22%3A%7B%22share%22%3A-1%7D%2C%22id%22%3A%22browsersDesktop%22%2C%22dateInterval%22%3A%22Monthly%22%2C%22dateStart%22%3A%222019-11%22%2C%22dateEnd%22%3A%222020-10%22%2C%22segments%22%3A%22-1000%22%7D
  3018. // So we assign the same score to them.
  3019. return 0.5;
  3020. }
  3021. // Another platform, e.g. a desktop Linux. It's rare, so it should be pretty unique.
  3022. return 0.7;
  3023. }
  3024. function deriveProConfidenceScore(openConfidenceScore) {
  3025. return round(0.99 + 0.01 * openConfidenceScore, 0.0001);
  3026. }
  3027. function componentsToCanonicalString(components) {
  3028. var result = '';
  3029. for (var _i = 0, _a = Object.keys(components).sort(); _i < _a.length; _i++) {
  3030. var componentKey = _a[_i];
  3031. var component = components[componentKey];
  3032. var value = 'error' in component ? 'error' : JSON.stringify(component.value);
  3033. result += "".concat(result ? '|' : '').concat(componentKey.replace(/([:|\\])/g, '\\$1'), ":").concat(value);
  3034. }
  3035. return result;
  3036. }
  3037. function componentsToDebugString(components) {
  3038. return JSON.stringify(components, function (_key, value) {
  3039. if (value instanceof Error) {
  3040. return errorToObject(value);
  3041. }
  3042. return value;
  3043. }, 2);
  3044. }
  3045. function hashComponents(components) {
  3046. return x64hash128(componentsToCanonicalString(components));
  3047. }
  3048. /**
  3049. * Makes a GetResult implementation that calculates the visitor id hash on demand.
  3050. * Designed for optimisation.
  3051. */
  3052. function makeLazyGetResult(components) {
  3053. var visitorIdCache;
  3054. // This function runs very fast, so there is no need to make it lazy
  3055. var confidence = getConfidence(components);
  3056. // A plain class isn't used because its getters and setters aren't enumerable.
  3057. return {
  3058. get visitorId() {
  3059. if (visitorIdCache === undefined) {
  3060. visitorIdCache = hashComponents(this.components);
  3061. }
  3062. return visitorIdCache;
  3063. },
  3064. set visitorId(visitorId) {
  3065. visitorIdCache = visitorId;
  3066. },
  3067. confidence: confidence,
  3068. components: components,
  3069. version: version,
  3070. };
  3071. }
  3072. /**
  3073. * A delay is required to ensure consistent entropy components.
  3074. * See https://github.com/fingerprintjs/fingerprintjs/issues/254
  3075. * and https://github.com/fingerprintjs/fingerprintjs/issues/307
  3076. * and https://github.com/fingerprintjs/fingerprintjs/commit/945633e7c5f67ae38eb0fea37349712f0e669b18
  3077. */
  3078. function prepareForSources(delayFallback) {
  3079. if (delayFallback === void 0) { delayFallback = 50; }
  3080. // A proper deadline is unknown. Let it be twice the fallback timeout so that both cases have the same average time.
  3081. return requestIdleCallbackIfAvailable(delayFallback, delayFallback * 2);
  3082. }
  3083. /**
  3084. * The function isn't exported from the index file to not allow to call it without `load()`.
  3085. * The hiding gives more freedom for future non-breaking updates.
  3086. *
  3087. * A factory function is used instead of a class to shorten the attribute names in the minified code.
  3088. * Native private class fields could've been used, but TypeScript doesn't allow them with `"target": "es5"`.
  3089. */
  3090. function makeAgent(getComponents, debug) {
  3091. var creationTime = Date.now();
  3092. return {
  3093. get: function (options) {
  3094. return tslib.__awaiter(this, void 0, void 0, function () {
  3095. var startTime, components, result;
  3096. return tslib.__generator(this, function (_a) {
  3097. switch (_a.label) {
  3098. case 0:
  3099. startTime = Date.now();
  3100. return [4 /*yield*/, getComponents()];
  3101. case 1:
  3102. components = _a.sent();
  3103. result = makeLazyGetResult(components);
  3104. if (debug || (options === null || options === void 0 ? void 0 : options.debug)) {
  3105. // console.log is ok here because it's under a debug clause
  3106. // eslint-disable-next-line no-console
  3107. console.log("Copy the text below to get the debug data:\n\n```\nversion: ".concat(result.version, "\nuserAgent: ").concat(navigator.userAgent, "\ntimeBetweenLoadAndGet: ").concat(startTime - creationTime, "\nvisitorId: ").concat(result.visitorId, "\ncomponents: ").concat(componentsToDebugString(components), "\n```"));
  3108. }
  3109. return [2 /*return*/, result];
  3110. }
  3111. });
  3112. });
  3113. },
  3114. };
  3115. }
  3116. /**
  3117. * Sends an unpersonalized AJAX request to collect installation statistics
  3118. */
  3119. function monitor() {
  3120. // The FingerprintJS CDN (https://github.com/fingerprintjs/cdn) replaces `window.__fpjs_d_m` with `true`
  3121. if (window.__fpjs_d_m || Math.random() >= 0.001) {
  3122. return;
  3123. }
  3124. try {
  3125. var request = new XMLHttpRequest();
  3126. request.open('get', "https://m1.openfpcdn.io/fingerprintjs/v".concat(version, "/npm-monitoring"), true);
  3127. request.send();
  3128. }
  3129. catch (error) {
  3130. // console.error is ok here because it's an unexpected error handler
  3131. // eslint-disable-next-line no-console
  3132. console.error(error);
  3133. }
  3134. }
  3135. /**
  3136. * Builds an instance of Agent and waits a delay required for a proper operation.
  3137. */
  3138. function load(options) {
  3139. var _a;
  3140. if (options === void 0) { options = {}; }
  3141. return tslib.__awaiter(this, void 0, void 0, function () {
  3142. var delayFallback, debug, getComponents;
  3143. return tslib.__generator(this, function (_b) {
  3144. switch (_b.label) {
  3145. case 0:
  3146. if ((_a = options.monitoring) !== null && _a !== void 0 ? _a : true) {
  3147. monitor();
  3148. }
  3149. delayFallback = options.delayFallback, debug = options.debug;
  3150. return [4 /*yield*/, prepareForSources(delayFallback)];
  3151. case 1:
  3152. _b.sent();
  3153. getComponents = loadBuiltinSources({ cache: {}, debug: debug });
  3154. return [2 /*return*/, makeAgent(getComponents, debug)];
  3155. }
  3156. });
  3157. });
  3158. }
  3159. // The default export is a syntax sugar (`import * as FP from '...' → import FP from '...'`).
  3160. // It should contain all the public exported values.
  3161. var index = { load: load, hashComponents: hashComponents, componentsToDebugString: componentsToDebugString };
  3162. // The exports below are for private usage. They may change unexpectedly. Use them at your own risk.
  3163. /** Not documented, out of Semantic Versioning, usage is at your own risk */
  3164. var murmurX64Hash128 = x64hash128;
  3165. exports.componentsToDebugString = componentsToDebugString;
  3166. exports.default = index;
  3167. exports.getFullscreenElement = getFullscreenElement;
  3168. exports.getUnstableAudioFingerprint = getUnstableAudioFingerprint;
  3169. exports.getUnstableCanvasFingerprint = getUnstableCanvasFingerprint;
  3170. exports.getUnstableScreenFrame = getUnstableScreenFrame;
  3171. exports.getUnstableScreenResolution = getUnstableScreenResolution;
  3172. exports.getWebGLContext = getWebGLContext;
  3173. exports.hashComponents = hashComponents;
  3174. exports.isAndroid = isAndroid;
  3175. exports.isChromium = isChromium;
  3176. exports.isDesktopWebKit = isDesktopWebKit;
  3177. exports.isEdgeHTML = isEdgeHTML;
  3178. exports.isGecko = isGecko;
  3179. exports.isSamsungInternet = isSamsungInternet;
  3180. exports.isTrident = isTrident;
  3181. exports.isWebKit = isWebKit;
  3182. exports.load = load;
  3183. exports.loadSources = loadSources;
  3184. exports.murmurX64Hash128 = murmurX64Hash128;
  3185. exports.prepareForSources = prepareForSources;
  3186. exports.sources = sources;
  3187. exports.transformSource = transformSource;
  3188. exports.withIframe = withIframe;