@authsignal/browser 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -0
- package/dist/cjs/index.js +3776 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/esm/index.js +3771 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/index.d.ts +51 -0
- package/package.json +47 -0
|
@@ -0,0 +1,3776 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
/******************************************************************************
|
|
6
|
+
Copyright (c) Microsoft Corporation.
|
|
7
|
+
|
|
8
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
9
|
+
purpose with or without fee is hereby granted.
|
|
10
|
+
|
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
12
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
13
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
14
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
15
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
16
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
17
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
18
|
+
***************************************************************************** */
|
|
19
|
+
|
|
20
|
+
var __assign = function() {
|
|
21
|
+
__assign = Object.assign || function __assign(t) {
|
|
22
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
23
|
+
s = arguments[i];
|
|
24
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
25
|
+
}
|
|
26
|
+
return t;
|
|
27
|
+
};
|
|
28
|
+
return __assign.apply(this, arguments);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
32
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
33
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
34
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
35
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
36
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
37
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function __generator(thisArg, body) {
|
|
42
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
43
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
44
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
45
|
+
function step(op) {
|
|
46
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
47
|
+
while (_) try {
|
|
48
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
49
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
50
|
+
switch (op[0]) {
|
|
51
|
+
case 0: case 1: t = op; break;
|
|
52
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
53
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
54
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
55
|
+
default:
|
|
56
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
57
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
58
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
59
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
60
|
+
if (t[2]) _.ops.pop();
|
|
61
|
+
_.trys.pop(); continue;
|
|
62
|
+
}
|
|
63
|
+
op = body.call(thisArg, _);
|
|
64
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
65
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** @deprecated */
|
|
70
|
+
function __spreadArrays() {
|
|
71
|
+
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
72
|
+
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
73
|
+
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
74
|
+
r[k] = a[j];
|
|
75
|
+
return r;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* FingerprintJS v3.3.3 - Copyright (c) FingerprintJS, Inc, 2022 (https://fingerprintjs.com)
|
|
80
|
+
* Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
|
|
81
|
+
*
|
|
82
|
+
* This software contains code from open-source projects:
|
|
83
|
+
* MurmurHash3 by Karan Lyons (https://github.com/karanlyons/murmurHash3.js)
|
|
84
|
+
*/
|
|
85
|
+
|
|
86
|
+
var version = "3.3.3";
|
|
87
|
+
|
|
88
|
+
function wait(durationMs, resolveWith) {
|
|
89
|
+
return new Promise(function (resolve) { return setTimeout(resolve, durationMs, resolveWith); });
|
|
90
|
+
}
|
|
91
|
+
function requestIdleCallbackIfAvailable(fallbackTimeout, deadlineTimeout) {
|
|
92
|
+
if (deadlineTimeout === void 0) { deadlineTimeout = Infinity; }
|
|
93
|
+
var requestIdleCallback = window.requestIdleCallback;
|
|
94
|
+
if (requestIdleCallback) {
|
|
95
|
+
// The function `requestIdleCallback` loses the binding to `window` here.
|
|
96
|
+
// `globalThis` isn't always equal `window` (see https://github.com/fingerprintjs/fingerprintjs/issues/683).
|
|
97
|
+
// Therefore, an error can occur. `call(window,` prevents the error.
|
|
98
|
+
return new Promise(function (resolve) { return requestIdleCallback.call(window, function () { return resolve(); }, { timeout: deadlineTimeout }); });
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
return wait(Math.min(fallbackTimeout, deadlineTimeout));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function isPromise(value) {
|
|
105
|
+
return value && typeof value.then === 'function';
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Calls a maybe asynchronous function without creating microtasks when the function is synchronous.
|
|
109
|
+
* Catches errors in both cases.
|
|
110
|
+
*
|
|
111
|
+
* If just you run a code like this:
|
|
112
|
+
* ```
|
|
113
|
+
* console.time('Action duration')
|
|
114
|
+
* await action()
|
|
115
|
+
* console.timeEnd('Action duration')
|
|
116
|
+
* ```
|
|
117
|
+
* The synchronous function time can be measured incorrectly because another microtask may run before the `await`
|
|
118
|
+
* returns the control back to the code.
|
|
119
|
+
*/
|
|
120
|
+
function awaitIfAsync(action, callback) {
|
|
121
|
+
try {
|
|
122
|
+
var returnedValue = action();
|
|
123
|
+
if (isPromise(returnedValue)) {
|
|
124
|
+
returnedValue.then(function (result) { return callback(true, result); }, function (error) { return callback(false, error); });
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
callback(true, returnedValue);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
callback(false, error);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* If you run many synchronous tasks without using this function, the JS main loop will be busy and asynchronous tasks
|
|
136
|
+
* (e.g. completing a network request, rendering the page) won't be able to happen.
|
|
137
|
+
* This function allows running many synchronous tasks such way that asynchronous tasks can run too in background.
|
|
138
|
+
*/
|
|
139
|
+
function forEachWithBreaks(items, callback, loopReleaseInterval) {
|
|
140
|
+
if (loopReleaseInterval === void 0) { loopReleaseInterval = 16; }
|
|
141
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
142
|
+
var lastLoopReleaseTime, i, now;
|
|
143
|
+
return __generator(this, function (_a) {
|
|
144
|
+
switch (_a.label) {
|
|
145
|
+
case 0:
|
|
146
|
+
lastLoopReleaseTime = Date.now();
|
|
147
|
+
i = 0;
|
|
148
|
+
_a.label = 1;
|
|
149
|
+
case 1:
|
|
150
|
+
if (!(i < items.length)) return [3 /*break*/, 4];
|
|
151
|
+
callback(items[i], i);
|
|
152
|
+
now = Date.now();
|
|
153
|
+
if (!(now >= lastLoopReleaseTime + loopReleaseInterval)) return [3 /*break*/, 3];
|
|
154
|
+
lastLoopReleaseTime = now;
|
|
155
|
+
// Allows asynchronous actions and microtasks to happen
|
|
156
|
+
return [4 /*yield*/, wait(0)];
|
|
157
|
+
case 2:
|
|
158
|
+
// Allows asynchronous actions and microtasks to happen
|
|
159
|
+
_a.sent();
|
|
160
|
+
_a.label = 3;
|
|
161
|
+
case 3:
|
|
162
|
+
++i;
|
|
163
|
+
return [3 /*break*/, 1];
|
|
164
|
+
case 4: return [2 /*return*/];
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/*
|
|
171
|
+
* Taken from https://github.com/karanlyons/murmurHash3.js/blob/a33d0723127e2e5415056c455f8aed2451ace208/murmurHash3.js
|
|
172
|
+
*/
|
|
173
|
+
//
|
|
174
|
+
// Given two 64bit ints (as an array of two 32bit ints) returns the two
|
|
175
|
+
// added together as a 64bit int (as an array of two 32bit ints).
|
|
176
|
+
//
|
|
177
|
+
function x64Add(m, n) {
|
|
178
|
+
m = [m[0] >>> 16, m[0] & 0xffff, m[1] >>> 16, m[1] & 0xffff];
|
|
179
|
+
n = [n[0] >>> 16, n[0] & 0xffff, n[1] >>> 16, n[1] & 0xffff];
|
|
180
|
+
var o = [0, 0, 0, 0];
|
|
181
|
+
o[3] += m[3] + n[3];
|
|
182
|
+
o[2] += o[3] >>> 16;
|
|
183
|
+
o[3] &= 0xffff;
|
|
184
|
+
o[2] += m[2] + n[2];
|
|
185
|
+
o[1] += o[2] >>> 16;
|
|
186
|
+
o[2] &= 0xffff;
|
|
187
|
+
o[1] += m[1] + n[1];
|
|
188
|
+
o[0] += o[1] >>> 16;
|
|
189
|
+
o[1] &= 0xffff;
|
|
190
|
+
o[0] += m[0] + n[0];
|
|
191
|
+
o[0] &= 0xffff;
|
|
192
|
+
return [(o[0] << 16) | o[1], (o[2] << 16) | o[3]];
|
|
193
|
+
}
|
|
194
|
+
//
|
|
195
|
+
// Given two 64bit ints (as an array of two 32bit ints) returns the two
|
|
196
|
+
// multiplied together as a 64bit int (as an array of two 32bit ints).
|
|
197
|
+
//
|
|
198
|
+
function x64Multiply(m, n) {
|
|
199
|
+
m = [m[0] >>> 16, m[0] & 0xffff, m[1] >>> 16, m[1] & 0xffff];
|
|
200
|
+
n = [n[0] >>> 16, n[0] & 0xffff, n[1] >>> 16, n[1] & 0xffff];
|
|
201
|
+
var o = [0, 0, 0, 0];
|
|
202
|
+
o[3] += m[3] * n[3];
|
|
203
|
+
o[2] += o[3] >>> 16;
|
|
204
|
+
o[3] &= 0xffff;
|
|
205
|
+
o[2] += m[2] * n[3];
|
|
206
|
+
o[1] += o[2] >>> 16;
|
|
207
|
+
o[2] &= 0xffff;
|
|
208
|
+
o[2] += m[3] * n[2];
|
|
209
|
+
o[1] += o[2] >>> 16;
|
|
210
|
+
o[2] &= 0xffff;
|
|
211
|
+
o[1] += m[1] * n[3];
|
|
212
|
+
o[0] += o[1] >>> 16;
|
|
213
|
+
o[1] &= 0xffff;
|
|
214
|
+
o[1] += m[2] * n[2];
|
|
215
|
+
o[0] += o[1] >>> 16;
|
|
216
|
+
o[1] &= 0xffff;
|
|
217
|
+
o[1] += m[3] * n[1];
|
|
218
|
+
o[0] += o[1] >>> 16;
|
|
219
|
+
o[1] &= 0xffff;
|
|
220
|
+
o[0] += m[0] * n[3] + m[1] * n[2] + m[2] * n[1] + m[3] * n[0];
|
|
221
|
+
o[0] &= 0xffff;
|
|
222
|
+
return [(o[0] << 16) | o[1], (o[2] << 16) | o[3]];
|
|
223
|
+
}
|
|
224
|
+
//
|
|
225
|
+
// Given a 64bit int (as an array of two 32bit ints) and an int
|
|
226
|
+
// representing a number of bit positions, returns the 64bit int (as an
|
|
227
|
+
// array of two 32bit ints) rotated left by that number of positions.
|
|
228
|
+
//
|
|
229
|
+
function x64Rotl(m, n) {
|
|
230
|
+
n %= 64;
|
|
231
|
+
if (n === 32) {
|
|
232
|
+
return [m[1], m[0]];
|
|
233
|
+
}
|
|
234
|
+
else if (n < 32) {
|
|
235
|
+
return [(m[0] << n) | (m[1] >>> (32 - n)), (m[1] << n) | (m[0] >>> (32 - n))];
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
n -= 32;
|
|
239
|
+
return [(m[1] << n) | (m[0] >>> (32 - n)), (m[0] << n) | (m[1] >>> (32 - n))];
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
//
|
|
243
|
+
// Given a 64bit int (as an array of two 32bit ints) and an int
|
|
244
|
+
// representing a number of bit positions, returns the 64bit int (as an
|
|
245
|
+
// array of two 32bit ints) shifted left by that number of positions.
|
|
246
|
+
//
|
|
247
|
+
function x64LeftShift(m, n) {
|
|
248
|
+
n %= 64;
|
|
249
|
+
if (n === 0) {
|
|
250
|
+
return m;
|
|
251
|
+
}
|
|
252
|
+
else if (n < 32) {
|
|
253
|
+
return [(m[0] << n) | (m[1] >>> (32 - n)), m[1] << n];
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
return [m[1] << (n - 32), 0];
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
//
|
|
260
|
+
// Given two 64bit ints (as an array of two 32bit ints) returns the two
|
|
261
|
+
// xored together as a 64bit int (as an array of two 32bit ints).
|
|
262
|
+
//
|
|
263
|
+
function x64Xor(m, n) {
|
|
264
|
+
return [m[0] ^ n[0], m[1] ^ n[1]];
|
|
265
|
+
}
|
|
266
|
+
//
|
|
267
|
+
// Given a block, returns murmurHash3's final x64 mix of that block.
|
|
268
|
+
// (`[0, h[0] >>> 1]` is a 33 bit unsigned right shift. This is the
|
|
269
|
+
// only place where we need to right shift 64bit ints.)
|
|
270
|
+
//
|
|
271
|
+
function x64Fmix(h) {
|
|
272
|
+
h = x64Xor(h, [0, h[0] >>> 1]);
|
|
273
|
+
h = x64Multiply(h, [0xff51afd7, 0xed558ccd]);
|
|
274
|
+
h = x64Xor(h, [0, h[0] >>> 1]);
|
|
275
|
+
h = x64Multiply(h, [0xc4ceb9fe, 0x1a85ec53]);
|
|
276
|
+
h = x64Xor(h, [0, h[0] >>> 1]);
|
|
277
|
+
return h;
|
|
278
|
+
}
|
|
279
|
+
//
|
|
280
|
+
// Given a string and an optional seed as an int, returns a 128 bit
|
|
281
|
+
// hash using the x64 flavor of MurmurHash3, as an unsigned hex.
|
|
282
|
+
//
|
|
283
|
+
function x64hash128(key, seed) {
|
|
284
|
+
key = key || '';
|
|
285
|
+
seed = seed || 0;
|
|
286
|
+
var remainder = key.length % 16;
|
|
287
|
+
var bytes = key.length - remainder;
|
|
288
|
+
var h1 = [0, seed];
|
|
289
|
+
var h2 = [0, seed];
|
|
290
|
+
var k1 = [0, 0];
|
|
291
|
+
var k2 = [0, 0];
|
|
292
|
+
var c1 = [0x87c37b91, 0x114253d5];
|
|
293
|
+
var c2 = [0x4cf5ad43, 0x2745937f];
|
|
294
|
+
var i;
|
|
295
|
+
for (i = 0; i < bytes; i = i + 16) {
|
|
296
|
+
k1 = [
|
|
297
|
+
(key.charCodeAt(i + 4) & 0xff) |
|
|
298
|
+
((key.charCodeAt(i + 5) & 0xff) << 8) |
|
|
299
|
+
((key.charCodeAt(i + 6) & 0xff) << 16) |
|
|
300
|
+
((key.charCodeAt(i + 7) & 0xff) << 24),
|
|
301
|
+
(key.charCodeAt(i) & 0xff) |
|
|
302
|
+
((key.charCodeAt(i + 1) & 0xff) << 8) |
|
|
303
|
+
((key.charCodeAt(i + 2) & 0xff) << 16) |
|
|
304
|
+
((key.charCodeAt(i + 3) & 0xff) << 24),
|
|
305
|
+
];
|
|
306
|
+
k2 = [
|
|
307
|
+
(key.charCodeAt(i + 12) & 0xff) |
|
|
308
|
+
((key.charCodeAt(i + 13) & 0xff) << 8) |
|
|
309
|
+
((key.charCodeAt(i + 14) & 0xff) << 16) |
|
|
310
|
+
((key.charCodeAt(i + 15) & 0xff) << 24),
|
|
311
|
+
(key.charCodeAt(i + 8) & 0xff) |
|
|
312
|
+
((key.charCodeAt(i + 9) & 0xff) << 8) |
|
|
313
|
+
((key.charCodeAt(i + 10) & 0xff) << 16) |
|
|
314
|
+
((key.charCodeAt(i + 11) & 0xff) << 24),
|
|
315
|
+
];
|
|
316
|
+
k1 = x64Multiply(k1, c1);
|
|
317
|
+
k1 = x64Rotl(k1, 31);
|
|
318
|
+
k1 = x64Multiply(k1, c2);
|
|
319
|
+
h1 = x64Xor(h1, k1);
|
|
320
|
+
h1 = x64Rotl(h1, 27);
|
|
321
|
+
h1 = x64Add(h1, h2);
|
|
322
|
+
h1 = x64Add(x64Multiply(h1, [0, 5]), [0, 0x52dce729]);
|
|
323
|
+
k2 = x64Multiply(k2, c2);
|
|
324
|
+
k2 = x64Rotl(k2, 33);
|
|
325
|
+
k2 = x64Multiply(k2, c1);
|
|
326
|
+
h2 = x64Xor(h2, k2);
|
|
327
|
+
h2 = x64Rotl(h2, 31);
|
|
328
|
+
h2 = x64Add(h2, h1);
|
|
329
|
+
h2 = x64Add(x64Multiply(h2, [0, 5]), [0, 0x38495ab5]);
|
|
330
|
+
}
|
|
331
|
+
k1 = [0, 0];
|
|
332
|
+
k2 = [0, 0];
|
|
333
|
+
switch (remainder) {
|
|
334
|
+
case 15:
|
|
335
|
+
k2 = x64Xor(k2, x64LeftShift([0, key.charCodeAt(i + 14)], 48));
|
|
336
|
+
// fallthrough
|
|
337
|
+
case 14:
|
|
338
|
+
k2 = x64Xor(k2, x64LeftShift([0, key.charCodeAt(i + 13)], 40));
|
|
339
|
+
// fallthrough
|
|
340
|
+
case 13:
|
|
341
|
+
k2 = x64Xor(k2, x64LeftShift([0, key.charCodeAt(i + 12)], 32));
|
|
342
|
+
// fallthrough
|
|
343
|
+
case 12:
|
|
344
|
+
k2 = x64Xor(k2, x64LeftShift([0, key.charCodeAt(i + 11)], 24));
|
|
345
|
+
// fallthrough
|
|
346
|
+
case 11:
|
|
347
|
+
k2 = x64Xor(k2, x64LeftShift([0, key.charCodeAt(i + 10)], 16));
|
|
348
|
+
// fallthrough
|
|
349
|
+
case 10:
|
|
350
|
+
k2 = x64Xor(k2, x64LeftShift([0, key.charCodeAt(i + 9)], 8));
|
|
351
|
+
// fallthrough
|
|
352
|
+
case 9:
|
|
353
|
+
k2 = x64Xor(k2, [0, key.charCodeAt(i + 8)]);
|
|
354
|
+
k2 = x64Multiply(k2, c2);
|
|
355
|
+
k2 = x64Rotl(k2, 33);
|
|
356
|
+
k2 = x64Multiply(k2, c1);
|
|
357
|
+
h2 = x64Xor(h2, k2);
|
|
358
|
+
// fallthrough
|
|
359
|
+
case 8:
|
|
360
|
+
k1 = x64Xor(k1, x64LeftShift([0, key.charCodeAt(i + 7)], 56));
|
|
361
|
+
// fallthrough
|
|
362
|
+
case 7:
|
|
363
|
+
k1 = x64Xor(k1, x64LeftShift([0, key.charCodeAt(i + 6)], 48));
|
|
364
|
+
// fallthrough
|
|
365
|
+
case 6:
|
|
366
|
+
k1 = x64Xor(k1, x64LeftShift([0, key.charCodeAt(i + 5)], 40));
|
|
367
|
+
// fallthrough
|
|
368
|
+
case 5:
|
|
369
|
+
k1 = x64Xor(k1, x64LeftShift([0, key.charCodeAt(i + 4)], 32));
|
|
370
|
+
// fallthrough
|
|
371
|
+
case 4:
|
|
372
|
+
k1 = x64Xor(k1, x64LeftShift([0, key.charCodeAt(i + 3)], 24));
|
|
373
|
+
// fallthrough
|
|
374
|
+
case 3:
|
|
375
|
+
k1 = x64Xor(k1, x64LeftShift([0, key.charCodeAt(i + 2)], 16));
|
|
376
|
+
// fallthrough
|
|
377
|
+
case 2:
|
|
378
|
+
k1 = x64Xor(k1, x64LeftShift([0, key.charCodeAt(i + 1)], 8));
|
|
379
|
+
// fallthrough
|
|
380
|
+
case 1:
|
|
381
|
+
k1 = x64Xor(k1, [0, key.charCodeAt(i)]);
|
|
382
|
+
k1 = x64Multiply(k1, c1);
|
|
383
|
+
k1 = x64Rotl(k1, 31);
|
|
384
|
+
k1 = x64Multiply(k1, c2);
|
|
385
|
+
h1 = x64Xor(h1, k1);
|
|
386
|
+
// fallthrough
|
|
387
|
+
}
|
|
388
|
+
h1 = x64Xor(h1, [0, key.length]);
|
|
389
|
+
h2 = x64Xor(h2, [0, key.length]);
|
|
390
|
+
h1 = x64Add(h1, h2);
|
|
391
|
+
h2 = x64Add(h2, h1);
|
|
392
|
+
h1 = x64Fmix(h1);
|
|
393
|
+
h2 = x64Fmix(h2);
|
|
394
|
+
h1 = x64Add(h1, h2);
|
|
395
|
+
h2 = x64Add(h2, h1);
|
|
396
|
+
return (('00000000' + (h1[0] >>> 0).toString(16)).slice(-8) +
|
|
397
|
+
('00000000' + (h1[1] >>> 0).toString(16)).slice(-8) +
|
|
398
|
+
('00000000' + (h2[0] >>> 0).toString(16)).slice(-8) +
|
|
399
|
+
('00000000' + (h2[1] >>> 0).toString(16)).slice(-8));
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Converts an error object to a plain object that can be used with `JSON.stringify`.
|
|
404
|
+
* If you just run `JSON.stringify(error)`, you'll get `'{}'`.
|
|
405
|
+
*/
|
|
406
|
+
function errorToObject(error) {
|
|
407
|
+
var _a;
|
|
408
|
+
return __assign({ name: error.name, message: error.message, stack: (_a = error.stack) === null || _a === void 0 ? void 0 : _a.split('\n') }, error);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/*
|
|
412
|
+
* This file contains functions to work with pure data only (no browser features, DOM, side effects, etc).
|
|
413
|
+
*/
|
|
414
|
+
/**
|
|
415
|
+
* Does the same as Array.prototype.includes but has better typing
|
|
416
|
+
*/
|
|
417
|
+
function includes(haystack, needle) {
|
|
418
|
+
for (var i = 0, l = haystack.length; i < l; ++i) {
|
|
419
|
+
if (haystack[i] === needle) {
|
|
420
|
+
return true;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
return false;
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Like `!includes()` but with proper typing
|
|
427
|
+
*/
|
|
428
|
+
function excludes(haystack, needle) {
|
|
429
|
+
return !includes(haystack, needle);
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Be careful, NaN can return
|
|
433
|
+
*/
|
|
434
|
+
function toInt(value) {
|
|
435
|
+
return parseInt(value);
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* Be careful, NaN can return
|
|
439
|
+
*/
|
|
440
|
+
function toFloat(value) {
|
|
441
|
+
return parseFloat(value);
|
|
442
|
+
}
|
|
443
|
+
function replaceNaN(value, replacement) {
|
|
444
|
+
return typeof value === 'number' && isNaN(value) ? replacement : value;
|
|
445
|
+
}
|
|
446
|
+
function countTruthy(values) {
|
|
447
|
+
return values.reduce(function (sum, value) { return sum + (value ? 1 : 0); }, 0);
|
|
448
|
+
}
|
|
449
|
+
function round(value, base) {
|
|
450
|
+
if (base === void 0) { base = 1; }
|
|
451
|
+
if (Math.abs(base) >= 1) {
|
|
452
|
+
return Math.round(value / base) * base;
|
|
453
|
+
}
|
|
454
|
+
else {
|
|
455
|
+
// Sometimes when a number is multiplied by a small number, precision is lost,
|
|
456
|
+
// for example 1234 * 0.0001 === 0.12340000000000001, and it's more precise divide: 1234 / (1 / 0.0001) === 0.1234.
|
|
457
|
+
var counterBase = 1 / base;
|
|
458
|
+
return Math.round(value * counterBase) / counterBase;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Parses a CSS selector into tag name with HTML attributes.
|
|
463
|
+
* Only single element selector are supported (without operators like space, +, >, etc).
|
|
464
|
+
*
|
|
465
|
+
* Multiple values can be returned for each attribute. You decide how to handle them.
|
|
466
|
+
*/
|
|
467
|
+
function parseSimpleCssSelector(selector) {
|
|
468
|
+
var _a, _b;
|
|
469
|
+
var errorMessage = "Unexpected syntax '" + selector + "'";
|
|
470
|
+
var tagMatch = /^\s*([a-z-]*)(.*)$/i.exec(selector);
|
|
471
|
+
var tag = tagMatch[1] || undefined;
|
|
472
|
+
var attributes = {};
|
|
473
|
+
var partsRegex = /([.:#][\w-]+|\[.+?\])/gi;
|
|
474
|
+
var addAttribute = function (name, value) {
|
|
475
|
+
attributes[name] = attributes[name] || [];
|
|
476
|
+
attributes[name].push(value);
|
|
477
|
+
};
|
|
478
|
+
for (;;) {
|
|
479
|
+
var match = partsRegex.exec(tagMatch[2]);
|
|
480
|
+
if (!match) {
|
|
481
|
+
break;
|
|
482
|
+
}
|
|
483
|
+
var part = match[0];
|
|
484
|
+
switch (part[0]) {
|
|
485
|
+
case '.':
|
|
486
|
+
addAttribute('class', part.slice(1));
|
|
487
|
+
break;
|
|
488
|
+
case '#':
|
|
489
|
+
addAttribute('id', part.slice(1));
|
|
490
|
+
break;
|
|
491
|
+
case '[': {
|
|
492
|
+
var attributeMatch = /^\[([\w-]+)([~|^$*]?=("(.*?)"|([\w-]+)))?(\s+[is])?\]$/.exec(part);
|
|
493
|
+
if (attributeMatch) {
|
|
494
|
+
addAttribute(attributeMatch[1], (_b = (_a = attributeMatch[4]) !== null && _a !== void 0 ? _a : attributeMatch[5]) !== null && _b !== void 0 ? _b : '');
|
|
495
|
+
}
|
|
496
|
+
else {
|
|
497
|
+
throw new Error(errorMessage);
|
|
498
|
+
}
|
|
499
|
+
break;
|
|
500
|
+
}
|
|
501
|
+
default:
|
|
502
|
+
throw new Error(errorMessage);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
return [tag, attributes];
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
function ensureErrorWithMessage(error) {
|
|
509
|
+
return error && typeof error === 'object' && 'message' in error ? error : { message: error };
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* Loads the given entropy source. Returns a function that gets an entropy component from the source.
|
|
513
|
+
*
|
|
514
|
+
* The result is returned synchronously to prevent `loadSources` from
|
|
515
|
+
* waiting for one source to load before getting the components from the other sources.
|
|
516
|
+
*/
|
|
517
|
+
function loadSource(source, sourceOptions) {
|
|
518
|
+
var isFinalResultLoaded = function (loadResult) {
|
|
519
|
+
return typeof loadResult !== 'function';
|
|
520
|
+
};
|
|
521
|
+
var sourceLoadPromise = new Promise(function (resolveLoad) {
|
|
522
|
+
var loadStartTime = Date.now();
|
|
523
|
+
// `awaitIfAsync` is used instead of just `await` in order to measure the duration of synchronous sources
|
|
524
|
+
// correctly (other microtasks won't affect the duration).
|
|
525
|
+
awaitIfAsync(source.bind(null, sourceOptions), function () {
|
|
526
|
+
var loadArgs = [];
|
|
527
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
528
|
+
loadArgs[_i] = arguments[_i];
|
|
529
|
+
}
|
|
530
|
+
var loadDuration = Date.now() - loadStartTime;
|
|
531
|
+
// Source loading failed
|
|
532
|
+
if (!loadArgs[0]) {
|
|
533
|
+
return resolveLoad(function () { return ({ error: ensureErrorWithMessage(loadArgs[1]), duration: loadDuration }); });
|
|
534
|
+
}
|
|
535
|
+
var loadResult = loadArgs[1];
|
|
536
|
+
// Source loaded with the final result
|
|
537
|
+
if (isFinalResultLoaded(loadResult)) {
|
|
538
|
+
return resolveLoad(function () { return ({ value: loadResult, duration: loadDuration }); });
|
|
539
|
+
}
|
|
540
|
+
// Source loaded with "get" stage
|
|
541
|
+
resolveLoad(function () {
|
|
542
|
+
return new Promise(function (resolveGet) {
|
|
543
|
+
var getStartTime = Date.now();
|
|
544
|
+
awaitIfAsync(loadResult, function () {
|
|
545
|
+
var getArgs = [];
|
|
546
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
547
|
+
getArgs[_i] = arguments[_i];
|
|
548
|
+
}
|
|
549
|
+
var duration = loadDuration + Date.now() - getStartTime;
|
|
550
|
+
// Source getting failed
|
|
551
|
+
if (!getArgs[0]) {
|
|
552
|
+
return resolveGet({ error: ensureErrorWithMessage(getArgs[1]), duration: duration });
|
|
553
|
+
}
|
|
554
|
+
// Source getting succeeded
|
|
555
|
+
resolveGet({ value: getArgs[1], duration: duration });
|
|
556
|
+
});
|
|
557
|
+
});
|
|
558
|
+
});
|
|
559
|
+
});
|
|
560
|
+
});
|
|
561
|
+
return function getComponent() {
|
|
562
|
+
return sourceLoadPromise.then(function (finalizeSource) { return finalizeSource(); });
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
/**
|
|
566
|
+
* Loads the given entropy sources. Returns a function that collects the entropy components.
|
|
567
|
+
*
|
|
568
|
+
* The result is returned synchronously in order to allow start getting the components
|
|
569
|
+
* before the sources are loaded completely.
|
|
570
|
+
*
|
|
571
|
+
* Warning for package users:
|
|
572
|
+
* This function is out of Semantic Versioning, i.e. can change unexpectedly. Usage is at your own risk.
|
|
573
|
+
*/
|
|
574
|
+
function loadSources(sources, sourceOptions, excludeSources) {
|
|
575
|
+
var includedSources = Object.keys(sources).filter(function (sourceKey) { return excludes(excludeSources, sourceKey); });
|
|
576
|
+
var sourceGetters = Array(includedSources.length);
|
|
577
|
+
// Using `forEachWithBreaks` allows asynchronous sources to complete between synchronous sources
|
|
578
|
+
// and measure the duration correctly
|
|
579
|
+
forEachWithBreaks(includedSources, function (sourceKey, index) {
|
|
580
|
+
sourceGetters[index] = loadSource(sources[sourceKey], sourceOptions);
|
|
581
|
+
});
|
|
582
|
+
return function getComponents() {
|
|
583
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
584
|
+
var components, _i, includedSources_1, sourceKey, componentPromises, _loop_1, state_1;
|
|
585
|
+
return __generator(this, function (_a) {
|
|
586
|
+
switch (_a.label) {
|
|
587
|
+
case 0:
|
|
588
|
+
components = {};
|
|
589
|
+
for (_i = 0, includedSources_1 = includedSources; _i < includedSources_1.length; _i++) {
|
|
590
|
+
sourceKey = includedSources_1[_i];
|
|
591
|
+
components[sourceKey] = undefined;
|
|
592
|
+
}
|
|
593
|
+
componentPromises = Array(includedSources.length);
|
|
594
|
+
_loop_1 = function () {
|
|
595
|
+
var hasAllComponentPromises;
|
|
596
|
+
return __generator(this, function (_a) {
|
|
597
|
+
switch (_a.label) {
|
|
598
|
+
case 0:
|
|
599
|
+
hasAllComponentPromises = true;
|
|
600
|
+
return [4 /*yield*/, forEachWithBreaks(includedSources, function (sourceKey, index) {
|
|
601
|
+
if (!componentPromises[index]) {
|
|
602
|
+
// `sourceGetters` may be incomplete at this point of execution because `forEachWithBreaks` is asynchronous
|
|
603
|
+
if (sourceGetters[index]) {
|
|
604
|
+
componentPromises[index] = sourceGetters[index]().then(function (component) { return (components[sourceKey] = component); });
|
|
605
|
+
}
|
|
606
|
+
else {
|
|
607
|
+
hasAllComponentPromises = false;
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
})];
|
|
611
|
+
case 1:
|
|
612
|
+
_a.sent();
|
|
613
|
+
if (hasAllComponentPromises) {
|
|
614
|
+
return [2 /*return*/, "break"];
|
|
615
|
+
}
|
|
616
|
+
return [4 /*yield*/, wait(1)]; // Lets the source load loop continue
|
|
617
|
+
case 2:
|
|
618
|
+
_a.sent(); // Lets the source load loop continue
|
|
619
|
+
return [2 /*return*/];
|
|
620
|
+
}
|
|
621
|
+
});
|
|
622
|
+
};
|
|
623
|
+
_a.label = 1;
|
|
624
|
+
case 1: return [5 /*yield**/, _loop_1()];
|
|
625
|
+
case 2:
|
|
626
|
+
state_1 = _a.sent();
|
|
627
|
+
if (state_1 === "break")
|
|
628
|
+
return [3 /*break*/, 4];
|
|
629
|
+
_a.label = 3;
|
|
630
|
+
case 3: return [3 /*break*/, 1];
|
|
631
|
+
case 4: return [4 /*yield*/, Promise.all(componentPromises)];
|
|
632
|
+
case 5:
|
|
633
|
+
_a.sent();
|
|
634
|
+
return [2 /*return*/, components];
|
|
635
|
+
}
|
|
636
|
+
});
|
|
637
|
+
});
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
/*
|
|
642
|
+
* Functions to help with features that vary through browsers
|
|
643
|
+
*/
|
|
644
|
+
/**
|
|
645
|
+
* Checks whether the browser is based on Trident (the Internet Explorer engine) without using user-agent.
|
|
646
|
+
*
|
|
647
|
+
* Warning for package users:
|
|
648
|
+
* This function is out of Semantic Versioning, i.e. can change unexpectedly. Usage is at your own risk.
|
|
649
|
+
*/
|
|
650
|
+
function isTrident() {
|
|
651
|
+
var w = window;
|
|
652
|
+
var n = navigator;
|
|
653
|
+
// The properties are checked to be in IE 10, IE 11 and not to be in other browsers in October 2020
|
|
654
|
+
return (countTruthy([
|
|
655
|
+
'MSCSSMatrix' in w,
|
|
656
|
+
'msSetImmediate' in w,
|
|
657
|
+
'msIndexedDB' in w,
|
|
658
|
+
'msMaxTouchPoints' in n,
|
|
659
|
+
'msPointerEnabled' in n,
|
|
660
|
+
]) >= 4);
|
|
661
|
+
}
|
|
662
|
+
/**
|
|
663
|
+
* Checks whether the browser is based on EdgeHTML (the pre-Chromium Edge engine) without using user-agent.
|
|
664
|
+
*
|
|
665
|
+
* Warning for package users:
|
|
666
|
+
* This function is out of Semantic Versioning, i.e. can change unexpectedly. Usage is at your own risk.
|
|
667
|
+
*/
|
|
668
|
+
function isEdgeHTML() {
|
|
669
|
+
// Based on research in October 2020
|
|
670
|
+
var w = window;
|
|
671
|
+
var n = navigator;
|
|
672
|
+
return (countTruthy(['msWriteProfilerMark' in w, 'MSStream' in w, 'msLaunchUri' in n, 'msSaveBlob' in n]) >= 3 &&
|
|
673
|
+
!isTrident());
|
|
674
|
+
}
|
|
675
|
+
/**
|
|
676
|
+
* Checks whether the browser is based on Chromium without using user-agent.
|
|
677
|
+
*
|
|
678
|
+
* Warning for package users:
|
|
679
|
+
* This function is out of Semantic Versioning, i.e. can change unexpectedly. Usage is at your own risk.
|
|
680
|
+
*/
|
|
681
|
+
function isChromium() {
|
|
682
|
+
// Based on research in October 2020. Tested to detect Chromium 42-86.
|
|
683
|
+
var w = window;
|
|
684
|
+
var n = navigator;
|
|
685
|
+
return (countTruthy([
|
|
686
|
+
'webkitPersistentStorage' in n,
|
|
687
|
+
'webkitTemporaryStorage' in n,
|
|
688
|
+
n.vendor.indexOf('Google') === 0,
|
|
689
|
+
'webkitResolveLocalFileSystemURL' in w,
|
|
690
|
+
'BatteryManager' in w,
|
|
691
|
+
'webkitMediaStream' in w,
|
|
692
|
+
'webkitSpeechGrammar' in w,
|
|
693
|
+
]) >= 5);
|
|
694
|
+
}
|
|
695
|
+
/**
|
|
696
|
+
* Checks whether the browser is based on mobile or desktop Safari without using user-agent.
|
|
697
|
+
* All iOS browsers use WebKit (the Safari engine).
|
|
698
|
+
*
|
|
699
|
+
* Warning for package users:
|
|
700
|
+
* This function is out of Semantic Versioning, i.e. can change unexpectedly. Usage is at your own risk.
|
|
701
|
+
*/
|
|
702
|
+
function isWebKit() {
|
|
703
|
+
// Based on research in September 2020
|
|
704
|
+
var w = window;
|
|
705
|
+
var n = navigator;
|
|
706
|
+
return (countTruthy([
|
|
707
|
+
'ApplePayError' in w,
|
|
708
|
+
'CSSPrimitiveValue' in w,
|
|
709
|
+
'Counter' in w,
|
|
710
|
+
n.vendor.indexOf('Apple') === 0,
|
|
711
|
+
'getStorageUpdates' in n,
|
|
712
|
+
'WebKitMediaKeys' in w,
|
|
713
|
+
]) >= 4);
|
|
714
|
+
}
|
|
715
|
+
/**
|
|
716
|
+
* Checks whether the WebKit browser is a desktop Safari.
|
|
717
|
+
*
|
|
718
|
+
* Warning for package users:
|
|
719
|
+
* This function is out of Semantic Versioning, i.e. can change unexpectedly. Usage is at your own risk.
|
|
720
|
+
*/
|
|
721
|
+
function isDesktopSafari() {
|
|
722
|
+
var w = window;
|
|
723
|
+
return (countTruthy([
|
|
724
|
+
'safari' in w,
|
|
725
|
+
!('DeviceMotionEvent' in w),
|
|
726
|
+
!('ongestureend' in w),
|
|
727
|
+
!('standalone' in navigator),
|
|
728
|
+
]) >= 3);
|
|
729
|
+
}
|
|
730
|
+
/**
|
|
731
|
+
* Checks whether the browser is based on Gecko (Firefox engine) without using user-agent.
|
|
732
|
+
*
|
|
733
|
+
* Warning for package users:
|
|
734
|
+
* This function is out of Semantic Versioning, i.e. can change unexpectedly. Usage is at your own risk.
|
|
735
|
+
*/
|
|
736
|
+
function isGecko() {
|
|
737
|
+
var _a, _b;
|
|
738
|
+
var w = window;
|
|
739
|
+
// Based on research in September 2020
|
|
740
|
+
return (countTruthy([
|
|
741
|
+
'buildID' in navigator,
|
|
742
|
+
'MozAppearance' in ((_b = (_a = document.documentElement) === null || _a === void 0 ? void 0 : _a.style) !== null && _b !== void 0 ? _b : {}),
|
|
743
|
+
'onmozfullscreenchange' in w,
|
|
744
|
+
'mozInnerScreenX' in w,
|
|
745
|
+
'CSSMozDocumentRule' in w,
|
|
746
|
+
'CanvasCaptureMediaStream' in w,
|
|
747
|
+
]) >= 4);
|
|
748
|
+
}
|
|
749
|
+
/**
|
|
750
|
+
* Checks whether the browser is based on Chromium version ≥86 without using user-agent.
|
|
751
|
+
* It doesn't check that the browser is based on Chromium, there is a separate function for this.
|
|
752
|
+
*/
|
|
753
|
+
function isChromium86OrNewer() {
|
|
754
|
+
// Checked in Chrome 85 vs Chrome 86 both on desktop and Android
|
|
755
|
+
var w = window;
|
|
756
|
+
return (countTruthy([
|
|
757
|
+
!('MediaSettingsRange' in w),
|
|
758
|
+
'RTCEncodedAudioFrame' in w,
|
|
759
|
+
'' + w.Intl === '[object Intl]',
|
|
760
|
+
'' + w.Reflect === '[object Reflect]',
|
|
761
|
+
]) >= 3);
|
|
762
|
+
}
|
|
763
|
+
/**
|
|
764
|
+
* Checks whether the browser is based on WebKit version ≥606 (Safari ≥12) without using user-agent.
|
|
765
|
+
* It doesn't check that the browser is based on WebKit, there is a separate function for this.
|
|
766
|
+
*
|
|
767
|
+
* @link https://en.wikipedia.org/wiki/Safari_version_history#Release_history Safari-WebKit versions map
|
|
768
|
+
*/
|
|
769
|
+
function isWebKit606OrNewer() {
|
|
770
|
+
// Checked in Safari 9–14
|
|
771
|
+
var w = window;
|
|
772
|
+
return (countTruthy([
|
|
773
|
+
'DOMRectList' in w,
|
|
774
|
+
'RTCPeerConnectionIceEvent' in w,
|
|
775
|
+
'SVGGeometryElement' in w,
|
|
776
|
+
'ontransitioncancel' in w,
|
|
777
|
+
]) >= 3);
|
|
778
|
+
}
|
|
779
|
+
/**
|
|
780
|
+
* Checks whether the device is an iPad.
|
|
781
|
+
* It doesn't check that the engine is WebKit and that the WebKit isn't desktop.
|
|
782
|
+
*/
|
|
783
|
+
function isIPad() {
|
|
784
|
+
// Checked on:
|
|
785
|
+
// Safari on iPadOS (both mobile and desktop modes): 8, 11, 12, 13, 14
|
|
786
|
+
// Chrome on iPadOS (both mobile and desktop modes): 11, 12, 13, 14
|
|
787
|
+
// Safari on iOS (both mobile and desktop modes): 9, 10, 11, 12, 13, 14
|
|
788
|
+
// Chrome on iOS (both mobile and desktop modes): 9, 10, 11, 12, 13, 14
|
|
789
|
+
// Before iOS 13. Safari tampers the value in "request desktop site" mode since iOS 13.
|
|
790
|
+
if (navigator.platform === 'iPad') {
|
|
791
|
+
return true;
|
|
792
|
+
}
|
|
793
|
+
var s = screen;
|
|
794
|
+
var screenRatio = s.width / s.height;
|
|
795
|
+
return (countTruthy([
|
|
796
|
+
'MediaSource' in window,
|
|
797
|
+
!!Element.prototype.webkitRequestFullscreen,
|
|
798
|
+
// iPhone 4S that runs iOS 9 matches this. But it won't match the criteria above, so it won't be detected as iPad.
|
|
799
|
+
screenRatio > 0.65 && screenRatio < 1.53,
|
|
800
|
+
]) >= 2);
|
|
801
|
+
}
|
|
802
|
+
/**
|
|
803
|
+
* Warning for package users:
|
|
804
|
+
* This function is out of Semantic Versioning, i.e. can change unexpectedly. Usage is at your own risk.
|
|
805
|
+
*/
|
|
806
|
+
function getFullscreenElement() {
|
|
807
|
+
var d = document;
|
|
808
|
+
return d.fullscreenElement || d.msFullscreenElement || d.mozFullScreenElement || d.webkitFullscreenElement || null;
|
|
809
|
+
}
|
|
810
|
+
function exitFullscreen() {
|
|
811
|
+
var d = document;
|
|
812
|
+
// `call` is required because the function throws an error without a proper "this" context
|
|
813
|
+
return (d.exitFullscreen || d.msExitFullscreen || d.mozCancelFullScreen || d.webkitExitFullscreen).call(d);
|
|
814
|
+
}
|
|
815
|
+
/**
|
|
816
|
+
* Checks whether the device runs on Android without using user-agent.
|
|
817
|
+
*
|
|
818
|
+
* Warning for package users:
|
|
819
|
+
* This function is out of Semantic Versioning, i.e. can change unexpectedly. Usage is at your own risk.
|
|
820
|
+
*/
|
|
821
|
+
function isAndroid() {
|
|
822
|
+
var isItChromium = isChromium();
|
|
823
|
+
var isItGecko = isGecko();
|
|
824
|
+
// Only 2 browser engines are presented on Android.
|
|
825
|
+
// Actually, there is also Android 4.1 browser, but it's not worth detecting it at the moment.
|
|
826
|
+
if (!isItChromium && !isItGecko) {
|
|
827
|
+
return false;
|
|
828
|
+
}
|
|
829
|
+
var w = window;
|
|
830
|
+
// Chrome removes all words "Android" from `navigator` when desktop version is requested
|
|
831
|
+
// Firefox keeps "Android" in `navigator.appVersion` when desktop version is requested
|
|
832
|
+
return (countTruthy([
|
|
833
|
+
'onorientationchange' in w,
|
|
834
|
+
'orientation' in w,
|
|
835
|
+
isItChromium && !('SharedWorker' in w),
|
|
836
|
+
isItGecko && /android/i.test(navigator.appVersion),
|
|
837
|
+
]) >= 2);
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
/**
|
|
841
|
+
* A deep description: https://fingerprintjs.com/blog/audio-fingerprinting/
|
|
842
|
+
* Inspired by and based on https://github.com/cozylife/audio-fingerprint
|
|
843
|
+
*/
|
|
844
|
+
function getAudioFingerprint() {
|
|
845
|
+
var w = window;
|
|
846
|
+
var AudioContext = w.OfflineAudioContext || w.webkitOfflineAudioContext;
|
|
847
|
+
if (!AudioContext) {
|
|
848
|
+
return -2 /* NotSupported */;
|
|
849
|
+
}
|
|
850
|
+
// In some browsers, audio context always stays suspended unless the context is started in response to a user action
|
|
851
|
+
// (e.g. a click or a tap). It prevents audio fingerprint from being taken at an arbitrary moment of time.
|
|
852
|
+
// Such browsers are old and unpopular, so the audio fingerprinting is just skipped in them.
|
|
853
|
+
// See a similar case explanation at https://stackoverflow.com/questions/46363048/onaudioprocess-not-called-on-ios11#46534088
|
|
854
|
+
if (doesCurrentBrowserSuspendAudioContext()) {
|
|
855
|
+
return -1 /* KnownToSuspend */;
|
|
856
|
+
}
|
|
857
|
+
var hashFromIndex = 4500;
|
|
858
|
+
var hashToIndex = 5000;
|
|
859
|
+
var context = new AudioContext(1, hashToIndex, 44100);
|
|
860
|
+
var oscillator = context.createOscillator();
|
|
861
|
+
oscillator.type = 'triangle';
|
|
862
|
+
oscillator.frequency.value = 10000;
|
|
863
|
+
var compressor = context.createDynamicsCompressor();
|
|
864
|
+
compressor.threshold.value = -50;
|
|
865
|
+
compressor.knee.value = 40;
|
|
866
|
+
compressor.ratio.value = 12;
|
|
867
|
+
compressor.attack.value = 0;
|
|
868
|
+
compressor.release.value = 0.25;
|
|
869
|
+
oscillator.connect(compressor);
|
|
870
|
+
compressor.connect(context.destination);
|
|
871
|
+
oscillator.start(0);
|
|
872
|
+
var _a = startRenderingAudio(context), renderPromise = _a[0], finishRendering = _a[1];
|
|
873
|
+
var fingerprintPromise = renderPromise.then(function (buffer) { return getHash(buffer.getChannelData(0).subarray(hashFromIndex)); }, function (error) {
|
|
874
|
+
if (error.name === "timeout" /* Timeout */ || error.name === "suspended" /* Suspended */) {
|
|
875
|
+
return -3 /* Timeout */;
|
|
876
|
+
}
|
|
877
|
+
throw error;
|
|
878
|
+
});
|
|
879
|
+
// Suppresses the console error message in case when the fingerprint fails before requested
|
|
880
|
+
fingerprintPromise.catch(function () { return undefined; });
|
|
881
|
+
return function () {
|
|
882
|
+
finishRendering();
|
|
883
|
+
return fingerprintPromise;
|
|
884
|
+
};
|
|
885
|
+
}
|
|
886
|
+
/**
|
|
887
|
+
* Checks if the current browser is known to always suspend audio context
|
|
888
|
+
*/
|
|
889
|
+
function doesCurrentBrowserSuspendAudioContext() {
|
|
890
|
+
return isWebKit() && !isDesktopSafari() && !isWebKit606OrNewer();
|
|
891
|
+
}
|
|
892
|
+
/**
|
|
893
|
+
* Starts rendering the audio context.
|
|
894
|
+
* When the returned function is called, the render process starts finishing.
|
|
895
|
+
*/
|
|
896
|
+
function startRenderingAudio(context) {
|
|
897
|
+
var renderTryMaxCount = 3;
|
|
898
|
+
var renderRetryDelay = 500;
|
|
899
|
+
var runningMaxAwaitTime = 500;
|
|
900
|
+
var runningSufficientTime = 5000;
|
|
901
|
+
var finalize = function () { return undefined; };
|
|
902
|
+
var resultPromise = new Promise(function (resolve, reject) {
|
|
903
|
+
var isFinalized = false;
|
|
904
|
+
var renderTryCount = 0;
|
|
905
|
+
var startedRunningAt = 0;
|
|
906
|
+
context.oncomplete = function (event) { return resolve(event.renderedBuffer); };
|
|
907
|
+
var startRunningTimeout = function () {
|
|
908
|
+
setTimeout(function () { return reject(makeInnerError("timeout" /* Timeout */)); }, Math.min(runningMaxAwaitTime, startedRunningAt + runningSufficientTime - Date.now()));
|
|
909
|
+
};
|
|
910
|
+
var tryRender = function () {
|
|
911
|
+
try {
|
|
912
|
+
context.startRendering();
|
|
913
|
+
switch (context.state) {
|
|
914
|
+
case 'running':
|
|
915
|
+
startedRunningAt = Date.now();
|
|
916
|
+
if (isFinalized) {
|
|
917
|
+
startRunningTimeout();
|
|
918
|
+
}
|
|
919
|
+
break;
|
|
920
|
+
// Sometimes the audio context doesn't start after calling `startRendering` (in addition to the cases where
|
|
921
|
+
// audio context doesn't start at all). A known case is starting an audio context when the browser tab is in
|
|
922
|
+
// background on iPhone. Retries usually help in this case.
|
|
923
|
+
case 'suspended':
|
|
924
|
+
// The audio context can reject starting until the tab is in foreground. Long fingerprint duration
|
|
925
|
+
// in background isn't a problem, therefore the retry attempts don't count in background. It can lead to
|
|
926
|
+
// a situation when a fingerprint takes very long time and finishes successfully. FYI, the audio context
|
|
927
|
+
// can be suspended when `document.hidden === false` and start running after a retry.
|
|
928
|
+
if (!document.hidden) {
|
|
929
|
+
renderTryCount++;
|
|
930
|
+
}
|
|
931
|
+
if (isFinalized && renderTryCount >= renderTryMaxCount) {
|
|
932
|
+
reject(makeInnerError("suspended" /* Suspended */));
|
|
933
|
+
}
|
|
934
|
+
else {
|
|
935
|
+
setTimeout(tryRender, renderRetryDelay);
|
|
936
|
+
}
|
|
937
|
+
break;
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
catch (error) {
|
|
941
|
+
reject(error);
|
|
942
|
+
}
|
|
943
|
+
};
|
|
944
|
+
tryRender();
|
|
945
|
+
finalize = function () {
|
|
946
|
+
if (!isFinalized) {
|
|
947
|
+
isFinalized = true;
|
|
948
|
+
if (startedRunningAt > 0) {
|
|
949
|
+
startRunningTimeout();
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
};
|
|
953
|
+
});
|
|
954
|
+
return [resultPromise, finalize];
|
|
955
|
+
}
|
|
956
|
+
function getHash(signal) {
|
|
957
|
+
var hash = 0;
|
|
958
|
+
for (var i = 0; i < signal.length; ++i) {
|
|
959
|
+
hash += Math.abs(signal[i]);
|
|
960
|
+
}
|
|
961
|
+
return hash;
|
|
962
|
+
}
|
|
963
|
+
function makeInnerError(name) {
|
|
964
|
+
var error = new Error(name);
|
|
965
|
+
error.name = name;
|
|
966
|
+
return error;
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
/**
|
|
970
|
+
* Creates and keeps an invisible iframe while the given function runs.
|
|
971
|
+
* The given function is called when the iframe is loaded and has a body.
|
|
972
|
+
* The iframe allows to measure DOM sizes inside itself.
|
|
973
|
+
*
|
|
974
|
+
* Notice: passing an initial HTML code doesn't work in IE.
|
|
975
|
+
*
|
|
976
|
+
* Warning for package users:
|
|
977
|
+
* This function is out of Semantic Versioning, i.e. can change unexpectedly. Usage is at your own risk.
|
|
978
|
+
*/
|
|
979
|
+
function withIframe(action, initialHtml, domPollInterval) {
|
|
980
|
+
var _a, _b, _c;
|
|
981
|
+
if (domPollInterval === void 0) { domPollInterval = 50; }
|
|
982
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
983
|
+
var d, iframe;
|
|
984
|
+
return __generator(this, function (_d) {
|
|
985
|
+
switch (_d.label) {
|
|
986
|
+
case 0:
|
|
987
|
+
d = document;
|
|
988
|
+
_d.label = 1;
|
|
989
|
+
case 1:
|
|
990
|
+
if (!!d.body) return [3 /*break*/, 3];
|
|
991
|
+
return [4 /*yield*/, wait(domPollInterval)];
|
|
992
|
+
case 2:
|
|
993
|
+
_d.sent();
|
|
994
|
+
return [3 /*break*/, 1];
|
|
995
|
+
case 3:
|
|
996
|
+
iframe = d.createElement('iframe');
|
|
997
|
+
_d.label = 4;
|
|
998
|
+
case 4:
|
|
999
|
+
_d.trys.push([4, , 10, 11]);
|
|
1000
|
+
return [4 /*yield*/, new Promise(function (_resolve, _reject) {
|
|
1001
|
+
var isComplete = false;
|
|
1002
|
+
var resolve = function () {
|
|
1003
|
+
isComplete = true;
|
|
1004
|
+
_resolve();
|
|
1005
|
+
};
|
|
1006
|
+
var reject = function (error) {
|
|
1007
|
+
isComplete = true;
|
|
1008
|
+
_reject(error);
|
|
1009
|
+
};
|
|
1010
|
+
iframe.onload = resolve;
|
|
1011
|
+
iframe.onerror = reject;
|
|
1012
|
+
var style = iframe.style;
|
|
1013
|
+
style.setProperty('display', 'block', 'important'); // Required for browsers to calculate the layout
|
|
1014
|
+
style.position = 'absolute';
|
|
1015
|
+
style.top = '0';
|
|
1016
|
+
style.left = '0';
|
|
1017
|
+
style.visibility = 'hidden';
|
|
1018
|
+
if (initialHtml && 'srcdoc' in iframe) {
|
|
1019
|
+
iframe.srcdoc = initialHtml;
|
|
1020
|
+
}
|
|
1021
|
+
else {
|
|
1022
|
+
iframe.src = 'about:blank';
|
|
1023
|
+
}
|
|
1024
|
+
d.body.appendChild(iframe);
|
|
1025
|
+
// WebKit in WeChat doesn't fire the iframe's `onload` for some reason.
|
|
1026
|
+
// This code checks for the loading state manually.
|
|
1027
|
+
// See https://github.com/fingerprintjs/fingerprintjs/issues/645
|
|
1028
|
+
var checkReadyState = function () {
|
|
1029
|
+
var _a, _b;
|
|
1030
|
+
// The ready state may never become 'complete' in Firefox despite the 'load' event being fired.
|
|
1031
|
+
// So an infinite setTimeout loop can happen without this check.
|
|
1032
|
+
// See https://github.com/fingerprintjs/fingerprintjs/pull/716#issuecomment-986898796
|
|
1033
|
+
if (isComplete) {
|
|
1034
|
+
return;
|
|
1035
|
+
}
|
|
1036
|
+
// Make sure iframe.contentWindow and iframe.contentWindow.document are both loaded
|
|
1037
|
+
// The contentWindow.document can miss in JSDOM (https://github.com/jsdom/jsdom).
|
|
1038
|
+
if (((_b = (_a = iframe.contentWindow) === null || _a === void 0 ? void 0 : _a.document) === null || _b === void 0 ? void 0 : _b.readyState) === 'complete') {
|
|
1039
|
+
resolve();
|
|
1040
|
+
}
|
|
1041
|
+
else {
|
|
1042
|
+
setTimeout(checkReadyState, 10);
|
|
1043
|
+
}
|
|
1044
|
+
};
|
|
1045
|
+
checkReadyState();
|
|
1046
|
+
})];
|
|
1047
|
+
case 5:
|
|
1048
|
+
_d.sent();
|
|
1049
|
+
_d.label = 6;
|
|
1050
|
+
case 6:
|
|
1051
|
+
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];
|
|
1052
|
+
return [4 /*yield*/, wait(domPollInterval)];
|
|
1053
|
+
case 7:
|
|
1054
|
+
_d.sent();
|
|
1055
|
+
return [3 /*break*/, 6];
|
|
1056
|
+
case 8: return [4 /*yield*/, action(iframe, iframe.contentWindow)];
|
|
1057
|
+
case 9: return [2 /*return*/, _d.sent()];
|
|
1058
|
+
case 10:
|
|
1059
|
+
(_c = iframe.parentNode) === null || _c === void 0 ? void 0 : _c.removeChild(iframe);
|
|
1060
|
+
return [7 /*endfinally*/];
|
|
1061
|
+
case 11: return [2 /*return*/];
|
|
1062
|
+
}
|
|
1063
|
+
});
|
|
1064
|
+
});
|
|
1065
|
+
}
|
|
1066
|
+
/**
|
|
1067
|
+
* Creates a DOM element that matches the given selector.
|
|
1068
|
+
* Only single element selector are supported (without operators like space, +, >, etc).
|
|
1069
|
+
*/
|
|
1070
|
+
function selectorToElement(selector) {
|
|
1071
|
+
var _a = parseSimpleCssSelector(selector), tag = _a[0], attributes = _a[1];
|
|
1072
|
+
var element = document.createElement(tag !== null && tag !== void 0 ? tag : 'div');
|
|
1073
|
+
for (var _i = 0, _b = Object.keys(attributes); _i < _b.length; _i++) {
|
|
1074
|
+
var name_1 = _b[_i];
|
|
1075
|
+
var value = attributes[name_1].join(' ');
|
|
1076
|
+
// Changing the `style` attribute can cause a CSP error, therefore we change the `style.cssText` property.
|
|
1077
|
+
// https://github.com/fingerprintjs/fingerprintjs/issues/733
|
|
1078
|
+
if (name_1 === 'style') {
|
|
1079
|
+
addStyleString(element.style, value);
|
|
1080
|
+
}
|
|
1081
|
+
else {
|
|
1082
|
+
element.setAttribute(name_1, value);
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
return element;
|
|
1086
|
+
}
|
|
1087
|
+
/**
|
|
1088
|
+
* Adds CSS styles from a string in such a way that doesn't trigger a CSP warning (unsafe-inline or unsafe-eval)
|
|
1089
|
+
*/
|
|
1090
|
+
function addStyleString(style, source) {
|
|
1091
|
+
// We don't use `style.cssText` because browsers must block it when no `unsafe-eval` CSP is presented: https://csplite.com/csp145/#w3c_note
|
|
1092
|
+
// Even though the browsers ignore this standard, we don't use `cssText` just in case.
|
|
1093
|
+
for (var _i = 0, _a = source.split(';'); _i < _a.length; _i++) {
|
|
1094
|
+
var property = _a[_i];
|
|
1095
|
+
var match = /^\s*([\w-]+)\s*:\s*(.+?)(\s*!([\w-]+))?\s*$/.exec(property);
|
|
1096
|
+
if (match) {
|
|
1097
|
+
var name_2 = match[1], value = match[2], priority = match[4];
|
|
1098
|
+
style.setProperty(name_2, value, priority || ''); // The last argument can't be undefined in IE11
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
// We use m or w because these two characters take up the maximum width.
|
|
1104
|
+
// And we use a LLi so that the same matching fonts can get separated.
|
|
1105
|
+
var testString = 'mmMwWLliI0O&1';
|
|
1106
|
+
// We test using 48px font size, we may use any size. I guess larger the better.
|
|
1107
|
+
var textSize = '48px';
|
|
1108
|
+
// A font will be compared against all the three default fonts.
|
|
1109
|
+
// And if for any default fonts it doesn't match, then that font is available.
|
|
1110
|
+
var baseFonts = ['monospace', 'sans-serif', 'serif'];
|
|
1111
|
+
var fontList = [
|
|
1112
|
+
// This is android-specific font from "Roboto" family
|
|
1113
|
+
'sans-serif-thin',
|
|
1114
|
+
'ARNO PRO',
|
|
1115
|
+
'Agency FB',
|
|
1116
|
+
'Arabic Typesetting',
|
|
1117
|
+
'Arial Unicode MS',
|
|
1118
|
+
'AvantGarde Bk BT',
|
|
1119
|
+
'BankGothic Md BT',
|
|
1120
|
+
'Batang',
|
|
1121
|
+
'Bitstream Vera Sans Mono',
|
|
1122
|
+
'Calibri',
|
|
1123
|
+
'Century',
|
|
1124
|
+
'Century Gothic',
|
|
1125
|
+
'Clarendon',
|
|
1126
|
+
'EUROSTILE',
|
|
1127
|
+
'Franklin Gothic',
|
|
1128
|
+
'Futura Bk BT',
|
|
1129
|
+
'Futura Md BT',
|
|
1130
|
+
'GOTHAM',
|
|
1131
|
+
'Gill Sans',
|
|
1132
|
+
'HELV',
|
|
1133
|
+
'Haettenschweiler',
|
|
1134
|
+
'Helvetica Neue',
|
|
1135
|
+
'Humanst521 BT',
|
|
1136
|
+
'Leelawadee',
|
|
1137
|
+
'Letter Gothic',
|
|
1138
|
+
'Levenim MT',
|
|
1139
|
+
'Lucida Bright',
|
|
1140
|
+
'Lucida Sans',
|
|
1141
|
+
'Menlo',
|
|
1142
|
+
'MS Mincho',
|
|
1143
|
+
'MS Outlook',
|
|
1144
|
+
'MS Reference Specialty',
|
|
1145
|
+
'MS UI Gothic',
|
|
1146
|
+
'MT Extra',
|
|
1147
|
+
'MYRIAD PRO',
|
|
1148
|
+
'Marlett',
|
|
1149
|
+
'Meiryo UI',
|
|
1150
|
+
'Microsoft Uighur',
|
|
1151
|
+
'Minion Pro',
|
|
1152
|
+
'Monotype Corsiva',
|
|
1153
|
+
'PMingLiU',
|
|
1154
|
+
'Pristina',
|
|
1155
|
+
'SCRIPTINA',
|
|
1156
|
+
'Segoe UI Light',
|
|
1157
|
+
'Serifa',
|
|
1158
|
+
'SimHei',
|
|
1159
|
+
'Small Fonts',
|
|
1160
|
+
'Staccato222 BT',
|
|
1161
|
+
'TRAJAN PRO',
|
|
1162
|
+
'Univers CE 55 Medium',
|
|
1163
|
+
'Vrinda',
|
|
1164
|
+
'ZWAdobeF',
|
|
1165
|
+
];
|
|
1166
|
+
// kudos to http://www.lalit.org/lab/javascript-css-font-detect/
|
|
1167
|
+
function getFonts() {
|
|
1168
|
+
// Running the script in an iframe makes it not affect the page look and not be affected by the page CSS. See:
|
|
1169
|
+
// https://github.com/fingerprintjs/fingerprintjs/issues/592
|
|
1170
|
+
// https://github.com/fingerprintjs/fingerprintjs/issues/628
|
|
1171
|
+
return withIframe(function (_, _a) {
|
|
1172
|
+
var document = _a.document;
|
|
1173
|
+
var holder = document.body;
|
|
1174
|
+
holder.style.fontSize = textSize;
|
|
1175
|
+
// div to load spans for the default fonts and the fonts to detect
|
|
1176
|
+
var spansContainer = document.createElement('div');
|
|
1177
|
+
var defaultWidth = {};
|
|
1178
|
+
var defaultHeight = {};
|
|
1179
|
+
// creates a span where the fonts will be loaded
|
|
1180
|
+
var createSpan = function (fontFamily) {
|
|
1181
|
+
var span = document.createElement('span');
|
|
1182
|
+
var style = span.style;
|
|
1183
|
+
style.position = 'absolute';
|
|
1184
|
+
style.top = '0';
|
|
1185
|
+
style.left = '0';
|
|
1186
|
+
style.fontFamily = fontFamily;
|
|
1187
|
+
span.textContent = testString;
|
|
1188
|
+
spansContainer.appendChild(span);
|
|
1189
|
+
return span;
|
|
1190
|
+
};
|
|
1191
|
+
// creates a span and load the font to detect and a base font for fallback
|
|
1192
|
+
var createSpanWithFonts = function (fontToDetect, baseFont) {
|
|
1193
|
+
return createSpan("'" + fontToDetect + "'," + baseFont);
|
|
1194
|
+
};
|
|
1195
|
+
// creates spans for the base fonts and adds them to baseFontsDiv
|
|
1196
|
+
var initializeBaseFontsSpans = function () {
|
|
1197
|
+
return baseFonts.map(createSpan);
|
|
1198
|
+
};
|
|
1199
|
+
// creates spans for the fonts to detect and adds them to fontsDiv
|
|
1200
|
+
var initializeFontsSpans = function () {
|
|
1201
|
+
// Stores {fontName : [spans for that font]}
|
|
1202
|
+
var spans = {};
|
|
1203
|
+
var _loop_1 = function (font) {
|
|
1204
|
+
spans[font] = baseFonts.map(function (baseFont) { return createSpanWithFonts(font, baseFont); });
|
|
1205
|
+
};
|
|
1206
|
+
for (var _i = 0, fontList_1 = fontList; _i < fontList_1.length; _i++) {
|
|
1207
|
+
var font = fontList_1[_i];
|
|
1208
|
+
_loop_1(font);
|
|
1209
|
+
}
|
|
1210
|
+
return spans;
|
|
1211
|
+
};
|
|
1212
|
+
// checks if a font is available
|
|
1213
|
+
var isFontAvailable = function (fontSpans) {
|
|
1214
|
+
return baseFonts.some(function (baseFont, baseFontIndex) {
|
|
1215
|
+
return fontSpans[baseFontIndex].offsetWidth !== defaultWidth[baseFont] ||
|
|
1216
|
+
fontSpans[baseFontIndex].offsetHeight !== defaultHeight[baseFont];
|
|
1217
|
+
});
|
|
1218
|
+
};
|
|
1219
|
+
// create spans for base fonts
|
|
1220
|
+
var baseFontsSpans = initializeBaseFontsSpans();
|
|
1221
|
+
// create spans for fonts to detect
|
|
1222
|
+
var fontsSpans = initializeFontsSpans();
|
|
1223
|
+
// add all the spans to the DOM
|
|
1224
|
+
holder.appendChild(spansContainer);
|
|
1225
|
+
// get the default width for the three base fonts
|
|
1226
|
+
for (var index = 0; index < baseFonts.length; index++) {
|
|
1227
|
+
defaultWidth[baseFonts[index]] = baseFontsSpans[index].offsetWidth; // width for the default font
|
|
1228
|
+
defaultHeight[baseFonts[index]] = baseFontsSpans[index].offsetHeight; // height for the default font
|
|
1229
|
+
}
|
|
1230
|
+
// check available fonts
|
|
1231
|
+
return fontList.filter(function (font) { return isFontAvailable(fontsSpans[font]); });
|
|
1232
|
+
});
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
function getPlugins() {
|
|
1236
|
+
var rawPlugins = navigator.plugins;
|
|
1237
|
+
if (!rawPlugins) {
|
|
1238
|
+
return undefined;
|
|
1239
|
+
}
|
|
1240
|
+
var plugins = [];
|
|
1241
|
+
// Safari 10 doesn't support iterating navigator.plugins with for...of
|
|
1242
|
+
for (var i = 0; i < rawPlugins.length; ++i) {
|
|
1243
|
+
var plugin = rawPlugins[i];
|
|
1244
|
+
if (!plugin) {
|
|
1245
|
+
continue;
|
|
1246
|
+
}
|
|
1247
|
+
var mimeTypes = [];
|
|
1248
|
+
for (var j = 0; j < plugin.length; ++j) {
|
|
1249
|
+
var mimeType = plugin[j];
|
|
1250
|
+
mimeTypes.push({
|
|
1251
|
+
type: mimeType.type,
|
|
1252
|
+
suffixes: mimeType.suffixes,
|
|
1253
|
+
});
|
|
1254
|
+
}
|
|
1255
|
+
plugins.push({
|
|
1256
|
+
name: plugin.name,
|
|
1257
|
+
description: plugin.description,
|
|
1258
|
+
mimeTypes: mimeTypes,
|
|
1259
|
+
});
|
|
1260
|
+
}
|
|
1261
|
+
return plugins;
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
// https://www.browserleaks.com/canvas#how-does-it-work
|
|
1265
|
+
function getCanvasFingerprint() {
|
|
1266
|
+
var _a = makeCanvasContext(), canvas = _a[0], context = _a[1];
|
|
1267
|
+
if (!isSupported(canvas, context)) {
|
|
1268
|
+
return { winding: false, geometry: '', text: '' };
|
|
1269
|
+
}
|
|
1270
|
+
return {
|
|
1271
|
+
winding: doesSupportWinding(context),
|
|
1272
|
+
geometry: makeGeometryImage(canvas, context),
|
|
1273
|
+
// Text is unstable:
|
|
1274
|
+
// https://github.com/fingerprintjs/fingerprintjs/issues/583
|
|
1275
|
+
// https://github.com/fingerprintjs/fingerprintjs/issues/103
|
|
1276
|
+
// Therefore it's extracted into a separate image.
|
|
1277
|
+
text: makeTextImage(canvas, context),
|
|
1278
|
+
};
|
|
1279
|
+
}
|
|
1280
|
+
function makeCanvasContext() {
|
|
1281
|
+
var canvas = document.createElement('canvas');
|
|
1282
|
+
canvas.width = 1;
|
|
1283
|
+
canvas.height = 1;
|
|
1284
|
+
return [canvas, canvas.getContext('2d')];
|
|
1285
|
+
}
|
|
1286
|
+
function isSupported(canvas, context) {
|
|
1287
|
+
// TODO: look into: https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob
|
|
1288
|
+
return !!(context && canvas.toDataURL);
|
|
1289
|
+
}
|
|
1290
|
+
function doesSupportWinding(context) {
|
|
1291
|
+
// https://web.archive.org/web/20170825024655/http://blogs.adobe.com/webplatform/2013/01/30/winding-rules-in-canvas/
|
|
1292
|
+
// https://github.com/Modernizr/Modernizr/blob/master/feature-detects/canvas/winding.js
|
|
1293
|
+
context.rect(0, 0, 10, 10);
|
|
1294
|
+
context.rect(2, 2, 6, 6);
|
|
1295
|
+
return !context.isPointInPath(5, 5, 'evenodd');
|
|
1296
|
+
}
|
|
1297
|
+
function makeTextImage(canvas, context) {
|
|
1298
|
+
// Resizing the canvas cleans it
|
|
1299
|
+
canvas.width = 240;
|
|
1300
|
+
canvas.height = 60;
|
|
1301
|
+
context.textBaseline = 'alphabetic';
|
|
1302
|
+
context.fillStyle = '#f60';
|
|
1303
|
+
context.fillRect(100, 1, 62, 20);
|
|
1304
|
+
context.fillStyle = '#069';
|
|
1305
|
+
// It's important to use explicit built-in fonts in order to exclude the affect of font preferences
|
|
1306
|
+
// (there is a separate entropy source for them).
|
|
1307
|
+
context.font = '11pt "Times New Roman"';
|
|
1308
|
+
// The choice of emojis has a gigantic impact on rendering performance (especially in FF).
|
|
1309
|
+
// Some newer emojis cause it to slow down 50-200 times.
|
|
1310
|
+
// There must be no text to the right of the emoji, see https://github.com/fingerprintjs/fingerprintjs/issues/574
|
|
1311
|
+
// A bare emoji shouldn't be used because the canvas will change depending on the script encoding:
|
|
1312
|
+
// https://github.com/fingerprintjs/fingerprintjs/issues/66
|
|
1313
|
+
// Escape sequence shouldn't be used too because Terser will turn it into a bare unicode.
|
|
1314
|
+
var printedText = "Cwm fjordbank gly " + String.fromCharCode(55357, 56835) /* 😃 */;
|
|
1315
|
+
context.fillText(printedText, 2, 15);
|
|
1316
|
+
context.fillStyle = 'rgba(102, 204, 0, 0.2)';
|
|
1317
|
+
context.font = '18pt Arial';
|
|
1318
|
+
context.fillText(printedText, 4, 45);
|
|
1319
|
+
return save(canvas);
|
|
1320
|
+
}
|
|
1321
|
+
function makeGeometryImage(canvas, context) {
|
|
1322
|
+
// Resizing the canvas cleans it
|
|
1323
|
+
canvas.width = 122;
|
|
1324
|
+
canvas.height = 110;
|
|
1325
|
+
// Canvas blending
|
|
1326
|
+
// https://web.archive.org/web/20170826194121/http://blogs.adobe.com/webplatform/2013/01/28/blending-features-in-canvas/
|
|
1327
|
+
// http://jsfiddle.net/NDYV8/16/
|
|
1328
|
+
context.globalCompositeOperation = 'multiply';
|
|
1329
|
+
for (var _i = 0, _a = [
|
|
1330
|
+
['#f2f', 40, 40],
|
|
1331
|
+
['#2ff', 80, 40],
|
|
1332
|
+
['#ff2', 60, 80],
|
|
1333
|
+
]; _i < _a.length; _i++) {
|
|
1334
|
+
var _b = _a[_i], color = _b[0], x = _b[1], y = _b[2];
|
|
1335
|
+
context.fillStyle = color;
|
|
1336
|
+
context.beginPath();
|
|
1337
|
+
context.arc(x, y, 40, 0, Math.PI * 2, true);
|
|
1338
|
+
context.closePath();
|
|
1339
|
+
context.fill();
|
|
1340
|
+
}
|
|
1341
|
+
// Canvas winding
|
|
1342
|
+
// https://web.archive.org/web/20130913061632/http://blogs.adobe.com/webplatform/2013/01/30/winding-rules-in-canvas/
|
|
1343
|
+
// http://jsfiddle.net/NDYV8/19/
|
|
1344
|
+
context.fillStyle = '#f9c';
|
|
1345
|
+
context.arc(60, 60, 60, 0, Math.PI * 2, true);
|
|
1346
|
+
context.arc(60, 60, 20, 0, Math.PI * 2, true);
|
|
1347
|
+
context.fill('evenodd');
|
|
1348
|
+
return save(canvas);
|
|
1349
|
+
}
|
|
1350
|
+
function save(canvas) {
|
|
1351
|
+
// TODO: look into: https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob
|
|
1352
|
+
return canvas.toDataURL();
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
/**
|
|
1356
|
+
* This is a crude and primitive touch screen detection. It's not possible to currently reliably detect the availability
|
|
1357
|
+
* of a touch screen with a JS, without actually subscribing to a touch event.
|
|
1358
|
+
*
|
|
1359
|
+
* @see http://www.stucox.com/blog/you-cant-detect-a-touchscreen/
|
|
1360
|
+
* @see https://github.com/Modernizr/Modernizr/issues/548
|
|
1361
|
+
*/
|
|
1362
|
+
function getTouchSupport() {
|
|
1363
|
+
var n = navigator;
|
|
1364
|
+
var maxTouchPoints = 0;
|
|
1365
|
+
var touchEvent;
|
|
1366
|
+
if (n.maxTouchPoints !== undefined) {
|
|
1367
|
+
maxTouchPoints = toInt(n.maxTouchPoints);
|
|
1368
|
+
}
|
|
1369
|
+
else if (n.msMaxTouchPoints !== undefined) {
|
|
1370
|
+
maxTouchPoints = n.msMaxTouchPoints;
|
|
1371
|
+
}
|
|
1372
|
+
try {
|
|
1373
|
+
document.createEvent('TouchEvent');
|
|
1374
|
+
touchEvent = true;
|
|
1375
|
+
}
|
|
1376
|
+
catch (_a) {
|
|
1377
|
+
touchEvent = false;
|
|
1378
|
+
}
|
|
1379
|
+
var touchStart = 'ontouchstart' in window;
|
|
1380
|
+
return {
|
|
1381
|
+
maxTouchPoints: maxTouchPoints,
|
|
1382
|
+
touchEvent: touchEvent,
|
|
1383
|
+
touchStart: touchStart,
|
|
1384
|
+
};
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1387
|
+
function getOsCpu() {
|
|
1388
|
+
return navigator.oscpu;
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
function getLanguages() {
|
|
1392
|
+
var n = navigator;
|
|
1393
|
+
var result = [];
|
|
1394
|
+
var language = n.language || n.userLanguage || n.browserLanguage || n.systemLanguage;
|
|
1395
|
+
if (language !== undefined) {
|
|
1396
|
+
result.push([language]);
|
|
1397
|
+
}
|
|
1398
|
+
if (Array.isArray(n.languages)) {
|
|
1399
|
+
// Starting from Chromium 86, there is only a single value in `navigator.language` in Incognito mode:
|
|
1400
|
+
// the value of `navigator.language`. Therefore the value is ignored in this browser.
|
|
1401
|
+
if (!(isChromium() && isChromium86OrNewer())) {
|
|
1402
|
+
result.push(n.languages);
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
else if (typeof n.languages === 'string') {
|
|
1406
|
+
var languages = n.languages;
|
|
1407
|
+
if (languages) {
|
|
1408
|
+
result.push(languages.split(','));
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
return result;
|
|
1412
|
+
}
|
|
1413
|
+
|
|
1414
|
+
function getColorDepth() {
|
|
1415
|
+
return window.screen.colorDepth;
|
|
1416
|
+
}
|
|
1417
|
+
|
|
1418
|
+
function getDeviceMemory() {
|
|
1419
|
+
// `navigator.deviceMemory` is a string containing a number in some unidentified cases
|
|
1420
|
+
return replaceNaN(toFloat(navigator.deviceMemory), undefined);
|
|
1421
|
+
}
|
|
1422
|
+
|
|
1423
|
+
function getScreenResolution() {
|
|
1424
|
+
var s = screen;
|
|
1425
|
+
// Some browsers return screen resolution as strings, e.g. "1200", instead of a number, e.g. 1200.
|
|
1426
|
+
// I suspect it's done by certain plugins that randomize browser properties to prevent fingerprinting.
|
|
1427
|
+
// Some browsers even return screen resolution as not numbers.
|
|
1428
|
+
var parseDimension = function (value) { return replaceNaN(toInt(value), null); };
|
|
1429
|
+
var dimensions = [parseDimension(s.width), parseDimension(s.height)];
|
|
1430
|
+
dimensions.sort().reverse();
|
|
1431
|
+
return dimensions;
|
|
1432
|
+
}
|
|
1433
|
+
|
|
1434
|
+
var screenFrameCheckInterval = 2500;
|
|
1435
|
+
var roundingPrecision = 10;
|
|
1436
|
+
// The type is readonly to protect from unwanted mutations
|
|
1437
|
+
var screenFrameBackup;
|
|
1438
|
+
var screenFrameSizeTimeoutId;
|
|
1439
|
+
/**
|
|
1440
|
+
* Starts watching the screen frame size. When a non-zero size appears, the size is saved and the watch is stopped.
|
|
1441
|
+
* Later, when `getScreenFrame` runs, it will return the saved non-zero size if the current size is null.
|
|
1442
|
+
*
|
|
1443
|
+
* This trick is required to mitigate the fact that the screen frame turns null in some cases.
|
|
1444
|
+
* See more on this at https://github.com/fingerprintjs/fingerprintjs/issues/568
|
|
1445
|
+
*/
|
|
1446
|
+
function watchScreenFrame() {
|
|
1447
|
+
if (screenFrameSizeTimeoutId !== undefined) {
|
|
1448
|
+
return;
|
|
1449
|
+
}
|
|
1450
|
+
var checkScreenFrame = function () {
|
|
1451
|
+
var frameSize = getCurrentScreenFrame();
|
|
1452
|
+
if (isFrameSizeNull(frameSize)) {
|
|
1453
|
+
screenFrameSizeTimeoutId = setTimeout(checkScreenFrame, screenFrameCheckInterval);
|
|
1454
|
+
}
|
|
1455
|
+
else {
|
|
1456
|
+
screenFrameBackup = frameSize;
|
|
1457
|
+
screenFrameSizeTimeoutId = undefined;
|
|
1458
|
+
}
|
|
1459
|
+
};
|
|
1460
|
+
checkScreenFrame();
|
|
1461
|
+
}
|
|
1462
|
+
function getScreenFrame() {
|
|
1463
|
+
var _this = this;
|
|
1464
|
+
watchScreenFrame();
|
|
1465
|
+
return function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1466
|
+
var frameSize;
|
|
1467
|
+
return __generator(this, function (_a) {
|
|
1468
|
+
switch (_a.label) {
|
|
1469
|
+
case 0:
|
|
1470
|
+
frameSize = getCurrentScreenFrame();
|
|
1471
|
+
if (!isFrameSizeNull(frameSize)) return [3 /*break*/, 2];
|
|
1472
|
+
if (screenFrameBackup) {
|
|
1473
|
+
return [2 /*return*/, __spreadArrays(screenFrameBackup)];
|
|
1474
|
+
}
|
|
1475
|
+
if (!getFullscreenElement()) return [3 /*break*/, 2];
|
|
1476
|
+
// Some browsers set the screen frame to zero when programmatic fullscreen is on.
|
|
1477
|
+
// There is a chance of getting a non-zero frame after exiting the fullscreen.
|
|
1478
|
+
// See more on this at https://github.com/fingerprintjs/fingerprintjs/issues/568
|
|
1479
|
+
return [4 /*yield*/, exitFullscreen()];
|
|
1480
|
+
case 1:
|
|
1481
|
+
// Some browsers set the screen frame to zero when programmatic fullscreen is on.
|
|
1482
|
+
// There is a chance of getting a non-zero frame after exiting the fullscreen.
|
|
1483
|
+
// See more on this at https://github.com/fingerprintjs/fingerprintjs/issues/568
|
|
1484
|
+
_a.sent();
|
|
1485
|
+
frameSize = getCurrentScreenFrame();
|
|
1486
|
+
_a.label = 2;
|
|
1487
|
+
case 2:
|
|
1488
|
+
if (!isFrameSizeNull(frameSize)) {
|
|
1489
|
+
screenFrameBackup = frameSize;
|
|
1490
|
+
}
|
|
1491
|
+
return [2 /*return*/, frameSize];
|
|
1492
|
+
}
|
|
1493
|
+
});
|
|
1494
|
+
}); };
|
|
1495
|
+
}
|
|
1496
|
+
/**
|
|
1497
|
+
* Sometimes the available screen resolution changes a bit, e.g. 1900x1440 → 1900x1439. A possible reason: macOS Dock
|
|
1498
|
+
* shrinks to fit more icons when there is too little space. The rounding is used to mitigate the difference.
|
|
1499
|
+
*/
|
|
1500
|
+
function getRoundedScreenFrame() {
|
|
1501
|
+
var _this = this;
|
|
1502
|
+
var screenFrameGetter = getScreenFrame();
|
|
1503
|
+
return function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1504
|
+
var frameSize, processSize;
|
|
1505
|
+
return __generator(this, function (_a) {
|
|
1506
|
+
switch (_a.label) {
|
|
1507
|
+
case 0: return [4 /*yield*/, screenFrameGetter()];
|
|
1508
|
+
case 1:
|
|
1509
|
+
frameSize = _a.sent();
|
|
1510
|
+
processSize = function (sideSize) { return (sideSize === null ? null : round(sideSize, roundingPrecision)); };
|
|
1511
|
+
// It might look like I don't know about `for` and `map`.
|
|
1512
|
+
// In fact, such code is used to avoid TypeScript issues without using `as`.
|
|
1513
|
+
return [2 /*return*/, [processSize(frameSize[0]), processSize(frameSize[1]), processSize(frameSize[2]), processSize(frameSize[3])]];
|
|
1514
|
+
}
|
|
1515
|
+
});
|
|
1516
|
+
}); };
|
|
1517
|
+
}
|
|
1518
|
+
function getCurrentScreenFrame() {
|
|
1519
|
+
var s = screen;
|
|
1520
|
+
// Some browsers return screen resolution as strings, e.g. "1200", instead of a number, e.g. 1200.
|
|
1521
|
+
// I suspect it's done by certain plugins that randomize browser properties to prevent fingerprinting.
|
|
1522
|
+
//
|
|
1523
|
+
// Some browsers (IE, Edge ≤18) don't provide `screen.availLeft` and `screen.availTop`. The property values are
|
|
1524
|
+
// replaced with 0 in such cases to not lose the entropy from `screen.availWidth` and `screen.availHeight`.
|
|
1525
|
+
return [
|
|
1526
|
+
replaceNaN(toFloat(s.availTop), null),
|
|
1527
|
+
replaceNaN(toFloat(s.width) - toFloat(s.availWidth) - replaceNaN(toFloat(s.availLeft), 0), null),
|
|
1528
|
+
replaceNaN(toFloat(s.height) - toFloat(s.availHeight) - replaceNaN(toFloat(s.availTop), 0), null),
|
|
1529
|
+
replaceNaN(toFloat(s.availLeft), null),
|
|
1530
|
+
];
|
|
1531
|
+
}
|
|
1532
|
+
function isFrameSizeNull(frameSize) {
|
|
1533
|
+
for (var i = 0; i < 4; ++i) {
|
|
1534
|
+
if (frameSize[i]) {
|
|
1535
|
+
return false;
|
|
1536
|
+
}
|
|
1537
|
+
}
|
|
1538
|
+
return true;
|
|
1539
|
+
}
|
|
1540
|
+
|
|
1541
|
+
function getHardwareConcurrency() {
|
|
1542
|
+
// sometimes hardware concurrency is a string
|
|
1543
|
+
return replaceNaN(toInt(navigator.hardwareConcurrency), undefined);
|
|
1544
|
+
}
|
|
1545
|
+
|
|
1546
|
+
function getTimezone() {
|
|
1547
|
+
var _a;
|
|
1548
|
+
var DateTimeFormat = (_a = window.Intl) === null || _a === void 0 ? void 0 : _a.DateTimeFormat;
|
|
1549
|
+
if (DateTimeFormat) {
|
|
1550
|
+
var timezone = new DateTimeFormat().resolvedOptions().timeZone;
|
|
1551
|
+
if (timezone) {
|
|
1552
|
+
return timezone;
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1555
|
+
// For browsers that don't support timezone names
|
|
1556
|
+
// The minus is intentional because the JS offset is opposite to the real offset
|
|
1557
|
+
var offset = -getTimezoneOffset();
|
|
1558
|
+
return "UTC" + (offset >= 0 ? '+' : '') + Math.abs(offset);
|
|
1559
|
+
}
|
|
1560
|
+
function getTimezoneOffset() {
|
|
1561
|
+
var currentYear = new Date().getFullYear();
|
|
1562
|
+
// The timezone offset may change over time due to daylight saving time (DST) shifts.
|
|
1563
|
+
// The non-DST timezone offset is used as the result timezone offset.
|
|
1564
|
+
// Since the DST season differs in the northern and the southern hemispheres,
|
|
1565
|
+
// both January and July timezones offsets are considered.
|
|
1566
|
+
return Math.max(
|
|
1567
|
+
// `getTimezoneOffset` returns a number as a string in some unidentified cases
|
|
1568
|
+
toFloat(new Date(currentYear, 0, 1).getTimezoneOffset()), toFloat(new Date(currentYear, 6, 1).getTimezoneOffset()));
|
|
1569
|
+
}
|
|
1570
|
+
|
|
1571
|
+
function getSessionStorage() {
|
|
1572
|
+
try {
|
|
1573
|
+
return !!window.sessionStorage;
|
|
1574
|
+
}
|
|
1575
|
+
catch (error) {
|
|
1576
|
+
/* SecurityError when referencing it means it exists */
|
|
1577
|
+
return true;
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
|
|
1581
|
+
// https://bugzilla.mozilla.org/show_bug.cgi?id=781447
|
|
1582
|
+
function getLocalStorage() {
|
|
1583
|
+
try {
|
|
1584
|
+
return !!window.localStorage;
|
|
1585
|
+
}
|
|
1586
|
+
catch (e) {
|
|
1587
|
+
/* SecurityError when referencing it means it exists */
|
|
1588
|
+
return true;
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
|
|
1592
|
+
function getIndexedDB() {
|
|
1593
|
+
// IE and Edge don't allow accessing indexedDB in private mode, therefore IE and Edge will have different
|
|
1594
|
+
// visitor identifier in normal and private modes.
|
|
1595
|
+
if (isTrident() || isEdgeHTML()) {
|
|
1596
|
+
return undefined;
|
|
1597
|
+
}
|
|
1598
|
+
try {
|
|
1599
|
+
return !!window.indexedDB;
|
|
1600
|
+
}
|
|
1601
|
+
catch (e) {
|
|
1602
|
+
/* SecurityError when referencing it means it exists */
|
|
1603
|
+
return true;
|
|
1604
|
+
}
|
|
1605
|
+
}
|
|
1606
|
+
|
|
1607
|
+
function getOpenDatabase() {
|
|
1608
|
+
return !!window.openDatabase;
|
|
1609
|
+
}
|
|
1610
|
+
|
|
1611
|
+
function getCpuClass() {
|
|
1612
|
+
return navigator.cpuClass;
|
|
1613
|
+
}
|
|
1614
|
+
|
|
1615
|
+
function getPlatform() {
|
|
1616
|
+
// Android Chrome 86 and 87 and Android Firefox 80 and 84 don't mock the platform value when desktop mode is requested
|
|
1617
|
+
var platform = navigator.platform;
|
|
1618
|
+
// iOS mocks the platform value when desktop version is requested: https://github.com/fingerprintjs/fingerprintjs/issues/514
|
|
1619
|
+
// iPad uses desktop mode by default since iOS 13
|
|
1620
|
+
// The value is 'MacIntel' on M1 Macs
|
|
1621
|
+
// The value is 'iPhone' on iPod Touch
|
|
1622
|
+
if (platform === 'MacIntel') {
|
|
1623
|
+
if (isWebKit() && !isDesktopSafari()) {
|
|
1624
|
+
return isIPad() ? 'iPad' : 'iPhone';
|
|
1625
|
+
}
|
|
1626
|
+
}
|
|
1627
|
+
return platform;
|
|
1628
|
+
}
|
|
1629
|
+
|
|
1630
|
+
function getVendor() {
|
|
1631
|
+
return navigator.vendor || '';
|
|
1632
|
+
}
|
|
1633
|
+
|
|
1634
|
+
/**
|
|
1635
|
+
* Checks for browser-specific (not engine specific) global variables to tell browsers with the same engine apart.
|
|
1636
|
+
* Only somewhat popular browsers are considered.
|
|
1637
|
+
*/
|
|
1638
|
+
function getVendorFlavors() {
|
|
1639
|
+
var flavors = [];
|
|
1640
|
+
for (var _i = 0, _a = [
|
|
1641
|
+
// Blink and some browsers on iOS
|
|
1642
|
+
'chrome',
|
|
1643
|
+
// Safari on macOS
|
|
1644
|
+
'safari',
|
|
1645
|
+
// Chrome on iOS (checked in 85 on 13 and 87 on 14)
|
|
1646
|
+
'__crWeb',
|
|
1647
|
+
'__gCrWeb',
|
|
1648
|
+
// Yandex Browser on iOS, macOS and Android (checked in 21.2 on iOS 14, macOS and Android)
|
|
1649
|
+
'yandex',
|
|
1650
|
+
// Yandex Browser on iOS (checked in 21.2 on 14)
|
|
1651
|
+
'__yb',
|
|
1652
|
+
'__ybro',
|
|
1653
|
+
// Firefox on iOS (checked in 32 on 14)
|
|
1654
|
+
'__firefox__',
|
|
1655
|
+
// Edge on iOS (checked in 46 on 14)
|
|
1656
|
+
'__edgeTrackingPreventionStatistics',
|
|
1657
|
+
'webkit',
|
|
1658
|
+
// Opera Touch on iOS (checked in 2.6 on 14)
|
|
1659
|
+
'oprt',
|
|
1660
|
+
// Samsung Internet on Android (checked in 11.1)
|
|
1661
|
+
'samsungAr',
|
|
1662
|
+
// UC Browser on Android (checked in 12.10 and 13.0)
|
|
1663
|
+
'ucweb',
|
|
1664
|
+
'UCShellJava',
|
|
1665
|
+
// Puffin on Android (checked in 9.0)
|
|
1666
|
+
'puffinDevice',
|
|
1667
|
+
]; _i < _a.length; _i++) {
|
|
1668
|
+
var key = _a[_i];
|
|
1669
|
+
var value = window[key];
|
|
1670
|
+
if (value && typeof value === 'object') {
|
|
1671
|
+
flavors.push(key);
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
return flavors.sort();
|
|
1675
|
+
}
|
|
1676
|
+
|
|
1677
|
+
/**
|
|
1678
|
+
* navigator.cookieEnabled cannot detect custom or nuanced cookie blocking configurations. For example, when blocking
|
|
1679
|
+
* cookies via the Advanced Privacy Settings in IE9, it always returns true. And there have been issues in the past with
|
|
1680
|
+
* site-specific exceptions. Don't rely on it.
|
|
1681
|
+
*
|
|
1682
|
+
* @see https://github.com/Modernizr/Modernizr/blob/master/feature-detects/cookies.js Taken from here
|
|
1683
|
+
*/
|
|
1684
|
+
function areCookiesEnabled() {
|
|
1685
|
+
var d = document;
|
|
1686
|
+
// Taken from here: https://github.com/Modernizr/Modernizr/blob/master/feature-detects/cookies.js
|
|
1687
|
+
// navigator.cookieEnabled cannot detect custom or nuanced cookie blocking configurations. For example, when blocking
|
|
1688
|
+
// cookies via the Advanced Privacy Settings in IE9, it always returns true. And there have been issues in the past
|
|
1689
|
+
// with site-specific exceptions. Don't rely on it.
|
|
1690
|
+
// try..catch because some in situations `document.cookie` is exposed but throws a
|
|
1691
|
+
// SecurityError if you try to access it; e.g. documents created from data URIs
|
|
1692
|
+
// or in sandboxed iframes (depending on flags/context)
|
|
1693
|
+
try {
|
|
1694
|
+
// Create cookie
|
|
1695
|
+
d.cookie = 'cookietest=1; SameSite=Strict;';
|
|
1696
|
+
var result = d.cookie.indexOf('cookietest=') !== -1;
|
|
1697
|
+
// Delete cookie
|
|
1698
|
+
d.cookie = 'cookietest=1; SameSite=Strict; expires=Thu, 01-Jan-1970 00:00:01 GMT';
|
|
1699
|
+
return result;
|
|
1700
|
+
}
|
|
1701
|
+
catch (e) {
|
|
1702
|
+
return false;
|
|
1703
|
+
}
|
|
1704
|
+
}
|
|
1705
|
+
|
|
1706
|
+
/**
|
|
1707
|
+
* Only single element selector are supported (no operators like space, +, >, etc).
|
|
1708
|
+
* `embed` and `position: fixed;` will be considered as blocked anyway because it always has no offsetParent.
|
|
1709
|
+
* Avoid `iframe` and anything with `[src=]` because they produce excess HTTP requests.
|
|
1710
|
+
*
|
|
1711
|
+
* See docs/content_blockers.md to learn how to make the list
|
|
1712
|
+
*/
|
|
1713
|
+
var filters = {
|
|
1714
|
+
abpIndo: [
|
|
1715
|
+
'#Iklan-Melayang',
|
|
1716
|
+
'#Kolom-Iklan-728',
|
|
1717
|
+
'#SidebarIklan-wrapper',
|
|
1718
|
+
'a[title="7naga poker" i]',
|
|
1719
|
+
'[title="ALIENBOLA" i]',
|
|
1720
|
+
],
|
|
1721
|
+
abpvn: [
|
|
1722
|
+
'#quangcaomb',
|
|
1723
|
+
'.iosAdsiosAds-layout',
|
|
1724
|
+
'.quangcao',
|
|
1725
|
+
'[href^="https://r88.vn/"]',
|
|
1726
|
+
'[href^="https://zbet.vn/"]',
|
|
1727
|
+
],
|
|
1728
|
+
adBlockFinland: [
|
|
1729
|
+
'.mainostila',
|
|
1730
|
+
'.sponsorit',
|
|
1731
|
+
'.ylamainos',
|
|
1732
|
+
'a[href*="/clickthrgh.asp?"]',
|
|
1733
|
+
'a[href^="https://app.readpeak.com/ads"]',
|
|
1734
|
+
],
|
|
1735
|
+
adBlockPersian: [
|
|
1736
|
+
'#navbar_notice_50',
|
|
1737
|
+
'a[href^="http://g1.v.fwmrm.net/ad/"]',
|
|
1738
|
+
'.kadr',
|
|
1739
|
+
'TABLE[width="140px"]',
|
|
1740
|
+
'#divAgahi',
|
|
1741
|
+
],
|
|
1742
|
+
adBlockWarningRemoval: ['#adblock-honeypot', '.adblocker-root', '.wp_adblock_detect'],
|
|
1743
|
+
adGuardAnnoyances: ['amp-embed[type="zen"]', '.hs-sosyal', '#cookieconsentdiv', 'div[class^="app_gdpr"]', '.as-oil'],
|
|
1744
|
+
adGuardBase: ['#ad-after', '#ad-p3', '.BetterJsPopOverlay', '#ad_300X250', '#bannerfloat22'],
|
|
1745
|
+
adGuardChinese: [
|
|
1746
|
+
// Disabled because not reproducible. Will be replaced during the next filter update.
|
|
1747
|
+
// '#piao_div_0[style*="width:140px;"]',
|
|
1748
|
+
'a[href*=".ttz5.cn"]',
|
|
1749
|
+
'a[href*=".yabovip2027.com/"]',
|
|
1750
|
+
'.tm3all2h4b',
|
|
1751
|
+
'.cc5278_banner_ad',
|
|
1752
|
+
],
|
|
1753
|
+
adGuardFrench: [
|
|
1754
|
+
'.zonepub',
|
|
1755
|
+
'[class*="_adLeaderboard"]',
|
|
1756
|
+
'[id^="block-xiti_oas-"]',
|
|
1757
|
+
'a[href^="http://ptapjmp.com/"]',
|
|
1758
|
+
'a[href^="https://go.alvexo.com/"]',
|
|
1759
|
+
],
|
|
1760
|
+
adGuardGerman: [
|
|
1761
|
+
'.banneritemwerbung_head_1',
|
|
1762
|
+
'.boxstartwerbung',
|
|
1763
|
+
'.werbung3',
|
|
1764
|
+
'a[href^="http://www.eis.de/index.phtml?refid="]',
|
|
1765
|
+
'a[href^="https://www.tipico.com/?affiliateId="]',
|
|
1766
|
+
],
|
|
1767
|
+
adGuardJapanese: [
|
|
1768
|
+
'#kauli_yad_1',
|
|
1769
|
+
'#ad-giftext',
|
|
1770
|
+
'#adsSPRBlock',
|
|
1771
|
+
'a[href^="http://ad2.trafficgate.net/"]',
|
|
1772
|
+
'a[href^="http://www.rssad.jp/"]',
|
|
1773
|
+
],
|
|
1774
|
+
adGuardMobile: ['amp-auto-ads', '#mgid_iframe', '.amp_ad', 'amp-embed[type="24smi"]', '#mgid_iframe1'],
|
|
1775
|
+
adGuardRussian: [
|
|
1776
|
+
'a[href^="https://ya-distrib.ru/r/"]',
|
|
1777
|
+
'a[href^="https://ad.letmeads.com/"]',
|
|
1778
|
+
'.reclama',
|
|
1779
|
+
'div[id^="smi2adblock"]',
|
|
1780
|
+
'div[id^="AdFox_banner_"]',
|
|
1781
|
+
],
|
|
1782
|
+
adGuardSocial: [
|
|
1783
|
+
'a[href^="//www.stumbleupon.com/submit?url="]',
|
|
1784
|
+
'a[href^="//telegram.me/share/url?"]',
|
|
1785
|
+
'.etsy-tweet',
|
|
1786
|
+
'#inlineShare',
|
|
1787
|
+
'.popup-social',
|
|
1788
|
+
],
|
|
1789
|
+
adGuardSpanishPortuguese: [
|
|
1790
|
+
'#barraPublicidade',
|
|
1791
|
+
'#Publicidade',
|
|
1792
|
+
'#publiEspecial',
|
|
1793
|
+
'#queTooltip',
|
|
1794
|
+
'[href^="http://ads.glispa.com/"]',
|
|
1795
|
+
],
|
|
1796
|
+
adGuardTrackingProtection: [
|
|
1797
|
+
'amp-embed[type="taboola"]',
|
|
1798
|
+
'#qoo-counter',
|
|
1799
|
+
'a[href^="http://click.hotlog.ru/"]',
|
|
1800
|
+
'a[href^="http://hitcounter.ru/top/stat.php"]',
|
|
1801
|
+
'a[href^="http://top.mail.ru/jump"]',
|
|
1802
|
+
],
|
|
1803
|
+
adGuardTurkish: [
|
|
1804
|
+
'#backkapat',
|
|
1805
|
+
'#reklami',
|
|
1806
|
+
'a[href^="http://adserv.ontek.com.tr/"]',
|
|
1807
|
+
'a[href^="http://izlenzi.com/campaign/"]',
|
|
1808
|
+
'a[href^="http://www.installads.net/"]',
|
|
1809
|
+
],
|
|
1810
|
+
bulgarian: ['td#freenet_table_ads', '#adbody', '#ea_intext_div', '.lapni-pop-over', '#xenium_hot_offers'],
|
|
1811
|
+
easyList: ['#AD_banner_bottom', '#Ads_google_02', '#N-ad-article-rightRail-1', '#ad-fullbanner2', '#ad-zone-2'],
|
|
1812
|
+
easyListChina: [
|
|
1813
|
+
'a[href*=".wensixuetang.com/"]',
|
|
1814
|
+
'A[href*="/hth107.com/"]',
|
|
1815
|
+
'.appguide-wrap[onclick*="bcebos.com"]',
|
|
1816
|
+
'.frontpageAdvM',
|
|
1817
|
+
'#taotaole',
|
|
1818
|
+
],
|
|
1819
|
+
easyListCookie: ['#adtoniq-msg-bar', '#CoockiesPage', '#CookieModal_cookiemodal', '#DO_CC_PANEL', '#ShowCookie'],
|
|
1820
|
+
easyListCzechSlovak: ['#onlajny-stickers', '#reklamni-box', '.reklama-megaboard', '.sklik', '[id^="sklikReklama"]'],
|
|
1821
|
+
easyListDutch: [
|
|
1822
|
+
'#advertentie',
|
|
1823
|
+
'#vipAdmarktBannerBlock',
|
|
1824
|
+
'.adstekst',
|
|
1825
|
+
'a[href^="https://xltube.nl/click/"]',
|
|
1826
|
+
'#semilo-lrectangle',
|
|
1827
|
+
],
|
|
1828
|
+
easyListGermany: [
|
|
1829
|
+
'a[href^="http://www.hw-area.com/?dp="]',
|
|
1830
|
+
'a[href^="https://ads.sunmaker.com/tracking.php?"]',
|
|
1831
|
+
'.werbung-skyscraper2',
|
|
1832
|
+
'.bannergroup_werbung',
|
|
1833
|
+
'.ads_rechts',
|
|
1834
|
+
],
|
|
1835
|
+
easyListItaly: [
|
|
1836
|
+
'.box_adv_annunci',
|
|
1837
|
+
'.sb-box-pubbliredazionale',
|
|
1838
|
+
'a[href^="http://affiliazioniads.snai.it/"]',
|
|
1839
|
+
'a[href^="https://adserver.html.it/"]',
|
|
1840
|
+
'a[href^="https://affiliazioniads.snai.it/"]',
|
|
1841
|
+
],
|
|
1842
|
+
easyListLithuania: [
|
|
1843
|
+
'.reklamos_tarpas',
|
|
1844
|
+
'.reklamos_nuorodos',
|
|
1845
|
+
'img[alt="Reklaminis skydelis"]',
|
|
1846
|
+
'img[alt="Dedikuoti.lt serveriai"]',
|
|
1847
|
+
'img[alt="Hostingas Serveriai.lt"]',
|
|
1848
|
+
],
|
|
1849
|
+
estonian: ['A[href*="http://pay4results24.eu"]'],
|
|
1850
|
+
fanboyAnnoyances: [
|
|
1851
|
+
'#feedback-tab',
|
|
1852
|
+
'#taboola-below-article',
|
|
1853
|
+
'.feedburnerFeedBlock',
|
|
1854
|
+
'.widget-feedburner-counter',
|
|
1855
|
+
'[title="Subscribe to our blog"]',
|
|
1856
|
+
],
|
|
1857
|
+
fanboyAntiFacebook: ['.util-bar-module-firefly-visible'],
|
|
1858
|
+
fanboyEnhancedTrackers: [
|
|
1859
|
+
'.open.pushModal',
|
|
1860
|
+
'#issuem-leaky-paywall-articles-zero-remaining-nag',
|
|
1861
|
+
'#sovrn_container',
|
|
1862
|
+
'div[class$="-hide"][zoompage-fontsize][style="display: block;"]',
|
|
1863
|
+
'.BlockNag__Card',
|
|
1864
|
+
],
|
|
1865
|
+
fanboySocial: [
|
|
1866
|
+
'.td-tags-and-social-wrapper-box',
|
|
1867
|
+
'.twitterContainer',
|
|
1868
|
+
'.youtube-social',
|
|
1869
|
+
'a[title^="Like us on Facebook"]',
|
|
1870
|
+
'img[alt^="Share on Digg"]',
|
|
1871
|
+
],
|
|
1872
|
+
frellwitSwedish: [
|
|
1873
|
+
'a[href*="casinopro.se"][target="_blank"]',
|
|
1874
|
+
'a[href*="doktor-se.onelink.me"]',
|
|
1875
|
+
'article.category-samarbete',
|
|
1876
|
+
'div.holidAds',
|
|
1877
|
+
'ul.adsmodern',
|
|
1878
|
+
],
|
|
1879
|
+
greekAdBlock: [
|
|
1880
|
+
'A[href*="adman.otenet.gr/click?"]',
|
|
1881
|
+
'A[href*="http://axiabanners.exodus.gr/"]',
|
|
1882
|
+
'A[href*="http://interactive.forthnet.gr/click?"]',
|
|
1883
|
+
'DIV.agores300',
|
|
1884
|
+
'TABLE.advright',
|
|
1885
|
+
],
|
|
1886
|
+
hungarian: [
|
|
1887
|
+
'A[href*="ad.eval.hu"]',
|
|
1888
|
+
'A[href*="ad.netmedia.hu"]',
|
|
1889
|
+
'A[href*="daserver.ultraweb.hu"]',
|
|
1890
|
+
'#cemp_doboz',
|
|
1891
|
+
'.optimonk-iframe-container',
|
|
1892
|
+
],
|
|
1893
|
+
iDontCareAboutCookies: [
|
|
1894
|
+
'.alert-info[data-block-track*="CookieNotice"]',
|
|
1895
|
+
'.ModuleTemplateCookieIndicator',
|
|
1896
|
+
'.o--cookies--container',
|
|
1897
|
+
'.cookie-msg-info-container',
|
|
1898
|
+
'#cookies-policy-sticky',
|
|
1899
|
+
],
|
|
1900
|
+
icelandicAbp: ['A[href^="/framework/resources/forms/ads.aspx"]'],
|
|
1901
|
+
latvian: [
|
|
1902
|
+
'a[href="http://www.salidzini.lv/"][style="display: block; width: 120px; height: 40px; overflow: hidden; position: relative;"]',
|
|
1903
|
+
'a[href="http://www.salidzini.lv/"][style="display: block; width: 88px; height: 31px; overflow: hidden; position: relative;"]',
|
|
1904
|
+
],
|
|
1905
|
+
listKr: [
|
|
1906
|
+
'a[href*="//kingtoon.slnk.kr"]',
|
|
1907
|
+
'a[href*="//playdsb.com/kr"]',
|
|
1908
|
+
'div.logly-lift-adz',
|
|
1909
|
+
'div[data-widget_id="ml6EJ074"]',
|
|
1910
|
+
'ins.daum_ddn_area',
|
|
1911
|
+
],
|
|
1912
|
+
listeAr: [
|
|
1913
|
+
'.geminiLB1Ad',
|
|
1914
|
+
'.right-and-left-sponsers',
|
|
1915
|
+
'a[href*=".aflam.info"]',
|
|
1916
|
+
'a[href*="booraq.org"]',
|
|
1917
|
+
'a[href*="dubizzle.com/ar/?utm_source="]',
|
|
1918
|
+
],
|
|
1919
|
+
listeFr: [
|
|
1920
|
+
'a[href^="http://promo.vador.com/"]',
|
|
1921
|
+
'#adcontainer_recherche',
|
|
1922
|
+
'a[href*="weborama.fr/fcgi-bin/"]',
|
|
1923
|
+
'.site-pub-interstitiel',
|
|
1924
|
+
'div[id^="crt-"][data-criteo-id]',
|
|
1925
|
+
],
|
|
1926
|
+
officialPolish: [
|
|
1927
|
+
'#ceneo-placeholder-ceneo-12',
|
|
1928
|
+
'[href^="https://aff.sendhub.pl/"]',
|
|
1929
|
+
'a[href^="http://advmanager.techfun.pl/redirect/"]',
|
|
1930
|
+
'a[href^="http://www.trizer.pl/?utm_source"]',
|
|
1931
|
+
'div#skapiec_ad',
|
|
1932
|
+
],
|
|
1933
|
+
ro: [
|
|
1934
|
+
'a[href^="//afftrk.altex.ro/Counter/Click"]',
|
|
1935
|
+
'a[href^="/magazin/"]',
|
|
1936
|
+
'a[href^="https://blackfridaysales.ro/trk/shop/"]',
|
|
1937
|
+
'a[href^="https://event.2performant.com/events/click"]',
|
|
1938
|
+
'a[href^="https://l.profitshare.ro/"]',
|
|
1939
|
+
],
|
|
1940
|
+
ruAd: [
|
|
1941
|
+
'a[href*="//febrare.ru/"]',
|
|
1942
|
+
'a[href*="//utimg.ru/"]',
|
|
1943
|
+
'a[href*="://chikidiki.ru"]',
|
|
1944
|
+
'#pgeldiz',
|
|
1945
|
+
'.yandex-rtb-block',
|
|
1946
|
+
],
|
|
1947
|
+
thaiAds: ['a[href*=macau-uta-popup]', '#ads-google-middle_rectangle-group', '.ads300s', '.bumq', '.img-kosana'],
|
|
1948
|
+
webAnnoyancesUltralist: [
|
|
1949
|
+
'#mod-social-share-2',
|
|
1950
|
+
'#social-tools',
|
|
1951
|
+
'.ctpl-fullbanner',
|
|
1952
|
+
'.zergnet-recommend',
|
|
1953
|
+
'.yt.btn-link.btn-md.btn',
|
|
1954
|
+
],
|
|
1955
|
+
};
|
|
1956
|
+
/**
|
|
1957
|
+
* The order of the returned array means nothing (it's always sorted alphabetically).
|
|
1958
|
+
*
|
|
1959
|
+
* Notice that the source is slightly unstable.
|
|
1960
|
+
* Safari provides a 2-taps way to disable all content blockers on a page temporarily.
|
|
1961
|
+
* Also content blockers can be disabled permanently for a domain, but it requires 4 taps.
|
|
1962
|
+
* So empty array shouldn't be treated as "no blockers", it should be treated as "no signal".
|
|
1963
|
+
* If you are a website owner, don't make your visitors want to disable content blockers.
|
|
1964
|
+
*/
|
|
1965
|
+
function getDomBlockers(_a) {
|
|
1966
|
+
var debug = (_a === void 0 ? {} : _a).debug;
|
|
1967
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1968
|
+
var filterNames, allSelectors, blockedSelectors, activeBlockers;
|
|
1969
|
+
var _b;
|
|
1970
|
+
return __generator(this, function (_c) {
|
|
1971
|
+
switch (_c.label) {
|
|
1972
|
+
case 0:
|
|
1973
|
+
if (!isApplicable()) {
|
|
1974
|
+
return [2 /*return*/, undefined];
|
|
1975
|
+
}
|
|
1976
|
+
filterNames = Object.keys(filters);
|
|
1977
|
+
allSelectors = (_b = []).concat.apply(_b, filterNames.map(function (filterName) { return filters[filterName]; }));
|
|
1978
|
+
return [4 /*yield*/, getBlockedSelectors(allSelectors)];
|
|
1979
|
+
case 1:
|
|
1980
|
+
blockedSelectors = _c.sent();
|
|
1981
|
+
if (debug) {
|
|
1982
|
+
printDebug(blockedSelectors);
|
|
1983
|
+
}
|
|
1984
|
+
activeBlockers = filterNames.filter(function (filterName) {
|
|
1985
|
+
var selectors = filters[filterName];
|
|
1986
|
+
var blockedCount = countTruthy(selectors.map(function (selector) { return blockedSelectors[selector]; }));
|
|
1987
|
+
return blockedCount > selectors.length * 0.6;
|
|
1988
|
+
});
|
|
1989
|
+
activeBlockers.sort();
|
|
1990
|
+
return [2 /*return*/, activeBlockers];
|
|
1991
|
+
}
|
|
1992
|
+
});
|
|
1993
|
+
});
|
|
1994
|
+
}
|
|
1995
|
+
function isApplicable() {
|
|
1996
|
+
// Safari (desktop and mobile) and all Android browsers keep content blockers in both regular and private mode
|
|
1997
|
+
return isWebKit() || isAndroid();
|
|
1998
|
+
}
|
|
1999
|
+
function getBlockedSelectors(selectors) {
|
|
2000
|
+
var _a;
|
|
2001
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2002
|
+
var d, root, elements, blockedSelectors, i, element, holder, i;
|
|
2003
|
+
return __generator(this, function (_b) {
|
|
2004
|
+
switch (_b.label) {
|
|
2005
|
+
case 0:
|
|
2006
|
+
d = document;
|
|
2007
|
+
root = d.createElement('div');
|
|
2008
|
+
elements = new Array(selectors.length);
|
|
2009
|
+
blockedSelectors = {} // Set() isn't used just in case somebody need older browser support
|
|
2010
|
+
;
|
|
2011
|
+
forceShow(root);
|
|
2012
|
+
// First create all elements that can be blocked. If the DOM steps below are done in a single cycle,
|
|
2013
|
+
// browser will alternate tree modification and layout reading, that is very slow.
|
|
2014
|
+
for (i = 0; i < selectors.length; ++i) {
|
|
2015
|
+
element = selectorToElement(selectors[i]);
|
|
2016
|
+
holder = d.createElement('div') // Protects from unwanted effects of `+` and `~` selectors of filters
|
|
2017
|
+
;
|
|
2018
|
+
forceShow(holder);
|
|
2019
|
+
holder.appendChild(element);
|
|
2020
|
+
root.appendChild(holder);
|
|
2021
|
+
elements[i] = element;
|
|
2022
|
+
}
|
|
2023
|
+
_b.label = 1;
|
|
2024
|
+
case 1:
|
|
2025
|
+
if (!!d.body) return [3 /*break*/, 3];
|
|
2026
|
+
return [4 /*yield*/, wait(50)];
|
|
2027
|
+
case 2:
|
|
2028
|
+
_b.sent();
|
|
2029
|
+
return [3 /*break*/, 1];
|
|
2030
|
+
case 3:
|
|
2031
|
+
d.body.appendChild(root);
|
|
2032
|
+
try {
|
|
2033
|
+
// Then check which of the elements are blocked
|
|
2034
|
+
for (i = 0; i < selectors.length; ++i) {
|
|
2035
|
+
if (!elements[i].offsetParent) {
|
|
2036
|
+
blockedSelectors[selectors[i]] = true;
|
|
2037
|
+
}
|
|
2038
|
+
}
|
|
2039
|
+
}
|
|
2040
|
+
finally {
|
|
2041
|
+
// Then remove the elements
|
|
2042
|
+
(_a = root.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(root);
|
|
2043
|
+
}
|
|
2044
|
+
return [2 /*return*/, blockedSelectors];
|
|
2045
|
+
}
|
|
2046
|
+
});
|
|
2047
|
+
});
|
|
2048
|
+
}
|
|
2049
|
+
function forceShow(element) {
|
|
2050
|
+
element.style.setProperty('display', 'block', 'important');
|
|
2051
|
+
}
|
|
2052
|
+
function printDebug(blockedSelectors) {
|
|
2053
|
+
var message = 'DOM blockers debug:\n```';
|
|
2054
|
+
for (var _i = 0, _a = Object.keys(filters); _i < _a.length; _i++) {
|
|
2055
|
+
var filterName = _a[_i];
|
|
2056
|
+
message += "\n" + filterName + ":";
|
|
2057
|
+
for (var _b = 0, _c = filters[filterName]; _b < _c.length; _b++) {
|
|
2058
|
+
var selector = _c[_b];
|
|
2059
|
+
message += "\n " + selector + " " + (blockedSelectors[selector] ? '🚫' : '➡️');
|
|
2060
|
+
}
|
|
2061
|
+
}
|
|
2062
|
+
// console.log is ok here because it's under a debug clause
|
|
2063
|
+
// eslint-disable-next-line no-console
|
|
2064
|
+
console.log(message + "\n```");
|
|
2065
|
+
}
|
|
2066
|
+
|
|
2067
|
+
/**
|
|
2068
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/@media/color-gamut
|
|
2069
|
+
*/
|
|
2070
|
+
function getColorGamut() {
|
|
2071
|
+
// rec2020 includes p3 and p3 includes srgb
|
|
2072
|
+
for (var _i = 0, _a = ['rec2020', 'p3', 'srgb']; _i < _a.length; _i++) {
|
|
2073
|
+
var gamut = _a[_i];
|
|
2074
|
+
if (matchMedia("(color-gamut: " + gamut + ")").matches) {
|
|
2075
|
+
return gamut;
|
|
2076
|
+
}
|
|
2077
|
+
}
|
|
2078
|
+
return undefined;
|
|
2079
|
+
}
|
|
2080
|
+
|
|
2081
|
+
/**
|
|
2082
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/@media/inverted-colors
|
|
2083
|
+
*/
|
|
2084
|
+
function areColorsInverted() {
|
|
2085
|
+
if (doesMatch('inverted')) {
|
|
2086
|
+
return true;
|
|
2087
|
+
}
|
|
2088
|
+
if (doesMatch('none')) {
|
|
2089
|
+
return false;
|
|
2090
|
+
}
|
|
2091
|
+
return undefined;
|
|
2092
|
+
}
|
|
2093
|
+
function doesMatch(value) {
|
|
2094
|
+
return matchMedia("(inverted-colors: " + value + ")").matches;
|
|
2095
|
+
}
|
|
2096
|
+
|
|
2097
|
+
/**
|
|
2098
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/@media/forced-colors
|
|
2099
|
+
*/
|
|
2100
|
+
function areColorsForced() {
|
|
2101
|
+
if (doesMatch$1('active')) {
|
|
2102
|
+
return true;
|
|
2103
|
+
}
|
|
2104
|
+
if (doesMatch$1('none')) {
|
|
2105
|
+
return false;
|
|
2106
|
+
}
|
|
2107
|
+
return undefined;
|
|
2108
|
+
}
|
|
2109
|
+
function doesMatch$1(value) {
|
|
2110
|
+
return matchMedia("(forced-colors: " + value + ")").matches;
|
|
2111
|
+
}
|
|
2112
|
+
|
|
2113
|
+
var maxValueToCheck = 100;
|
|
2114
|
+
/**
|
|
2115
|
+
* If the display is monochrome (e.g. black&white), the value will be ≥0 and will mean the number of bits per pixel.
|
|
2116
|
+
* If the display is not monochrome, the returned value will be 0.
|
|
2117
|
+
* If the browser doesn't support this feature, the returned value will be undefined.
|
|
2118
|
+
*
|
|
2119
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/@media/monochrome
|
|
2120
|
+
*/
|
|
2121
|
+
function getMonochromeDepth() {
|
|
2122
|
+
if (!matchMedia('(min-monochrome: 0)').matches) {
|
|
2123
|
+
// The media feature isn't supported by the browser
|
|
2124
|
+
return undefined;
|
|
2125
|
+
}
|
|
2126
|
+
// A variation of binary search algorithm can be used here.
|
|
2127
|
+
// But since expected values are very small (≤10), there is no sense in adding the complexity.
|
|
2128
|
+
for (var i = 0; i <= maxValueToCheck; ++i) {
|
|
2129
|
+
if (matchMedia("(max-monochrome: " + i + ")").matches) {
|
|
2130
|
+
return i;
|
|
2131
|
+
}
|
|
2132
|
+
}
|
|
2133
|
+
throw new Error('Too high value');
|
|
2134
|
+
}
|
|
2135
|
+
|
|
2136
|
+
/**
|
|
2137
|
+
* @see https://www.w3.org/TR/mediaqueries-5/#prefers-contrast
|
|
2138
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-contrast
|
|
2139
|
+
*/
|
|
2140
|
+
function getContrastPreference() {
|
|
2141
|
+
if (doesMatch$2('no-preference')) {
|
|
2142
|
+
return 0 /* None */;
|
|
2143
|
+
}
|
|
2144
|
+
// The sources contradict on the keywords. Probably 'high' and 'low' will never be implemented.
|
|
2145
|
+
// Need to check it when all browsers implement the feature.
|
|
2146
|
+
if (doesMatch$2('high') || doesMatch$2('more')) {
|
|
2147
|
+
return 1 /* More */;
|
|
2148
|
+
}
|
|
2149
|
+
if (doesMatch$2('low') || doesMatch$2('less')) {
|
|
2150
|
+
return -1 /* Less */;
|
|
2151
|
+
}
|
|
2152
|
+
if (doesMatch$2('forced')) {
|
|
2153
|
+
return 10 /* ForcedColors */;
|
|
2154
|
+
}
|
|
2155
|
+
return undefined;
|
|
2156
|
+
}
|
|
2157
|
+
function doesMatch$2(value) {
|
|
2158
|
+
return matchMedia("(prefers-contrast: " + value + ")").matches;
|
|
2159
|
+
}
|
|
2160
|
+
|
|
2161
|
+
/**
|
|
2162
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-motion
|
|
2163
|
+
*/
|
|
2164
|
+
function isMotionReduced() {
|
|
2165
|
+
if (doesMatch$3('reduce')) {
|
|
2166
|
+
return true;
|
|
2167
|
+
}
|
|
2168
|
+
if (doesMatch$3('no-preference')) {
|
|
2169
|
+
return false;
|
|
2170
|
+
}
|
|
2171
|
+
return undefined;
|
|
2172
|
+
}
|
|
2173
|
+
function doesMatch$3(value) {
|
|
2174
|
+
return matchMedia("(prefers-reduced-motion: " + value + ")").matches;
|
|
2175
|
+
}
|
|
2176
|
+
|
|
2177
|
+
/**
|
|
2178
|
+
* @see https://www.w3.org/TR/mediaqueries-5/#dynamic-range
|
|
2179
|
+
*/
|
|
2180
|
+
function isHDR() {
|
|
2181
|
+
if (doesMatch$4('high')) {
|
|
2182
|
+
return true;
|
|
2183
|
+
}
|
|
2184
|
+
if (doesMatch$4('standard')) {
|
|
2185
|
+
return false;
|
|
2186
|
+
}
|
|
2187
|
+
return undefined;
|
|
2188
|
+
}
|
|
2189
|
+
function doesMatch$4(value) {
|
|
2190
|
+
return matchMedia("(dynamic-range: " + value + ")").matches;
|
|
2191
|
+
}
|
|
2192
|
+
|
|
2193
|
+
var M = Math; // To reduce the minified code size
|
|
2194
|
+
var fallbackFn = function () { return 0; };
|
|
2195
|
+
/**
|
|
2196
|
+
* @see https://gitlab.torproject.org/legacy/trac/-/issues/13018
|
|
2197
|
+
* @see https://bugzilla.mozilla.org/show_bug.cgi?id=531915
|
|
2198
|
+
*/
|
|
2199
|
+
function getMathFingerprint() {
|
|
2200
|
+
// Native operations
|
|
2201
|
+
var acos = M.acos || fallbackFn;
|
|
2202
|
+
var acosh = M.acosh || fallbackFn;
|
|
2203
|
+
var asin = M.asin || fallbackFn;
|
|
2204
|
+
var asinh = M.asinh || fallbackFn;
|
|
2205
|
+
var atanh = M.atanh || fallbackFn;
|
|
2206
|
+
var atan = M.atan || fallbackFn;
|
|
2207
|
+
var sin = M.sin || fallbackFn;
|
|
2208
|
+
var sinh = M.sinh || fallbackFn;
|
|
2209
|
+
var cos = M.cos || fallbackFn;
|
|
2210
|
+
var cosh = M.cosh || fallbackFn;
|
|
2211
|
+
var tan = M.tan || fallbackFn;
|
|
2212
|
+
var tanh = M.tanh || fallbackFn;
|
|
2213
|
+
var exp = M.exp || fallbackFn;
|
|
2214
|
+
var expm1 = M.expm1 || fallbackFn;
|
|
2215
|
+
var log1p = M.log1p || fallbackFn;
|
|
2216
|
+
// Operation polyfills
|
|
2217
|
+
var powPI = function (value) { return M.pow(M.PI, value); };
|
|
2218
|
+
var acoshPf = function (value) { return M.log(value + M.sqrt(value * value - 1)); };
|
|
2219
|
+
var asinhPf = function (value) { return M.log(value + M.sqrt(value * value + 1)); };
|
|
2220
|
+
var atanhPf = function (value) { return M.log((1 + value) / (1 - value)) / 2; };
|
|
2221
|
+
var sinhPf = function (value) { return M.exp(value) - 1 / M.exp(value) / 2; };
|
|
2222
|
+
var coshPf = function (value) { return (M.exp(value) + 1 / M.exp(value)) / 2; };
|
|
2223
|
+
var expm1Pf = function (value) { return M.exp(value) - 1; };
|
|
2224
|
+
var tanhPf = function (value) { return (M.exp(2 * value) - 1) / (M.exp(2 * value) + 1); };
|
|
2225
|
+
var log1pPf = function (value) { return M.log(1 + value); };
|
|
2226
|
+
// Note: constant values are empirical
|
|
2227
|
+
return {
|
|
2228
|
+
acos: acos(0.123124234234234242),
|
|
2229
|
+
acosh: acosh(1e308),
|
|
2230
|
+
acoshPf: acoshPf(1e154),
|
|
2231
|
+
asin: asin(0.123124234234234242),
|
|
2232
|
+
asinh: asinh(1),
|
|
2233
|
+
asinhPf: asinhPf(1),
|
|
2234
|
+
atanh: atanh(0.5),
|
|
2235
|
+
atanhPf: atanhPf(0.5),
|
|
2236
|
+
atan: atan(0.5),
|
|
2237
|
+
sin: sin(-1e300),
|
|
2238
|
+
sinh: sinh(1),
|
|
2239
|
+
sinhPf: sinhPf(1),
|
|
2240
|
+
cos: cos(10.000000000123),
|
|
2241
|
+
cosh: cosh(1),
|
|
2242
|
+
coshPf: coshPf(1),
|
|
2243
|
+
tan: tan(-1e300),
|
|
2244
|
+
tanh: tanh(1),
|
|
2245
|
+
tanhPf: tanhPf(1),
|
|
2246
|
+
exp: exp(1),
|
|
2247
|
+
expm1: expm1(1),
|
|
2248
|
+
expm1Pf: expm1Pf(1),
|
|
2249
|
+
log1p: log1p(10),
|
|
2250
|
+
log1pPf: log1pPf(10),
|
|
2251
|
+
powPI: powPI(-100),
|
|
2252
|
+
};
|
|
2253
|
+
}
|
|
2254
|
+
|
|
2255
|
+
/**
|
|
2256
|
+
* We use m or w because these two characters take up the maximum width.
|
|
2257
|
+
* Also there are a couple of ligatures.
|
|
2258
|
+
*/
|
|
2259
|
+
var defaultText = 'mmMwWLliI0fiflO&1';
|
|
2260
|
+
/**
|
|
2261
|
+
* Settings of text blocks to measure. The keys are random but persistent words.
|
|
2262
|
+
*/
|
|
2263
|
+
var presets = {
|
|
2264
|
+
/**
|
|
2265
|
+
* The default font. User can change it in desktop Chrome, desktop Firefox, IE 11,
|
|
2266
|
+
* Android Chrome (but only when the size is ≥ than the default) and Android Firefox.
|
|
2267
|
+
*/
|
|
2268
|
+
default: [],
|
|
2269
|
+
/** OS font on macOS. User can change its size and weight. Applies after Safari restart. */
|
|
2270
|
+
apple: [{ font: '-apple-system-body' }],
|
|
2271
|
+
/** User can change it in desktop Chrome and desktop Firefox. */
|
|
2272
|
+
serif: [{ fontFamily: 'serif' }],
|
|
2273
|
+
/** User can change it in desktop Chrome and desktop Firefox. */
|
|
2274
|
+
sans: [{ fontFamily: 'sans-serif' }],
|
|
2275
|
+
/** User can change it in desktop Chrome and desktop Firefox. */
|
|
2276
|
+
mono: [{ fontFamily: 'monospace' }],
|
|
2277
|
+
/**
|
|
2278
|
+
* Check the smallest allowed font size. User can change it in desktop Chrome, desktop Firefox and desktop Safari.
|
|
2279
|
+
* The height can be 0 in Chrome on a retina display.
|
|
2280
|
+
*/
|
|
2281
|
+
min: [{ fontSize: '1px' }],
|
|
2282
|
+
/** Tells one OS from another in desktop Chrome. */
|
|
2283
|
+
system: [{ fontFamily: 'system-ui' }],
|
|
2284
|
+
};
|
|
2285
|
+
/**
|
|
2286
|
+
* The result is a dictionary of the width of the text samples.
|
|
2287
|
+
* Heights aren't included because they give no extra entropy and are unstable.
|
|
2288
|
+
*
|
|
2289
|
+
* The result is very stable in IE 11, Edge 18 and Safari 14.
|
|
2290
|
+
* The result changes when the OS pixel density changes in Chromium 87. The real pixel density is required to solve,
|
|
2291
|
+
* but seems like it's impossible: https://stackoverflow.com/q/1713771/1118709.
|
|
2292
|
+
* The "min" and the "mono" (only on Windows) value may change when the page is zoomed in Firefox 87.
|
|
2293
|
+
*/
|
|
2294
|
+
function getFontPreferences() {
|
|
2295
|
+
return withNaturalFonts(function (document, container) {
|
|
2296
|
+
var elements = {};
|
|
2297
|
+
var sizes = {};
|
|
2298
|
+
// First create all elements to measure. If the DOM steps below are done in a single cycle,
|
|
2299
|
+
// browser will alternate tree modification and layout reading, that is very slow.
|
|
2300
|
+
for (var _i = 0, _a = Object.keys(presets); _i < _a.length; _i++) {
|
|
2301
|
+
var key = _a[_i];
|
|
2302
|
+
var _b = presets[key], _c = _b[0], style = _c === void 0 ? {} : _c, _d = _b[1], text = _d === void 0 ? defaultText : _d;
|
|
2303
|
+
var element = document.createElement('span');
|
|
2304
|
+
element.textContent = text;
|
|
2305
|
+
element.style.whiteSpace = 'nowrap';
|
|
2306
|
+
for (var _e = 0, _f = Object.keys(style); _e < _f.length; _e++) {
|
|
2307
|
+
var name_1 = _f[_e];
|
|
2308
|
+
var value = style[name_1];
|
|
2309
|
+
if (value !== undefined) {
|
|
2310
|
+
element.style[name_1] = value;
|
|
2311
|
+
}
|
|
2312
|
+
}
|
|
2313
|
+
elements[key] = element;
|
|
2314
|
+
container.appendChild(document.createElement('br'));
|
|
2315
|
+
container.appendChild(element);
|
|
2316
|
+
}
|
|
2317
|
+
// Then measure the created elements
|
|
2318
|
+
for (var _g = 0, _h = Object.keys(presets); _g < _h.length; _g++) {
|
|
2319
|
+
var key = _h[_g];
|
|
2320
|
+
sizes[key] = elements[key].getBoundingClientRect().width;
|
|
2321
|
+
}
|
|
2322
|
+
return sizes;
|
|
2323
|
+
});
|
|
2324
|
+
}
|
|
2325
|
+
/**
|
|
2326
|
+
* Creates a DOM environment that provides the most natural font available, including Android OS font.
|
|
2327
|
+
* Measurements of the elements are zoom-independent.
|
|
2328
|
+
* Don't put a content to measure inside an absolutely positioned element.
|
|
2329
|
+
*/
|
|
2330
|
+
function withNaturalFonts(action, containerWidthPx) {
|
|
2331
|
+
if (containerWidthPx === void 0) { containerWidthPx = 4000; }
|
|
2332
|
+
/*
|
|
2333
|
+
* Requirements for Android Chrome to apply the system font size to a text inside an iframe:
|
|
2334
|
+
* - The iframe mustn't have a `display: none;` style;
|
|
2335
|
+
* - The text mustn't be positioned absolutely;
|
|
2336
|
+
* - The text block must be wide enough.
|
|
2337
|
+
* 2560px on some devices in portrait orientation for the biggest font size option (32px);
|
|
2338
|
+
* - There must be much enough text to form a few lines (I don't know the exact numbers);
|
|
2339
|
+
* - The text must have the `text-size-adjust: none` style. Otherwise the text will scale in "Desktop site" mode;
|
|
2340
|
+
*
|
|
2341
|
+
* Requirements for Android Firefox to apply the system font size to a text inside an iframe:
|
|
2342
|
+
* - The iframe document must have a header: `<meta name="viewport" content="width=device-width, initial-scale=1" />`.
|
|
2343
|
+
* The only way to set it is to use the `srcdoc` attribute of the iframe;
|
|
2344
|
+
* - The iframe content must get loaded before adding extra content with JavaScript;
|
|
2345
|
+
*
|
|
2346
|
+
* https://example.com as the iframe target always inherits Android font settings so it can be used as a reference.
|
|
2347
|
+
*
|
|
2348
|
+
* Observations on how page zoom affects the measurements:
|
|
2349
|
+
* - macOS Safari 11.1, 12.1, 13.1, 14.0: zoom reset + offsetWidth = 100% reliable;
|
|
2350
|
+
* - macOS Safari 11.1, 12.1, 13.1, 14.0: zoom reset + getBoundingClientRect = 100% reliable;
|
|
2351
|
+
* - macOS Safari 14.0: offsetWidth = 5% fluctuation;
|
|
2352
|
+
* - macOS Safari 14.0: getBoundingClientRect = 5% fluctuation;
|
|
2353
|
+
* - iOS Safari 9, 10, 11.0, 12.0: haven't found a way to zoom a page (pinch doesn't change layout);
|
|
2354
|
+
* - iOS Safari 13.1, 14.0: zoom reset + offsetWidth = 100% reliable;
|
|
2355
|
+
* - iOS Safari 13.1, 14.0: zoom reset + getBoundingClientRect = 100% reliable;
|
|
2356
|
+
* - iOS Safari 14.0: offsetWidth = 100% reliable;
|
|
2357
|
+
* - iOS Safari 14.0: getBoundingClientRect = 100% reliable;
|
|
2358
|
+
* - Chrome 42, 65, 80, 87: zoom 1/devicePixelRatio + offsetWidth = 1px fluctuation;
|
|
2359
|
+
* - Chrome 42, 65, 80, 87: zoom 1/devicePixelRatio + getBoundingClientRect = 100% reliable;
|
|
2360
|
+
* - Chrome 87: offsetWidth = 1px fluctuation;
|
|
2361
|
+
* - Chrome 87: getBoundingClientRect = 0.7px fluctuation;
|
|
2362
|
+
* - Firefox 48, 51: offsetWidth = 10% fluctuation;
|
|
2363
|
+
* - Firefox 48, 51: getBoundingClientRect = 10% fluctuation;
|
|
2364
|
+
* - Firefox 52, 53, 57, 62, 66, 67, 68, 71, 75, 80, 84: offsetWidth = width 100% reliable, height 10% fluctuation;
|
|
2365
|
+
* - Firefox 52, 53, 57, 62, 66, 67, 68, 71, 75, 80, 84: getBoundingClientRect = width 100% reliable, height 10%
|
|
2366
|
+
* fluctuation;
|
|
2367
|
+
* - Android Chrome 86: haven't found a way to zoom a page (pinch doesn't change layout);
|
|
2368
|
+
* - Android Firefox 84: font size in accessibility settings changes all the CSS sizes, but offsetWidth and
|
|
2369
|
+
* getBoundingClientRect keep measuring with regular units, so the size reflects the font size setting and doesn't
|
|
2370
|
+
* fluctuate;
|
|
2371
|
+
* - IE 11, Edge 18: zoom 1/devicePixelRatio + offsetWidth = 100% reliable;
|
|
2372
|
+
* - IE 11, Edge 18: zoom 1/devicePixelRatio + getBoundingClientRect = reflects the zoom level;
|
|
2373
|
+
* - IE 11, Edge 18: offsetWidth = 100% reliable;
|
|
2374
|
+
* - IE 11, Edge 18: getBoundingClientRect = 100% reliable;
|
|
2375
|
+
*/
|
|
2376
|
+
return withIframe(function (_, iframeWindow) {
|
|
2377
|
+
var iframeDocument = iframeWindow.document;
|
|
2378
|
+
var iframeBody = iframeDocument.body;
|
|
2379
|
+
var bodyStyle = iframeBody.style;
|
|
2380
|
+
bodyStyle.width = containerWidthPx + "px";
|
|
2381
|
+
bodyStyle.webkitTextSizeAdjust = bodyStyle.textSizeAdjust = 'none';
|
|
2382
|
+
// See the big comment above
|
|
2383
|
+
if (isChromium()) {
|
|
2384
|
+
iframeBody.style.zoom = "" + 1 / iframeWindow.devicePixelRatio;
|
|
2385
|
+
}
|
|
2386
|
+
else if (isWebKit()) {
|
|
2387
|
+
iframeBody.style.zoom = 'reset';
|
|
2388
|
+
}
|
|
2389
|
+
// See the big comment above
|
|
2390
|
+
var linesOfText = iframeDocument.createElement('div');
|
|
2391
|
+
linesOfText.textContent = __spreadArrays(Array((containerWidthPx / 20) << 0)).map(function () { return 'word'; }).join(' ');
|
|
2392
|
+
iframeBody.appendChild(linesOfText);
|
|
2393
|
+
return action(iframeDocument, iframeBody);
|
|
2394
|
+
}, '<!doctype html><html><head><meta name="viewport" content="width=device-width, initial-scale=1">');
|
|
2395
|
+
}
|
|
2396
|
+
|
|
2397
|
+
/**
|
|
2398
|
+
* The list of entropy sources used to make visitor identifiers.
|
|
2399
|
+
*
|
|
2400
|
+
* This value isn't restricted by Semantic Versioning, i.e. it may be changed without bumping minor or major version of
|
|
2401
|
+
* this package.
|
|
2402
|
+
*/
|
|
2403
|
+
var sources = {
|
|
2404
|
+
// READ FIRST:
|
|
2405
|
+
// See https://github.com/fingerprintjs/fingerprintjs/blob/master/contributing.md#how-to-make-an-entropy-source
|
|
2406
|
+
// to learn how entropy source works and how to make your own.
|
|
2407
|
+
// The sources run in this exact order.
|
|
2408
|
+
// The asynchronous sources are at the start to run in parallel with other sources.
|
|
2409
|
+
fonts: getFonts,
|
|
2410
|
+
domBlockers: getDomBlockers,
|
|
2411
|
+
fontPreferences: getFontPreferences,
|
|
2412
|
+
audio: getAudioFingerprint,
|
|
2413
|
+
screenFrame: getRoundedScreenFrame,
|
|
2414
|
+
osCpu: getOsCpu,
|
|
2415
|
+
languages: getLanguages,
|
|
2416
|
+
colorDepth: getColorDepth,
|
|
2417
|
+
deviceMemory: getDeviceMemory,
|
|
2418
|
+
screenResolution: getScreenResolution,
|
|
2419
|
+
hardwareConcurrency: getHardwareConcurrency,
|
|
2420
|
+
timezone: getTimezone,
|
|
2421
|
+
sessionStorage: getSessionStorage,
|
|
2422
|
+
localStorage: getLocalStorage,
|
|
2423
|
+
indexedDB: getIndexedDB,
|
|
2424
|
+
openDatabase: getOpenDatabase,
|
|
2425
|
+
cpuClass: getCpuClass,
|
|
2426
|
+
platform: getPlatform,
|
|
2427
|
+
plugins: getPlugins,
|
|
2428
|
+
canvas: getCanvasFingerprint,
|
|
2429
|
+
touchSupport: getTouchSupport,
|
|
2430
|
+
vendor: getVendor,
|
|
2431
|
+
vendorFlavors: getVendorFlavors,
|
|
2432
|
+
cookiesEnabled: areCookiesEnabled,
|
|
2433
|
+
colorGamut: getColorGamut,
|
|
2434
|
+
invertedColors: areColorsInverted,
|
|
2435
|
+
forcedColors: areColorsForced,
|
|
2436
|
+
monochrome: getMonochromeDepth,
|
|
2437
|
+
contrast: getContrastPreference,
|
|
2438
|
+
reducedMotion: isMotionReduced,
|
|
2439
|
+
hdr: isHDR,
|
|
2440
|
+
math: getMathFingerprint,
|
|
2441
|
+
};
|
|
2442
|
+
/**
|
|
2443
|
+
* Loads the built-in entropy sources.
|
|
2444
|
+
* Returns a function that collects the entropy components to make the visitor identifier.
|
|
2445
|
+
*/
|
|
2446
|
+
function loadBuiltinSources(options) {
|
|
2447
|
+
return loadSources(sources, options, []);
|
|
2448
|
+
}
|
|
2449
|
+
|
|
2450
|
+
var commentTemplate = '$ if upgrade to Pro: https://fpjs.dev/pro';
|
|
2451
|
+
function getConfidence(components) {
|
|
2452
|
+
var openConfidenceScore = getOpenConfidenceScore(components);
|
|
2453
|
+
var proConfidenceScore = deriveProConfidenceScore(openConfidenceScore);
|
|
2454
|
+
return { score: openConfidenceScore, comment: commentTemplate.replace(/\$/g, "" + proConfidenceScore) };
|
|
2455
|
+
}
|
|
2456
|
+
function getOpenConfidenceScore(components) {
|
|
2457
|
+
// In order to calculate the true probability of the visitor identifier being correct, we need to know the number of
|
|
2458
|
+
// website visitors (the higher the number, the less the probability because the fingerprint entropy is limited).
|
|
2459
|
+
// JS agent doesn't know the number of visitors, so we can only do an approximate assessment.
|
|
2460
|
+
if (isAndroid()) {
|
|
2461
|
+
return 0.4;
|
|
2462
|
+
}
|
|
2463
|
+
// Safari (mobile and desktop)
|
|
2464
|
+
if (isWebKit()) {
|
|
2465
|
+
return isDesktopSafari() ? 0.5 : 0.3;
|
|
2466
|
+
}
|
|
2467
|
+
var platform = components.platform.value || '';
|
|
2468
|
+
// Windows
|
|
2469
|
+
if (/^Win/.test(platform)) {
|
|
2470
|
+
// The score is greater than on macOS because of the higher variety of devices running Windows.
|
|
2471
|
+
// Chrome provides more entropy than Firefox according too
|
|
2472
|
+
// 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
|
|
2473
|
+
// So we assign the same score to them.
|
|
2474
|
+
return 0.6;
|
|
2475
|
+
}
|
|
2476
|
+
// macOS
|
|
2477
|
+
if (/^Mac/.test(platform)) {
|
|
2478
|
+
// Chrome provides more entropy than Safari and Safari provides more entropy than Firefox.
|
|
2479
|
+
// Chrome is more popular than Safari and Safari is more popular than Firefox according to
|
|
2480
|
+
// 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
|
|
2481
|
+
// So we assign the same score to them.
|
|
2482
|
+
return 0.5;
|
|
2483
|
+
}
|
|
2484
|
+
// Another platform, e.g. a desktop Linux. It's rare, so it should be pretty unique.
|
|
2485
|
+
return 0.7;
|
|
2486
|
+
}
|
|
2487
|
+
function deriveProConfidenceScore(openConfidenceScore) {
|
|
2488
|
+
return round(0.99 + 0.01 * openConfidenceScore, 0.0001);
|
|
2489
|
+
}
|
|
2490
|
+
|
|
2491
|
+
function componentsToCanonicalString(components) {
|
|
2492
|
+
var result = '';
|
|
2493
|
+
for (var _i = 0, _a = Object.keys(components).sort(); _i < _a.length; _i++) {
|
|
2494
|
+
var componentKey = _a[_i];
|
|
2495
|
+
var component = components[componentKey];
|
|
2496
|
+
var value = component.error ? 'error' : JSON.stringify(component.value);
|
|
2497
|
+
result += "" + (result ? '|' : '') + componentKey.replace(/([:|\\])/g, '\\$1') + ":" + value;
|
|
2498
|
+
}
|
|
2499
|
+
return result;
|
|
2500
|
+
}
|
|
2501
|
+
function componentsToDebugString(components) {
|
|
2502
|
+
return JSON.stringify(components, function (_key, value) {
|
|
2503
|
+
if (value instanceof Error) {
|
|
2504
|
+
return errorToObject(value);
|
|
2505
|
+
}
|
|
2506
|
+
return value;
|
|
2507
|
+
}, 2);
|
|
2508
|
+
}
|
|
2509
|
+
function hashComponents(components) {
|
|
2510
|
+
return x64hash128(componentsToCanonicalString(components));
|
|
2511
|
+
}
|
|
2512
|
+
/**
|
|
2513
|
+
* Makes a GetResult implementation that calculates the visitor id hash on demand.
|
|
2514
|
+
* Designed for optimisation.
|
|
2515
|
+
*/
|
|
2516
|
+
function makeLazyGetResult(components) {
|
|
2517
|
+
var visitorIdCache;
|
|
2518
|
+
// This function runs very fast, so there is no need to make it lazy
|
|
2519
|
+
var confidence = getConfidence(components);
|
|
2520
|
+
// A plain class isn't used because its getters and setters aren't enumerable.
|
|
2521
|
+
return {
|
|
2522
|
+
get visitorId() {
|
|
2523
|
+
if (visitorIdCache === undefined) {
|
|
2524
|
+
visitorIdCache = hashComponents(this.components);
|
|
2525
|
+
}
|
|
2526
|
+
return visitorIdCache;
|
|
2527
|
+
},
|
|
2528
|
+
set visitorId(visitorId) {
|
|
2529
|
+
visitorIdCache = visitorId;
|
|
2530
|
+
},
|
|
2531
|
+
confidence: confidence,
|
|
2532
|
+
components: components,
|
|
2533
|
+
version: version,
|
|
2534
|
+
};
|
|
2535
|
+
}
|
|
2536
|
+
/**
|
|
2537
|
+
* A delay is required to ensure consistent entropy components.
|
|
2538
|
+
* See https://github.com/fingerprintjs/fingerprintjs/issues/254
|
|
2539
|
+
* and https://github.com/fingerprintjs/fingerprintjs/issues/307
|
|
2540
|
+
* and https://github.com/fingerprintjs/fingerprintjs/commit/945633e7c5f67ae38eb0fea37349712f0e669b18
|
|
2541
|
+
*/
|
|
2542
|
+
function prepareForSources(delayFallback) {
|
|
2543
|
+
if (delayFallback === void 0) { delayFallback = 50; }
|
|
2544
|
+
// A proper deadline is unknown. Let it be twice the fallback timeout so that both cases have the same average time.
|
|
2545
|
+
return requestIdleCallbackIfAvailable(delayFallback, delayFallback * 2);
|
|
2546
|
+
}
|
|
2547
|
+
/**
|
|
2548
|
+
* The function isn't exported from the index file to not allow to call it without `load()`.
|
|
2549
|
+
* The hiding gives more freedom for future non-breaking updates.
|
|
2550
|
+
*
|
|
2551
|
+
* A factory function is used instead of a class to shorten the attribute names in the minified code.
|
|
2552
|
+
* Native private class fields could've been used, but TypeScript doesn't allow them with `"target": "es5"`.
|
|
2553
|
+
*/
|
|
2554
|
+
function makeAgent(getComponents, debug) {
|
|
2555
|
+
var creationTime = Date.now();
|
|
2556
|
+
return {
|
|
2557
|
+
get: function (options) {
|
|
2558
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2559
|
+
var startTime, components, result;
|
|
2560
|
+
return __generator(this, function (_a) {
|
|
2561
|
+
switch (_a.label) {
|
|
2562
|
+
case 0:
|
|
2563
|
+
startTime = Date.now();
|
|
2564
|
+
return [4 /*yield*/, getComponents()];
|
|
2565
|
+
case 1:
|
|
2566
|
+
components = _a.sent();
|
|
2567
|
+
result = makeLazyGetResult(components);
|
|
2568
|
+
if (debug || (options === null || options === void 0 ? void 0 : options.debug)) {
|
|
2569
|
+
// console.log is ok here because it's under a debug clause
|
|
2570
|
+
// eslint-disable-next-line no-console
|
|
2571
|
+
console.log("Copy the text below to get the debug data:\n\n```\nversion: " + result.version + "\nuserAgent: " + navigator.userAgent + "\ntimeBetweenLoadAndGet: " + (startTime - creationTime) + "\nvisitorId: " + result.visitorId + "\ncomponents: " + componentsToDebugString(components) + "\n```");
|
|
2572
|
+
}
|
|
2573
|
+
return [2 /*return*/, result];
|
|
2574
|
+
}
|
|
2575
|
+
});
|
|
2576
|
+
});
|
|
2577
|
+
},
|
|
2578
|
+
};
|
|
2579
|
+
}
|
|
2580
|
+
/**
|
|
2581
|
+
* Sends an unpersonalized AJAX request to collect installation statistics
|
|
2582
|
+
*/
|
|
2583
|
+
function monitor() {
|
|
2584
|
+
// The FingerprintJS CDN (https://github.com/fingerprintjs/cdn) replaces `window.__fpjs_d_m` with `true`
|
|
2585
|
+
if (window.__fpjs_d_m || Math.random() >= 0.001) {
|
|
2586
|
+
return;
|
|
2587
|
+
}
|
|
2588
|
+
try {
|
|
2589
|
+
var request = new XMLHttpRequest();
|
|
2590
|
+
request.open('get', "https://m1.openfpcdn.io/fingerprintjs/v" + version + "/npm-monitoring", true);
|
|
2591
|
+
request.send();
|
|
2592
|
+
}
|
|
2593
|
+
catch (error) {
|
|
2594
|
+
// console.error is ok here because it's an unexpected error handler
|
|
2595
|
+
// eslint-disable-next-line no-console
|
|
2596
|
+
console.error(error);
|
|
2597
|
+
}
|
|
2598
|
+
}
|
|
2599
|
+
/**
|
|
2600
|
+
* Builds an instance of Agent and waits a delay required for a proper operation.
|
|
2601
|
+
*/
|
|
2602
|
+
function load(_a) {
|
|
2603
|
+
var _b = _a === void 0 ? {} : _a, delayFallback = _b.delayFallback, debug = _b.debug, _c = _b.monitoring, monitoring = _c === void 0 ? true : _c;
|
|
2604
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2605
|
+
var getComponents;
|
|
2606
|
+
return __generator(this, function (_d) {
|
|
2607
|
+
switch (_d.label) {
|
|
2608
|
+
case 0:
|
|
2609
|
+
if (monitoring) {
|
|
2610
|
+
monitor();
|
|
2611
|
+
}
|
|
2612
|
+
return [4 /*yield*/, prepareForSources(delayFallback)];
|
|
2613
|
+
case 1:
|
|
2614
|
+
_d.sent();
|
|
2615
|
+
getComponents = loadBuiltinSources({ debug: debug });
|
|
2616
|
+
return [2 /*return*/, makeAgent(getComponents, debug)];
|
|
2617
|
+
}
|
|
2618
|
+
});
|
|
2619
|
+
});
|
|
2620
|
+
}
|
|
2621
|
+
|
|
2622
|
+
// Unique ID creation requires a high quality random # generator. In the browser we therefore
|
|
2623
|
+
// require the crypto API and do not support built-in fallback to lower quality random number
|
|
2624
|
+
// generators (like Math.random()).
|
|
2625
|
+
var getRandomValues;
|
|
2626
|
+
var rnds8 = new Uint8Array(16);
|
|
2627
|
+
function rng() {
|
|
2628
|
+
// lazy load so that environments that need to polyfill have a chance to do so
|
|
2629
|
+
if (!getRandomValues) {
|
|
2630
|
+
// getRandomValues needs to be invoked in a context where "this" is a Crypto implementation. Also,
|
|
2631
|
+
// find the complete implementation of crypto (msCrypto) on IE11.
|
|
2632
|
+
getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto !== 'undefined' && typeof msCrypto.getRandomValues === 'function' && msCrypto.getRandomValues.bind(msCrypto);
|
|
2633
|
+
|
|
2634
|
+
if (!getRandomValues) {
|
|
2635
|
+
throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
|
|
2636
|
+
}
|
|
2637
|
+
}
|
|
2638
|
+
|
|
2639
|
+
return getRandomValues(rnds8);
|
|
2640
|
+
}
|
|
2641
|
+
|
|
2642
|
+
var REGEX = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
|
|
2643
|
+
|
|
2644
|
+
function validate(uuid) {
|
|
2645
|
+
return typeof uuid === 'string' && REGEX.test(uuid);
|
|
2646
|
+
}
|
|
2647
|
+
|
|
2648
|
+
/**
|
|
2649
|
+
* Convert array of 16 byte values to UUID string format of the form:
|
|
2650
|
+
* XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
|
|
2651
|
+
*/
|
|
2652
|
+
|
|
2653
|
+
var byteToHex = [];
|
|
2654
|
+
|
|
2655
|
+
for (var i = 0; i < 256; ++i) {
|
|
2656
|
+
byteToHex.push((i + 0x100).toString(16).substr(1));
|
|
2657
|
+
}
|
|
2658
|
+
|
|
2659
|
+
function stringify(arr) {
|
|
2660
|
+
var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
2661
|
+
// Note: Be careful editing this code! It's been tuned for performance
|
|
2662
|
+
// and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
|
|
2663
|
+
var uuid = (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase(); // Consistency check for valid UUID. If this throws, it's likely due to one
|
|
2664
|
+
// of the following:
|
|
2665
|
+
// - One or more input array values don't map to a hex octet (leading to
|
|
2666
|
+
// "undefined" in the uuid)
|
|
2667
|
+
// - Invalid input values for the RFC `version` or `variant` fields
|
|
2668
|
+
|
|
2669
|
+
if (!validate(uuid)) {
|
|
2670
|
+
throw TypeError('Stringified UUID is invalid');
|
|
2671
|
+
}
|
|
2672
|
+
|
|
2673
|
+
return uuid;
|
|
2674
|
+
}
|
|
2675
|
+
|
|
2676
|
+
function parse(uuid) {
|
|
2677
|
+
if (!validate(uuid)) {
|
|
2678
|
+
throw TypeError('Invalid UUID');
|
|
2679
|
+
}
|
|
2680
|
+
|
|
2681
|
+
var v;
|
|
2682
|
+
var arr = new Uint8Array(16); // Parse ########-....-....-....-............
|
|
2683
|
+
|
|
2684
|
+
arr[0] = (v = parseInt(uuid.slice(0, 8), 16)) >>> 24;
|
|
2685
|
+
arr[1] = v >>> 16 & 0xff;
|
|
2686
|
+
arr[2] = v >>> 8 & 0xff;
|
|
2687
|
+
arr[3] = v & 0xff; // Parse ........-####-....-....-............
|
|
2688
|
+
|
|
2689
|
+
arr[4] = (v = parseInt(uuid.slice(9, 13), 16)) >>> 8;
|
|
2690
|
+
arr[5] = v & 0xff; // Parse ........-....-####-....-............
|
|
2691
|
+
|
|
2692
|
+
arr[6] = (v = parseInt(uuid.slice(14, 18), 16)) >>> 8;
|
|
2693
|
+
arr[7] = v & 0xff; // Parse ........-....-....-####-............
|
|
2694
|
+
|
|
2695
|
+
arr[8] = (v = parseInt(uuid.slice(19, 23), 16)) >>> 8;
|
|
2696
|
+
arr[9] = v & 0xff; // Parse ........-....-....-....-############
|
|
2697
|
+
// (Use "/" to avoid 32-bit truncation when bit-shifting high-order bytes)
|
|
2698
|
+
|
|
2699
|
+
arr[10] = (v = parseInt(uuid.slice(24, 36), 16)) / 0x10000000000 & 0xff;
|
|
2700
|
+
arr[11] = v / 0x100000000 & 0xff;
|
|
2701
|
+
arr[12] = v >>> 24 & 0xff;
|
|
2702
|
+
arr[13] = v >>> 16 & 0xff;
|
|
2703
|
+
arr[14] = v >>> 8 & 0xff;
|
|
2704
|
+
arr[15] = v & 0xff;
|
|
2705
|
+
return arr;
|
|
2706
|
+
}
|
|
2707
|
+
|
|
2708
|
+
function stringToBytes(str) {
|
|
2709
|
+
str = unescape(encodeURIComponent(str)); // UTF8 escape
|
|
2710
|
+
|
|
2711
|
+
var bytes = [];
|
|
2712
|
+
|
|
2713
|
+
for (var i = 0; i < str.length; ++i) {
|
|
2714
|
+
bytes.push(str.charCodeAt(i));
|
|
2715
|
+
}
|
|
2716
|
+
|
|
2717
|
+
return bytes;
|
|
2718
|
+
}
|
|
2719
|
+
|
|
2720
|
+
var DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
|
|
2721
|
+
var URL = '6ba7b811-9dad-11d1-80b4-00c04fd430c8';
|
|
2722
|
+
function v35 (name, version, hashfunc) {
|
|
2723
|
+
function generateUUID(value, namespace, buf, offset) {
|
|
2724
|
+
if (typeof value === 'string') {
|
|
2725
|
+
value = stringToBytes(value);
|
|
2726
|
+
}
|
|
2727
|
+
|
|
2728
|
+
if (typeof namespace === 'string') {
|
|
2729
|
+
namespace = parse(namespace);
|
|
2730
|
+
}
|
|
2731
|
+
|
|
2732
|
+
if (namespace.length !== 16) {
|
|
2733
|
+
throw TypeError('Namespace must be array-like (16 iterable integer values, 0-255)');
|
|
2734
|
+
} // Compute hash of namespace and value, Per 4.3
|
|
2735
|
+
// Future: Use spread syntax when supported on all platforms, e.g. `bytes =
|
|
2736
|
+
// hashfunc([...namespace, ... value])`
|
|
2737
|
+
|
|
2738
|
+
|
|
2739
|
+
var bytes = new Uint8Array(16 + value.length);
|
|
2740
|
+
bytes.set(namespace);
|
|
2741
|
+
bytes.set(value, namespace.length);
|
|
2742
|
+
bytes = hashfunc(bytes);
|
|
2743
|
+
bytes[6] = bytes[6] & 0x0f | version;
|
|
2744
|
+
bytes[8] = bytes[8] & 0x3f | 0x80;
|
|
2745
|
+
|
|
2746
|
+
if (buf) {
|
|
2747
|
+
offset = offset || 0;
|
|
2748
|
+
|
|
2749
|
+
for (var i = 0; i < 16; ++i) {
|
|
2750
|
+
buf[offset + i] = bytes[i];
|
|
2751
|
+
}
|
|
2752
|
+
|
|
2753
|
+
return buf;
|
|
2754
|
+
}
|
|
2755
|
+
|
|
2756
|
+
return stringify(bytes);
|
|
2757
|
+
} // Function#name is not settable on some platforms (#270)
|
|
2758
|
+
|
|
2759
|
+
|
|
2760
|
+
try {
|
|
2761
|
+
generateUUID.name = name; // eslint-disable-next-line no-empty
|
|
2762
|
+
} catch (err) {} // For CommonJS default export support
|
|
2763
|
+
|
|
2764
|
+
|
|
2765
|
+
generateUUID.DNS = DNS;
|
|
2766
|
+
generateUUID.URL = URL;
|
|
2767
|
+
return generateUUID;
|
|
2768
|
+
}
|
|
2769
|
+
|
|
2770
|
+
/*
|
|
2771
|
+
* Browser-compatible JavaScript MD5
|
|
2772
|
+
*
|
|
2773
|
+
* Modification of JavaScript MD5
|
|
2774
|
+
* https://github.com/blueimp/JavaScript-MD5
|
|
2775
|
+
*
|
|
2776
|
+
* Copyright 2011, Sebastian Tschan
|
|
2777
|
+
* https://blueimp.net
|
|
2778
|
+
*
|
|
2779
|
+
* Licensed under the MIT license:
|
|
2780
|
+
* https://opensource.org/licenses/MIT
|
|
2781
|
+
*
|
|
2782
|
+
* Based on
|
|
2783
|
+
* A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
|
|
2784
|
+
* Digest Algorithm, as defined in RFC 1321.
|
|
2785
|
+
* Version 2.2 Copyright (C) Paul Johnston 1999 - 2009
|
|
2786
|
+
* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
|
|
2787
|
+
* Distributed under the BSD License
|
|
2788
|
+
* See http://pajhome.org.uk/crypt/md5 for more info.
|
|
2789
|
+
*/
|
|
2790
|
+
function md5(bytes) {
|
|
2791
|
+
if (typeof bytes === 'string') {
|
|
2792
|
+
var msg = unescape(encodeURIComponent(bytes)); // UTF8 escape
|
|
2793
|
+
|
|
2794
|
+
bytes = new Uint8Array(msg.length);
|
|
2795
|
+
|
|
2796
|
+
for (var i = 0; i < msg.length; ++i) {
|
|
2797
|
+
bytes[i] = msg.charCodeAt(i);
|
|
2798
|
+
}
|
|
2799
|
+
}
|
|
2800
|
+
|
|
2801
|
+
return md5ToHexEncodedArray(wordsToMd5(bytesToWords(bytes), bytes.length * 8));
|
|
2802
|
+
}
|
|
2803
|
+
/*
|
|
2804
|
+
* Convert an array of little-endian words to an array of bytes
|
|
2805
|
+
*/
|
|
2806
|
+
|
|
2807
|
+
|
|
2808
|
+
function md5ToHexEncodedArray(input) {
|
|
2809
|
+
var output = [];
|
|
2810
|
+
var length32 = input.length * 32;
|
|
2811
|
+
var hexTab = '0123456789abcdef';
|
|
2812
|
+
|
|
2813
|
+
for (var i = 0; i < length32; i += 8) {
|
|
2814
|
+
var x = input[i >> 5] >>> i % 32 & 0xff;
|
|
2815
|
+
var hex = parseInt(hexTab.charAt(x >>> 4 & 0x0f) + hexTab.charAt(x & 0x0f), 16);
|
|
2816
|
+
output.push(hex);
|
|
2817
|
+
}
|
|
2818
|
+
|
|
2819
|
+
return output;
|
|
2820
|
+
}
|
|
2821
|
+
/**
|
|
2822
|
+
* Calculate output length with padding and bit length
|
|
2823
|
+
*/
|
|
2824
|
+
|
|
2825
|
+
|
|
2826
|
+
function getOutputLength(inputLength8) {
|
|
2827
|
+
return (inputLength8 + 64 >>> 9 << 4) + 14 + 1;
|
|
2828
|
+
}
|
|
2829
|
+
/*
|
|
2830
|
+
* Calculate the MD5 of an array of little-endian words, and a bit length.
|
|
2831
|
+
*/
|
|
2832
|
+
|
|
2833
|
+
|
|
2834
|
+
function wordsToMd5(x, len) {
|
|
2835
|
+
/* append padding */
|
|
2836
|
+
x[len >> 5] |= 0x80 << len % 32;
|
|
2837
|
+
x[getOutputLength(len) - 1] = len;
|
|
2838
|
+
var a = 1732584193;
|
|
2839
|
+
var b = -271733879;
|
|
2840
|
+
var c = -1732584194;
|
|
2841
|
+
var d = 271733878;
|
|
2842
|
+
|
|
2843
|
+
for (var i = 0; i < x.length; i += 16) {
|
|
2844
|
+
var olda = a;
|
|
2845
|
+
var oldb = b;
|
|
2846
|
+
var oldc = c;
|
|
2847
|
+
var oldd = d;
|
|
2848
|
+
a = md5ff(a, b, c, d, x[i], 7, -680876936);
|
|
2849
|
+
d = md5ff(d, a, b, c, x[i + 1], 12, -389564586);
|
|
2850
|
+
c = md5ff(c, d, a, b, x[i + 2], 17, 606105819);
|
|
2851
|
+
b = md5ff(b, c, d, a, x[i + 3], 22, -1044525330);
|
|
2852
|
+
a = md5ff(a, b, c, d, x[i + 4], 7, -176418897);
|
|
2853
|
+
d = md5ff(d, a, b, c, x[i + 5], 12, 1200080426);
|
|
2854
|
+
c = md5ff(c, d, a, b, x[i + 6], 17, -1473231341);
|
|
2855
|
+
b = md5ff(b, c, d, a, x[i + 7], 22, -45705983);
|
|
2856
|
+
a = md5ff(a, b, c, d, x[i + 8], 7, 1770035416);
|
|
2857
|
+
d = md5ff(d, a, b, c, x[i + 9], 12, -1958414417);
|
|
2858
|
+
c = md5ff(c, d, a, b, x[i + 10], 17, -42063);
|
|
2859
|
+
b = md5ff(b, c, d, a, x[i + 11], 22, -1990404162);
|
|
2860
|
+
a = md5ff(a, b, c, d, x[i + 12], 7, 1804603682);
|
|
2861
|
+
d = md5ff(d, a, b, c, x[i + 13], 12, -40341101);
|
|
2862
|
+
c = md5ff(c, d, a, b, x[i + 14], 17, -1502002290);
|
|
2863
|
+
b = md5ff(b, c, d, a, x[i + 15], 22, 1236535329);
|
|
2864
|
+
a = md5gg(a, b, c, d, x[i + 1], 5, -165796510);
|
|
2865
|
+
d = md5gg(d, a, b, c, x[i + 6], 9, -1069501632);
|
|
2866
|
+
c = md5gg(c, d, a, b, x[i + 11], 14, 643717713);
|
|
2867
|
+
b = md5gg(b, c, d, a, x[i], 20, -373897302);
|
|
2868
|
+
a = md5gg(a, b, c, d, x[i + 5], 5, -701558691);
|
|
2869
|
+
d = md5gg(d, a, b, c, x[i + 10], 9, 38016083);
|
|
2870
|
+
c = md5gg(c, d, a, b, x[i + 15], 14, -660478335);
|
|
2871
|
+
b = md5gg(b, c, d, a, x[i + 4], 20, -405537848);
|
|
2872
|
+
a = md5gg(a, b, c, d, x[i + 9], 5, 568446438);
|
|
2873
|
+
d = md5gg(d, a, b, c, x[i + 14], 9, -1019803690);
|
|
2874
|
+
c = md5gg(c, d, a, b, x[i + 3], 14, -187363961);
|
|
2875
|
+
b = md5gg(b, c, d, a, x[i + 8], 20, 1163531501);
|
|
2876
|
+
a = md5gg(a, b, c, d, x[i + 13], 5, -1444681467);
|
|
2877
|
+
d = md5gg(d, a, b, c, x[i + 2], 9, -51403784);
|
|
2878
|
+
c = md5gg(c, d, a, b, x[i + 7], 14, 1735328473);
|
|
2879
|
+
b = md5gg(b, c, d, a, x[i + 12], 20, -1926607734);
|
|
2880
|
+
a = md5hh(a, b, c, d, x[i + 5], 4, -378558);
|
|
2881
|
+
d = md5hh(d, a, b, c, x[i + 8], 11, -2022574463);
|
|
2882
|
+
c = md5hh(c, d, a, b, x[i + 11], 16, 1839030562);
|
|
2883
|
+
b = md5hh(b, c, d, a, x[i + 14], 23, -35309556);
|
|
2884
|
+
a = md5hh(a, b, c, d, x[i + 1], 4, -1530992060);
|
|
2885
|
+
d = md5hh(d, a, b, c, x[i + 4], 11, 1272893353);
|
|
2886
|
+
c = md5hh(c, d, a, b, x[i + 7], 16, -155497632);
|
|
2887
|
+
b = md5hh(b, c, d, a, x[i + 10], 23, -1094730640);
|
|
2888
|
+
a = md5hh(a, b, c, d, x[i + 13], 4, 681279174);
|
|
2889
|
+
d = md5hh(d, a, b, c, x[i], 11, -358537222);
|
|
2890
|
+
c = md5hh(c, d, a, b, x[i + 3], 16, -722521979);
|
|
2891
|
+
b = md5hh(b, c, d, a, x[i + 6], 23, 76029189);
|
|
2892
|
+
a = md5hh(a, b, c, d, x[i + 9], 4, -640364487);
|
|
2893
|
+
d = md5hh(d, a, b, c, x[i + 12], 11, -421815835);
|
|
2894
|
+
c = md5hh(c, d, a, b, x[i + 15], 16, 530742520);
|
|
2895
|
+
b = md5hh(b, c, d, a, x[i + 2], 23, -995338651);
|
|
2896
|
+
a = md5ii(a, b, c, d, x[i], 6, -198630844);
|
|
2897
|
+
d = md5ii(d, a, b, c, x[i + 7], 10, 1126891415);
|
|
2898
|
+
c = md5ii(c, d, a, b, x[i + 14], 15, -1416354905);
|
|
2899
|
+
b = md5ii(b, c, d, a, x[i + 5], 21, -57434055);
|
|
2900
|
+
a = md5ii(a, b, c, d, x[i + 12], 6, 1700485571);
|
|
2901
|
+
d = md5ii(d, a, b, c, x[i + 3], 10, -1894986606);
|
|
2902
|
+
c = md5ii(c, d, a, b, x[i + 10], 15, -1051523);
|
|
2903
|
+
b = md5ii(b, c, d, a, x[i + 1], 21, -2054922799);
|
|
2904
|
+
a = md5ii(a, b, c, d, x[i + 8], 6, 1873313359);
|
|
2905
|
+
d = md5ii(d, a, b, c, x[i + 15], 10, -30611744);
|
|
2906
|
+
c = md5ii(c, d, a, b, x[i + 6], 15, -1560198380);
|
|
2907
|
+
b = md5ii(b, c, d, a, x[i + 13], 21, 1309151649);
|
|
2908
|
+
a = md5ii(a, b, c, d, x[i + 4], 6, -145523070);
|
|
2909
|
+
d = md5ii(d, a, b, c, x[i + 11], 10, -1120210379);
|
|
2910
|
+
c = md5ii(c, d, a, b, x[i + 2], 15, 718787259);
|
|
2911
|
+
b = md5ii(b, c, d, a, x[i + 9], 21, -343485551);
|
|
2912
|
+
a = safeAdd(a, olda);
|
|
2913
|
+
b = safeAdd(b, oldb);
|
|
2914
|
+
c = safeAdd(c, oldc);
|
|
2915
|
+
d = safeAdd(d, oldd);
|
|
2916
|
+
}
|
|
2917
|
+
|
|
2918
|
+
return [a, b, c, d];
|
|
2919
|
+
}
|
|
2920
|
+
/*
|
|
2921
|
+
* Convert an array bytes to an array of little-endian words
|
|
2922
|
+
* Characters >255 have their high-byte silently ignored.
|
|
2923
|
+
*/
|
|
2924
|
+
|
|
2925
|
+
|
|
2926
|
+
function bytesToWords(input) {
|
|
2927
|
+
if (input.length === 0) {
|
|
2928
|
+
return [];
|
|
2929
|
+
}
|
|
2930
|
+
|
|
2931
|
+
var length8 = input.length * 8;
|
|
2932
|
+
var output = new Uint32Array(getOutputLength(length8));
|
|
2933
|
+
|
|
2934
|
+
for (var i = 0; i < length8; i += 8) {
|
|
2935
|
+
output[i >> 5] |= (input[i / 8] & 0xff) << i % 32;
|
|
2936
|
+
}
|
|
2937
|
+
|
|
2938
|
+
return output;
|
|
2939
|
+
}
|
|
2940
|
+
/*
|
|
2941
|
+
* Add integers, wrapping at 2^32. This uses 16-bit operations internally
|
|
2942
|
+
* to work around bugs in some JS interpreters.
|
|
2943
|
+
*/
|
|
2944
|
+
|
|
2945
|
+
|
|
2946
|
+
function safeAdd(x, y) {
|
|
2947
|
+
var lsw = (x & 0xffff) + (y & 0xffff);
|
|
2948
|
+
var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
|
|
2949
|
+
return msw << 16 | lsw & 0xffff;
|
|
2950
|
+
}
|
|
2951
|
+
/*
|
|
2952
|
+
* Bitwise rotate a 32-bit number to the left.
|
|
2953
|
+
*/
|
|
2954
|
+
|
|
2955
|
+
|
|
2956
|
+
function bitRotateLeft(num, cnt) {
|
|
2957
|
+
return num << cnt | num >>> 32 - cnt;
|
|
2958
|
+
}
|
|
2959
|
+
/*
|
|
2960
|
+
* These functions implement the four basic operations the algorithm uses.
|
|
2961
|
+
*/
|
|
2962
|
+
|
|
2963
|
+
|
|
2964
|
+
function md5cmn(q, a, b, x, s, t) {
|
|
2965
|
+
return safeAdd(bitRotateLeft(safeAdd(safeAdd(a, q), safeAdd(x, t)), s), b);
|
|
2966
|
+
}
|
|
2967
|
+
|
|
2968
|
+
function md5ff(a, b, c, d, x, s, t) {
|
|
2969
|
+
return md5cmn(b & c | ~b & d, a, b, x, s, t);
|
|
2970
|
+
}
|
|
2971
|
+
|
|
2972
|
+
function md5gg(a, b, c, d, x, s, t) {
|
|
2973
|
+
return md5cmn(b & d | c & ~d, a, b, x, s, t);
|
|
2974
|
+
}
|
|
2975
|
+
|
|
2976
|
+
function md5hh(a, b, c, d, x, s, t) {
|
|
2977
|
+
return md5cmn(b ^ c ^ d, a, b, x, s, t);
|
|
2978
|
+
}
|
|
2979
|
+
|
|
2980
|
+
function md5ii(a, b, c, d, x, s, t) {
|
|
2981
|
+
return md5cmn(c ^ (b | ~d), a, b, x, s, t);
|
|
2982
|
+
}
|
|
2983
|
+
|
|
2984
|
+
v35('v3', 0x30, md5);
|
|
2985
|
+
|
|
2986
|
+
function v4(options, buf, offset) {
|
|
2987
|
+
options = options || {};
|
|
2988
|
+
var rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
|
|
2989
|
+
|
|
2990
|
+
rnds[6] = rnds[6] & 0x0f | 0x40;
|
|
2991
|
+
rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
|
|
2992
|
+
|
|
2993
|
+
if (buf) {
|
|
2994
|
+
offset = offset || 0;
|
|
2995
|
+
|
|
2996
|
+
for (var i = 0; i < 16; ++i) {
|
|
2997
|
+
buf[offset + i] = rnds[i];
|
|
2998
|
+
}
|
|
2999
|
+
|
|
3000
|
+
return buf;
|
|
3001
|
+
}
|
|
3002
|
+
|
|
3003
|
+
return stringify(rnds);
|
|
3004
|
+
}
|
|
3005
|
+
|
|
3006
|
+
// Adapted from Chris Veness' SHA1 code at
|
|
3007
|
+
// http://www.movable-type.co.uk/scripts/sha1.html
|
|
3008
|
+
function f(s, x, y, z) {
|
|
3009
|
+
switch (s) {
|
|
3010
|
+
case 0:
|
|
3011
|
+
return x & y ^ ~x & z;
|
|
3012
|
+
|
|
3013
|
+
case 1:
|
|
3014
|
+
return x ^ y ^ z;
|
|
3015
|
+
|
|
3016
|
+
case 2:
|
|
3017
|
+
return x & y ^ x & z ^ y & z;
|
|
3018
|
+
|
|
3019
|
+
case 3:
|
|
3020
|
+
return x ^ y ^ z;
|
|
3021
|
+
}
|
|
3022
|
+
}
|
|
3023
|
+
|
|
3024
|
+
function ROTL(x, n) {
|
|
3025
|
+
return x << n | x >>> 32 - n;
|
|
3026
|
+
}
|
|
3027
|
+
|
|
3028
|
+
function sha1(bytes) {
|
|
3029
|
+
var K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6];
|
|
3030
|
+
var H = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0];
|
|
3031
|
+
|
|
3032
|
+
if (typeof bytes === 'string') {
|
|
3033
|
+
var msg = unescape(encodeURIComponent(bytes)); // UTF8 escape
|
|
3034
|
+
|
|
3035
|
+
bytes = [];
|
|
3036
|
+
|
|
3037
|
+
for (var i = 0; i < msg.length; ++i) {
|
|
3038
|
+
bytes.push(msg.charCodeAt(i));
|
|
3039
|
+
}
|
|
3040
|
+
} else if (!Array.isArray(bytes)) {
|
|
3041
|
+
// Convert Array-like to Array
|
|
3042
|
+
bytes = Array.prototype.slice.call(bytes);
|
|
3043
|
+
}
|
|
3044
|
+
|
|
3045
|
+
bytes.push(0x80);
|
|
3046
|
+
var l = bytes.length / 4 + 2;
|
|
3047
|
+
var N = Math.ceil(l / 16);
|
|
3048
|
+
var M = new Array(N);
|
|
3049
|
+
|
|
3050
|
+
for (var _i = 0; _i < N; ++_i) {
|
|
3051
|
+
var arr = new Uint32Array(16);
|
|
3052
|
+
|
|
3053
|
+
for (var j = 0; j < 16; ++j) {
|
|
3054
|
+
arr[j] = bytes[_i * 64 + j * 4] << 24 | bytes[_i * 64 + j * 4 + 1] << 16 | bytes[_i * 64 + j * 4 + 2] << 8 | bytes[_i * 64 + j * 4 + 3];
|
|
3055
|
+
}
|
|
3056
|
+
|
|
3057
|
+
M[_i] = arr;
|
|
3058
|
+
}
|
|
3059
|
+
|
|
3060
|
+
M[N - 1][14] = (bytes.length - 1) * 8 / Math.pow(2, 32);
|
|
3061
|
+
M[N - 1][14] = Math.floor(M[N - 1][14]);
|
|
3062
|
+
M[N - 1][15] = (bytes.length - 1) * 8 & 0xffffffff;
|
|
3063
|
+
|
|
3064
|
+
for (var _i2 = 0; _i2 < N; ++_i2) {
|
|
3065
|
+
var W = new Uint32Array(80);
|
|
3066
|
+
|
|
3067
|
+
for (var t = 0; t < 16; ++t) {
|
|
3068
|
+
W[t] = M[_i2][t];
|
|
3069
|
+
}
|
|
3070
|
+
|
|
3071
|
+
for (var _t = 16; _t < 80; ++_t) {
|
|
3072
|
+
W[_t] = ROTL(W[_t - 3] ^ W[_t - 8] ^ W[_t - 14] ^ W[_t - 16], 1);
|
|
3073
|
+
}
|
|
3074
|
+
|
|
3075
|
+
var a = H[0];
|
|
3076
|
+
var b = H[1];
|
|
3077
|
+
var c = H[2];
|
|
3078
|
+
var d = H[3];
|
|
3079
|
+
var e = H[4];
|
|
3080
|
+
|
|
3081
|
+
for (var _t2 = 0; _t2 < 80; ++_t2) {
|
|
3082
|
+
var s = Math.floor(_t2 / 20);
|
|
3083
|
+
var T = ROTL(a, 5) + f(s, b, c, d) + e + K[s] + W[_t2] >>> 0;
|
|
3084
|
+
e = d;
|
|
3085
|
+
d = c;
|
|
3086
|
+
c = ROTL(b, 30) >>> 0;
|
|
3087
|
+
b = a;
|
|
3088
|
+
a = T;
|
|
3089
|
+
}
|
|
3090
|
+
|
|
3091
|
+
H[0] = H[0] + a >>> 0;
|
|
3092
|
+
H[1] = H[1] + b >>> 0;
|
|
3093
|
+
H[2] = H[2] + c >>> 0;
|
|
3094
|
+
H[3] = H[3] + d >>> 0;
|
|
3095
|
+
H[4] = H[4] + e >>> 0;
|
|
3096
|
+
}
|
|
3097
|
+
|
|
3098
|
+
return [H[0] >> 24 & 0xff, H[0] >> 16 & 0xff, H[0] >> 8 & 0xff, H[0] & 0xff, H[1] >> 24 & 0xff, H[1] >> 16 & 0xff, H[1] >> 8 & 0xff, H[1] & 0xff, H[2] >> 24 & 0xff, H[2] >> 16 & 0xff, H[2] >> 8 & 0xff, H[2] & 0xff, H[3] >> 24 & 0xff, H[3] >> 16 & 0xff, H[3] >> 8 & 0xff, H[3] & 0xff, H[4] >> 24 & 0xff, H[4] >> 16 & 0xff, H[4] >> 8 & 0xff, H[4] & 0xff];
|
|
3099
|
+
}
|
|
3100
|
+
|
|
3101
|
+
v35('v5', 0x50, sha1);
|
|
3102
|
+
|
|
3103
|
+
var setCookie = function (name, value, expire, domain, secure) {
|
|
3104
|
+
var expireString = expire === Infinity ? " expires=Fri, 31 Dec 9999 23:59:59 GMT" : "; max-age=" + expire;
|
|
3105
|
+
document.cookie =
|
|
3106
|
+
encodeURIComponent(name) +
|
|
3107
|
+
"=" +
|
|
3108
|
+
value +
|
|
3109
|
+
"; path=/;" +
|
|
3110
|
+
expireString +
|
|
3111
|
+
(domain ? "; domain=" + domain : "") +
|
|
3112
|
+
(secure ? "; secure" : "");
|
|
3113
|
+
};
|
|
3114
|
+
var getCookieDomain = function () {
|
|
3115
|
+
return location.hostname.replace("www.", "");
|
|
3116
|
+
};
|
|
3117
|
+
var generateId = function () {
|
|
3118
|
+
return v4();
|
|
3119
|
+
};
|
|
3120
|
+
var getCookie = function (name) {
|
|
3121
|
+
if (!name) {
|
|
3122
|
+
return null;
|
|
3123
|
+
}
|
|
3124
|
+
return (decodeURIComponent(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*" + encodeURIComponent(name).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*([^;]*).*$)|^.*$"), "$1")) || null);
|
|
3125
|
+
};
|
|
3126
|
+
var getHostWithProtocol = function (host) {
|
|
3127
|
+
while (endsWith(host, "/")) {
|
|
3128
|
+
host = host.substr(0, host.length - 1);
|
|
3129
|
+
}
|
|
3130
|
+
if (host.indexOf("https://") === 0 || host.indexOf("http://") === 0) {
|
|
3131
|
+
return host;
|
|
3132
|
+
}
|
|
3133
|
+
else {
|
|
3134
|
+
return "//" + host;
|
|
3135
|
+
}
|
|
3136
|
+
};
|
|
3137
|
+
function endsWith(str, suffix) {
|
|
3138
|
+
return str.indexOf(suffix, str.length - suffix.length) !== -1;
|
|
3139
|
+
}
|
|
3140
|
+
var reformatDate = function (strDate) {
|
|
3141
|
+
var end = strDate.split(".")[1];
|
|
3142
|
+
if (!end) {
|
|
3143
|
+
return strDate;
|
|
3144
|
+
}
|
|
3145
|
+
if (end.length >= 7) {
|
|
3146
|
+
return strDate;
|
|
3147
|
+
}
|
|
3148
|
+
return strDate.slice(0, -1) + "0".repeat(7 - end.length) + "Z";
|
|
3149
|
+
};
|
|
3150
|
+
|
|
3151
|
+
var focusableSelectors = [
|
|
3152
|
+
'a[href]:not([tabindex^="-"])',
|
|
3153
|
+
'area[href]:not([tabindex^="-"])',
|
|
3154
|
+
'input:not([type="hidden"]):not([type="radio"]):not([disabled]):not([tabindex^="-"])',
|
|
3155
|
+
'input[type="radio"]:not([disabled]):not([tabindex^="-"])',
|
|
3156
|
+
'select:not([disabled]):not([tabindex^="-"])',
|
|
3157
|
+
'textarea:not([disabled]):not([tabindex^="-"])',
|
|
3158
|
+
'button:not([disabled]):not([tabindex^="-"])',
|
|
3159
|
+
'iframe:not([tabindex^="-"])',
|
|
3160
|
+
'audio[controls]:not([tabindex^="-"])',
|
|
3161
|
+
'video[controls]:not([tabindex^="-"])',
|
|
3162
|
+
'[contenteditable]:not([tabindex^="-"])',
|
|
3163
|
+
'[tabindex]:not([tabindex^="-"])',
|
|
3164
|
+
];
|
|
3165
|
+
|
|
3166
|
+
var TAB_KEY = 9;
|
|
3167
|
+
var ESCAPE_KEY = 27;
|
|
3168
|
+
|
|
3169
|
+
/**
|
|
3170
|
+
* Define the constructor to instantiate a dialog
|
|
3171
|
+
*
|
|
3172
|
+
* @constructor
|
|
3173
|
+
* @param {Element} element
|
|
3174
|
+
*/
|
|
3175
|
+
function A11yDialog(element) {
|
|
3176
|
+
// Prebind the functions that will be bound in addEventListener and
|
|
3177
|
+
// removeEventListener to avoid losing references
|
|
3178
|
+
this._show = this.show.bind(this);
|
|
3179
|
+
this._hide = this.hide.bind(this);
|
|
3180
|
+
this._maintainFocus = this._maintainFocus.bind(this);
|
|
3181
|
+
this._bindKeypress = this._bindKeypress.bind(this);
|
|
3182
|
+
|
|
3183
|
+
this.$el = element;
|
|
3184
|
+
this.shown = false;
|
|
3185
|
+
this._id = this.$el.getAttribute('data-a11y-dialog') || this.$el.id;
|
|
3186
|
+
this._previouslyFocused = null;
|
|
3187
|
+
this._listeners = {};
|
|
3188
|
+
|
|
3189
|
+
// Initialise everything needed for the dialog to work properly
|
|
3190
|
+
this.create();
|
|
3191
|
+
}
|
|
3192
|
+
|
|
3193
|
+
/**
|
|
3194
|
+
* Set up everything necessary for the dialog to be functioning
|
|
3195
|
+
*
|
|
3196
|
+
* @param {(NodeList | Element | string)} targets
|
|
3197
|
+
* @return {this}
|
|
3198
|
+
*/
|
|
3199
|
+
A11yDialog.prototype.create = function () {
|
|
3200
|
+
this.$el.setAttribute('aria-hidden', true);
|
|
3201
|
+
this.$el.setAttribute('aria-modal', true);
|
|
3202
|
+
this.$el.setAttribute('tabindex', -1);
|
|
3203
|
+
|
|
3204
|
+
if (!this.$el.hasAttribute('role')) {
|
|
3205
|
+
this.$el.setAttribute('role', 'dialog');
|
|
3206
|
+
}
|
|
3207
|
+
|
|
3208
|
+
// Keep a collection of dialog openers, each of which will be bound a click
|
|
3209
|
+
// event listener to open the dialog
|
|
3210
|
+
this._openers = $$('[data-a11y-dialog-show="' + this._id + '"]');
|
|
3211
|
+
this._openers.forEach(
|
|
3212
|
+
function (opener) {
|
|
3213
|
+
opener.addEventListener('click', this._show);
|
|
3214
|
+
}.bind(this)
|
|
3215
|
+
);
|
|
3216
|
+
|
|
3217
|
+
// Keep a collection of dialog closers, each of which will be bound a click
|
|
3218
|
+
// event listener to close the dialog
|
|
3219
|
+
this._closers = $$('[data-a11y-dialog-hide]', this.$el).concat(
|
|
3220
|
+
$$('[data-a11y-dialog-hide="' + this._id + '"]')
|
|
3221
|
+
);
|
|
3222
|
+
this._closers.forEach(
|
|
3223
|
+
function (closer) {
|
|
3224
|
+
closer.addEventListener('click', this._hide);
|
|
3225
|
+
}.bind(this)
|
|
3226
|
+
);
|
|
3227
|
+
|
|
3228
|
+
// Execute all callbacks registered for the `create` event
|
|
3229
|
+
this._fire('create');
|
|
3230
|
+
|
|
3231
|
+
return this
|
|
3232
|
+
};
|
|
3233
|
+
|
|
3234
|
+
/**
|
|
3235
|
+
* Show the dialog element, disable all the targets (siblings), trap the
|
|
3236
|
+
* current focus within it, listen for some specific key presses and fire all
|
|
3237
|
+
* registered callbacks for `show` event
|
|
3238
|
+
*
|
|
3239
|
+
* @param {CustomEvent} event
|
|
3240
|
+
* @return {this}
|
|
3241
|
+
*/
|
|
3242
|
+
A11yDialog.prototype.show = function (event) {
|
|
3243
|
+
// If the dialog is already open, abort
|
|
3244
|
+
if (this.shown) {
|
|
3245
|
+
return this
|
|
3246
|
+
}
|
|
3247
|
+
|
|
3248
|
+
// Keep a reference to the currently focused element to be able to restore
|
|
3249
|
+
// it later
|
|
3250
|
+
this._previouslyFocused = document.activeElement;
|
|
3251
|
+
this.$el.removeAttribute('aria-hidden');
|
|
3252
|
+
this.shown = true;
|
|
3253
|
+
|
|
3254
|
+
// Set the focus to the dialog element
|
|
3255
|
+
moveFocusToDialog(this.$el);
|
|
3256
|
+
|
|
3257
|
+
// Bind a focus event listener to the body element to make sure the focus
|
|
3258
|
+
// stays trapped inside the dialog while open, and start listening for some
|
|
3259
|
+
// specific key presses (TAB and ESC)
|
|
3260
|
+
document.body.addEventListener('focus', this._maintainFocus, true);
|
|
3261
|
+
document.addEventListener('keydown', this._bindKeypress);
|
|
3262
|
+
|
|
3263
|
+
// Execute all callbacks registered for the `show` event
|
|
3264
|
+
this._fire('show', event);
|
|
3265
|
+
|
|
3266
|
+
return this
|
|
3267
|
+
};
|
|
3268
|
+
|
|
3269
|
+
/**
|
|
3270
|
+
* Hide the dialog element, enable all the targets (siblings), restore the
|
|
3271
|
+
* focus to the previously active element, stop listening for some specific
|
|
3272
|
+
* key presses and fire all registered callbacks for `hide` event
|
|
3273
|
+
*
|
|
3274
|
+
* @param {CustomEvent} event
|
|
3275
|
+
* @return {this}
|
|
3276
|
+
*/
|
|
3277
|
+
A11yDialog.prototype.hide = function (event) {
|
|
3278
|
+
// If the dialog is already closed, abort
|
|
3279
|
+
if (!this.shown) {
|
|
3280
|
+
return this
|
|
3281
|
+
}
|
|
3282
|
+
|
|
3283
|
+
this.shown = false;
|
|
3284
|
+
this.$el.setAttribute('aria-hidden', 'true');
|
|
3285
|
+
|
|
3286
|
+
// If there was a focused element before the dialog was opened (and it has a
|
|
3287
|
+
// `focus` method), restore the focus back to it
|
|
3288
|
+
// See: https://github.com/KittyGiraudel/a11y-dialog/issues/108
|
|
3289
|
+
if (this._previouslyFocused && this._previouslyFocused.focus) {
|
|
3290
|
+
this._previouslyFocused.focus();
|
|
3291
|
+
}
|
|
3292
|
+
|
|
3293
|
+
// Remove the focus event listener to the body element and stop listening
|
|
3294
|
+
// for specific key presses
|
|
3295
|
+
document.body.removeEventListener('focus', this._maintainFocus, true);
|
|
3296
|
+
document.removeEventListener('keydown', this._bindKeypress);
|
|
3297
|
+
|
|
3298
|
+
// Execute all callbacks registered for the `hide` event
|
|
3299
|
+
this._fire('hide', event);
|
|
3300
|
+
|
|
3301
|
+
return this
|
|
3302
|
+
};
|
|
3303
|
+
|
|
3304
|
+
/**
|
|
3305
|
+
* Destroy the current instance (after making sure the dialog has been hidden)
|
|
3306
|
+
* and remove all associated listeners from dialog openers and closers
|
|
3307
|
+
*
|
|
3308
|
+
* @return {this}
|
|
3309
|
+
*/
|
|
3310
|
+
A11yDialog.prototype.destroy = function () {
|
|
3311
|
+
// Hide the dialog to avoid destroying an open instance
|
|
3312
|
+
this.hide();
|
|
3313
|
+
|
|
3314
|
+
// Remove the click event listener from all dialog openers
|
|
3315
|
+
this._openers.forEach(
|
|
3316
|
+
function (opener) {
|
|
3317
|
+
opener.removeEventListener('click', this._show);
|
|
3318
|
+
}.bind(this)
|
|
3319
|
+
);
|
|
3320
|
+
|
|
3321
|
+
// Remove the click event listener from all dialog closers
|
|
3322
|
+
this._closers.forEach(
|
|
3323
|
+
function (closer) {
|
|
3324
|
+
closer.removeEventListener('click', this._hide);
|
|
3325
|
+
}.bind(this)
|
|
3326
|
+
);
|
|
3327
|
+
|
|
3328
|
+
// Execute all callbacks registered for the `destroy` event
|
|
3329
|
+
this._fire('destroy');
|
|
3330
|
+
|
|
3331
|
+
// Keep an object of listener types mapped to callback functions
|
|
3332
|
+
this._listeners = {};
|
|
3333
|
+
|
|
3334
|
+
return this
|
|
3335
|
+
};
|
|
3336
|
+
|
|
3337
|
+
/**
|
|
3338
|
+
* Register a new callback for the given event type
|
|
3339
|
+
*
|
|
3340
|
+
* @param {string} type
|
|
3341
|
+
* @param {Function} handler
|
|
3342
|
+
*/
|
|
3343
|
+
A11yDialog.prototype.on = function (type, handler) {
|
|
3344
|
+
if (typeof this._listeners[type] === 'undefined') {
|
|
3345
|
+
this._listeners[type] = [];
|
|
3346
|
+
}
|
|
3347
|
+
|
|
3348
|
+
this._listeners[type].push(handler);
|
|
3349
|
+
|
|
3350
|
+
return this
|
|
3351
|
+
};
|
|
3352
|
+
|
|
3353
|
+
/**
|
|
3354
|
+
* Unregister an existing callback for the given event type
|
|
3355
|
+
*
|
|
3356
|
+
* @param {string} type
|
|
3357
|
+
* @param {Function} handler
|
|
3358
|
+
*/
|
|
3359
|
+
A11yDialog.prototype.off = function (type, handler) {
|
|
3360
|
+
var index = (this._listeners[type] || []).indexOf(handler);
|
|
3361
|
+
|
|
3362
|
+
if (index > -1) {
|
|
3363
|
+
this._listeners[type].splice(index, 1);
|
|
3364
|
+
}
|
|
3365
|
+
|
|
3366
|
+
return this
|
|
3367
|
+
};
|
|
3368
|
+
|
|
3369
|
+
/**
|
|
3370
|
+
* Iterate over all registered handlers for given type and call them all with
|
|
3371
|
+
* the dialog element as first argument, event as second argument (if any). Also
|
|
3372
|
+
* dispatch a custom event on the DOM element itself to make it possible to
|
|
3373
|
+
* react to the lifecycle of auto-instantiated dialogs.
|
|
3374
|
+
*
|
|
3375
|
+
* @access private
|
|
3376
|
+
* @param {string} type
|
|
3377
|
+
* @param {CustomEvent} event
|
|
3378
|
+
*/
|
|
3379
|
+
A11yDialog.prototype._fire = function (type, event) {
|
|
3380
|
+
var listeners = this._listeners[type] || [];
|
|
3381
|
+
var domEvent = new CustomEvent(type, { detail: event });
|
|
3382
|
+
|
|
3383
|
+
this.$el.dispatchEvent(domEvent);
|
|
3384
|
+
|
|
3385
|
+
listeners.forEach(
|
|
3386
|
+
function (listener) {
|
|
3387
|
+
listener(this.$el, event);
|
|
3388
|
+
}.bind(this)
|
|
3389
|
+
);
|
|
3390
|
+
};
|
|
3391
|
+
|
|
3392
|
+
/**
|
|
3393
|
+
* Private event handler used when listening to some specific key presses
|
|
3394
|
+
* (namely ESCAPE and TAB)
|
|
3395
|
+
*
|
|
3396
|
+
* @access private
|
|
3397
|
+
* @param {Event} event
|
|
3398
|
+
*/
|
|
3399
|
+
A11yDialog.prototype._bindKeypress = function (event) {
|
|
3400
|
+
// This is an escape hatch in case there are nested dialogs, so the keypresses
|
|
3401
|
+
// are only reacted to for the most recent one
|
|
3402
|
+
if (!this.$el.contains(document.activeElement)) return
|
|
3403
|
+
|
|
3404
|
+
// If the dialog is shown and the ESCAPE key is being pressed, prevent any
|
|
3405
|
+
// further effects from the ESCAPE key and hide the dialog, unless its role
|
|
3406
|
+
// is 'alertdialog', which should be modal
|
|
3407
|
+
if (
|
|
3408
|
+
this.shown &&
|
|
3409
|
+
event.which === ESCAPE_KEY &&
|
|
3410
|
+
this.$el.getAttribute('role') !== 'alertdialog'
|
|
3411
|
+
) {
|
|
3412
|
+
event.preventDefault();
|
|
3413
|
+
this.hide(event);
|
|
3414
|
+
}
|
|
3415
|
+
|
|
3416
|
+
// If the dialog is shown and the TAB key is being pressed, make sure the
|
|
3417
|
+
// focus stays trapped within the dialog element
|
|
3418
|
+
if (this.shown && event.which === TAB_KEY) {
|
|
3419
|
+
trapTabKey(this.$el, event);
|
|
3420
|
+
}
|
|
3421
|
+
};
|
|
3422
|
+
|
|
3423
|
+
/**
|
|
3424
|
+
* Private event handler used when making sure the focus stays within the
|
|
3425
|
+
* currently open dialog
|
|
3426
|
+
*
|
|
3427
|
+
* @access private
|
|
3428
|
+
* @param {Event} event
|
|
3429
|
+
*/
|
|
3430
|
+
A11yDialog.prototype._maintainFocus = function (event) {
|
|
3431
|
+
// If the dialog is shown and the focus is not within a dialog element (either
|
|
3432
|
+
// this one or another one in case of nested dialogs) or within an element
|
|
3433
|
+
// with the `data-a11y-dialog-focus-trap-ignore` attribute, move it back to
|
|
3434
|
+
// its first focusable child.
|
|
3435
|
+
// See: https://github.com/KittyGiraudel/a11y-dialog/issues/177
|
|
3436
|
+
if (
|
|
3437
|
+
this.shown &&
|
|
3438
|
+
!event.target.closest('[aria-modal="true"]') &&
|
|
3439
|
+
!event.target.closest('[data-a11y-dialog-ignore-focus-trap]')
|
|
3440
|
+
) {
|
|
3441
|
+
moveFocusToDialog(this.$el);
|
|
3442
|
+
}
|
|
3443
|
+
};
|
|
3444
|
+
|
|
3445
|
+
/**
|
|
3446
|
+
* Convert a NodeList into an array
|
|
3447
|
+
*
|
|
3448
|
+
* @param {NodeList} collection
|
|
3449
|
+
* @return {Array<Element>}
|
|
3450
|
+
*/
|
|
3451
|
+
function toArray(collection) {
|
|
3452
|
+
return Array.prototype.slice.call(collection)
|
|
3453
|
+
}
|
|
3454
|
+
|
|
3455
|
+
/**
|
|
3456
|
+
* Query the DOM for nodes matching the given selector, scoped to context (or
|
|
3457
|
+
* the whole document)
|
|
3458
|
+
*
|
|
3459
|
+
* @param {String} selector
|
|
3460
|
+
* @param {Element} [context = document]
|
|
3461
|
+
* @return {Array<Element>}
|
|
3462
|
+
*/
|
|
3463
|
+
function $$(selector, context) {
|
|
3464
|
+
return toArray((context || document).querySelectorAll(selector))
|
|
3465
|
+
}
|
|
3466
|
+
|
|
3467
|
+
/**
|
|
3468
|
+
* Set the focus to the first element with `autofocus` with the element or the
|
|
3469
|
+
* element itself
|
|
3470
|
+
*
|
|
3471
|
+
* @param {Element} node
|
|
3472
|
+
*/
|
|
3473
|
+
function moveFocusToDialog(node) {
|
|
3474
|
+
var focused = node.querySelector('[autofocus]') || node;
|
|
3475
|
+
|
|
3476
|
+
focused.focus();
|
|
3477
|
+
}
|
|
3478
|
+
|
|
3479
|
+
/**
|
|
3480
|
+
* Get the focusable children of the given element
|
|
3481
|
+
*
|
|
3482
|
+
* @param {Element} node
|
|
3483
|
+
* @return {Array<Element>}
|
|
3484
|
+
*/
|
|
3485
|
+
function getFocusableChildren(node) {
|
|
3486
|
+
return $$(focusableSelectors.join(','), node).filter(function (child) {
|
|
3487
|
+
return !!(
|
|
3488
|
+
child.offsetWidth ||
|
|
3489
|
+
child.offsetHeight ||
|
|
3490
|
+
child.getClientRects().length
|
|
3491
|
+
)
|
|
3492
|
+
})
|
|
3493
|
+
}
|
|
3494
|
+
|
|
3495
|
+
/**
|
|
3496
|
+
* Trap the focus inside the given element
|
|
3497
|
+
*
|
|
3498
|
+
* @param {Element} node
|
|
3499
|
+
* @param {Event} event
|
|
3500
|
+
*/
|
|
3501
|
+
function trapTabKey(node, event) {
|
|
3502
|
+
var focusableChildren = getFocusableChildren(node);
|
|
3503
|
+
var focusedItemIndex = focusableChildren.indexOf(document.activeElement);
|
|
3504
|
+
|
|
3505
|
+
// If the SHIFT key is being pressed while tabbing (moving backwards) and
|
|
3506
|
+
// the currently focused item is the first one, move the focus to the last
|
|
3507
|
+
// focusable item from the dialog element
|
|
3508
|
+
if (event.shiftKey && focusedItemIndex === 0) {
|
|
3509
|
+
focusableChildren[focusableChildren.length - 1].focus();
|
|
3510
|
+
event.preventDefault();
|
|
3511
|
+
// If the SHIFT key is not being pressed (moving forwards) and the currently
|
|
3512
|
+
// focused item is the last one, move the focus to the first focusable item
|
|
3513
|
+
// from the dialog element
|
|
3514
|
+
} else if (
|
|
3515
|
+
!event.shiftKey &&
|
|
3516
|
+
focusedItemIndex === focusableChildren.length - 1
|
|
3517
|
+
) {
|
|
3518
|
+
focusableChildren[0].focus();
|
|
3519
|
+
event.preventDefault();
|
|
3520
|
+
}
|
|
3521
|
+
}
|
|
3522
|
+
|
|
3523
|
+
function instantiateDialogs() {
|
|
3524
|
+
$$('[data-a11y-dialog]').forEach(function (node) {
|
|
3525
|
+
new A11yDialog(node);
|
|
3526
|
+
});
|
|
3527
|
+
}
|
|
3528
|
+
|
|
3529
|
+
if (typeof document !== 'undefined') {
|
|
3530
|
+
if (document.readyState === 'loading') {
|
|
3531
|
+
document.addEventListener('DOMContentLoaded', instantiateDialogs);
|
|
3532
|
+
} else {
|
|
3533
|
+
if (window.requestAnimationFrame) {
|
|
3534
|
+
window.requestAnimationFrame(instantiateDialogs);
|
|
3535
|
+
} else {
|
|
3536
|
+
window.setTimeout(instantiateDialogs, 16);
|
|
3537
|
+
}
|
|
3538
|
+
}
|
|
3539
|
+
}
|
|
3540
|
+
|
|
3541
|
+
var DIALOG_CONTAINER_ID = "authsignal-popup";
|
|
3542
|
+
var DIALOG_CONTENT_ID = "authsignal-popup-content";
|
|
3543
|
+
var PopupHandler = /** @class */ (function () {
|
|
3544
|
+
function PopupHandler() {
|
|
3545
|
+
this.popup = null;
|
|
3546
|
+
if (document.querySelector("#".concat(DIALOG_CONTAINER_ID))) {
|
|
3547
|
+
throw new Error("Multiple instances of Authsignal popup is not supported.");
|
|
3548
|
+
}
|
|
3549
|
+
this.create();
|
|
3550
|
+
}
|
|
3551
|
+
PopupHandler.prototype.create = function () {
|
|
3552
|
+
// Dialog container
|
|
3553
|
+
var container = document.createElement("div");
|
|
3554
|
+
container.setAttribute("id", DIALOG_CONTAINER_ID);
|
|
3555
|
+
container.setAttribute("aria-hidden", "true");
|
|
3556
|
+
container.setAttribute("class", "dialog-container");
|
|
3557
|
+
// Dialog overlay
|
|
3558
|
+
var overlay = document.createElement("div");
|
|
3559
|
+
overlay.setAttribute("class", "dialog-overlay");
|
|
3560
|
+
overlay.setAttribute("data-a11y-dialog-hide", "true");
|
|
3561
|
+
container.appendChild(overlay);
|
|
3562
|
+
// Dialog content
|
|
3563
|
+
var content = document.createElement("div");
|
|
3564
|
+
content.setAttribute("class", "dialog-content");
|
|
3565
|
+
content.setAttribute("id", DIALOG_CONTENT_ID);
|
|
3566
|
+
container.appendChild(content);
|
|
3567
|
+
document.body.appendChild(container);
|
|
3568
|
+
this.popup = new A11yDialog(container);
|
|
3569
|
+
this.popup.on("hide", this.destroy);
|
|
3570
|
+
};
|
|
3571
|
+
PopupHandler.prototype.destroy = function () {
|
|
3572
|
+
var dialogEl = document.querySelector("#".concat(DIALOG_CONTAINER_ID));
|
|
3573
|
+
if (dialogEl) {
|
|
3574
|
+
document.body.removeChild(dialogEl);
|
|
3575
|
+
}
|
|
3576
|
+
};
|
|
3577
|
+
PopupHandler.prototype.show = function (_a) {
|
|
3578
|
+
var challengeUrl = _a.challengeUrl;
|
|
3579
|
+
if (!this.popup) {
|
|
3580
|
+
throw new Error("Popup is not initialized");
|
|
3581
|
+
}
|
|
3582
|
+
var iframe = document.createElement("iframe");
|
|
3583
|
+
iframe.setAttribute("name", "authsignal");
|
|
3584
|
+
iframe.setAttribute("title", "Authsignal multi-factor authentication challenge");
|
|
3585
|
+
iframe.setAttribute("src", challengeUrl);
|
|
3586
|
+
iframe.setAttribute("width", "600");
|
|
3587
|
+
iframe.setAttribute("height", "600");
|
|
3588
|
+
iframe.setAttribute("frameborder", "0");
|
|
3589
|
+
var dialogContent = document.querySelector("#".concat(DIALOG_CONTENT_ID));
|
|
3590
|
+
if (dialogContent) {
|
|
3591
|
+
dialogContent.appendChild(iframe);
|
|
3592
|
+
}
|
|
3593
|
+
this.popup.show();
|
|
3594
|
+
};
|
|
3595
|
+
PopupHandler.prototype.close = function () {
|
|
3596
|
+
if (!this.popup) {
|
|
3597
|
+
throw new Error("Popup is not initialized");
|
|
3598
|
+
}
|
|
3599
|
+
this.popup.hide();
|
|
3600
|
+
};
|
|
3601
|
+
return PopupHandler;
|
|
3602
|
+
}());
|
|
3603
|
+
|
|
3604
|
+
function authsignalClient(publishableKey, options) {
|
|
3605
|
+
var client = new AuthsignalClient();
|
|
3606
|
+
client.init(publishableKey, options);
|
|
3607
|
+
return client;
|
|
3608
|
+
}
|
|
3609
|
+
var AuthsignalClient = /** @class */ (function () {
|
|
3610
|
+
function AuthsignalClient() {
|
|
3611
|
+
this.anonymousId = "";
|
|
3612
|
+
this.initialized = false;
|
|
3613
|
+
this.publishableKey = "";
|
|
3614
|
+
this.cookieDomain = "";
|
|
3615
|
+
this.idCookieName = "";
|
|
3616
|
+
this.trackingHost = "";
|
|
3617
|
+
}
|
|
3618
|
+
AuthsignalClient.prototype.init = function (publishableKey, options) {
|
|
3619
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3620
|
+
var _a, anonymousId, isGeneratedAnonymousId, agent, registerAnonymousIdRequest;
|
|
3621
|
+
return __generator(this, function (_b) {
|
|
3622
|
+
switch (_b.label) {
|
|
3623
|
+
case 0:
|
|
3624
|
+
this.cookieDomain = (options === null || options === void 0 ? void 0 : options.cookie_domain) || getCookieDomain();
|
|
3625
|
+
this.idCookieName = (options === null || options === void 0 ? void 0 : options.cookie_name) || "__as_aid";
|
|
3626
|
+
this.trackingHost = getHostWithProtocol((options === null || options === void 0 ? void 0 : options.tracking_host) || "t.authsignal.com");
|
|
3627
|
+
_a = this;
|
|
3628
|
+
return [4 /*yield*/, load({
|
|
3629
|
+
monitoring: false
|
|
3630
|
+
})];
|
|
3631
|
+
case 1:
|
|
3632
|
+
_a.fingerprintClient = _b.sent();
|
|
3633
|
+
anonymousId = this.getAnonymousId();
|
|
3634
|
+
this.anonymousId = anonymousId.idCookie;
|
|
3635
|
+
isGeneratedAnonymousId = anonymousId.generated;
|
|
3636
|
+
return [4 /*yield*/, this.fingerprintClient.get()];
|
|
3637
|
+
case 2:
|
|
3638
|
+
agent = _b.sent();
|
|
3639
|
+
this.deviceFingerprint = agent.visitorId;
|
|
3640
|
+
if (!publishableKey) {
|
|
3641
|
+
throw Error("IntegrationError");
|
|
3642
|
+
}
|
|
3643
|
+
this.publishableKey = publishableKey;
|
|
3644
|
+
if (!isGeneratedAnonymousId) return [3 /*break*/, 4];
|
|
3645
|
+
registerAnonymousIdRequest = this.buildRegisterAnonymousIdRequest();
|
|
3646
|
+
return [4 /*yield*/, this.registerAnonymousId(registerAnonymousIdRequest)];
|
|
3647
|
+
case 3:
|
|
3648
|
+
_b.sent();
|
|
3649
|
+
_b.label = 4;
|
|
3650
|
+
case 4:
|
|
3651
|
+
this.initialized = true;
|
|
3652
|
+
return [2 /*return*/];
|
|
3653
|
+
}
|
|
3654
|
+
});
|
|
3655
|
+
});
|
|
3656
|
+
};
|
|
3657
|
+
AuthsignalClient.prototype.identify = function (props) {
|
|
3658
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3659
|
+
var request;
|
|
3660
|
+
return __generator(this, function (_a) {
|
|
3661
|
+
switch (_a.label) {
|
|
3662
|
+
case 0:
|
|
3663
|
+
console.log("AS user identified", props);
|
|
3664
|
+
request = __assign(__assign({}, props), { anonymousId: this.anonymousId });
|
|
3665
|
+
return [4 /*yield*/, this.registerIdentity(request)];
|
|
3666
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
3667
|
+
}
|
|
3668
|
+
});
|
|
3669
|
+
});
|
|
3670
|
+
};
|
|
3671
|
+
AuthsignalClient.prototype.getAnonymousId = function () {
|
|
3672
|
+
var idCookie = getCookie(this.idCookieName);
|
|
3673
|
+
if (idCookie) {
|
|
3674
|
+
return { idCookie: idCookie, generated: false };
|
|
3675
|
+
}
|
|
3676
|
+
var newId = generateId();
|
|
3677
|
+
setCookie("__as_aid", newId, Infinity, this.cookieDomain, document.location.protocol !== "http:");
|
|
3678
|
+
return { idCookie: newId, generated: true };
|
|
3679
|
+
};
|
|
3680
|
+
AuthsignalClient.prototype.challengeWithPopup = function (_a) {
|
|
3681
|
+
var challengeUrl = _a.challengeUrl;
|
|
3682
|
+
var Popup = new PopupHandler();
|
|
3683
|
+
Popup.show({ challengeUrl: challengeUrl });
|
|
3684
|
+
return new Promise(function (resolve, reject) {
|
|
3685
|
+
var handleChallenge = function (event) {
|
|
3686
|
+
if (event.data === "authsignal-challenge-success") {
|
|
3687
|
+
Popup.close();
|
|
3688
|
+
resolve(true);
|
|
3689
|
+
}
|
|
3690
|
+
else if (event.data === "authsignal-challenge-failure") {
|
|
3691
|
+
Popup.close();
|
|
3692
|
+
reject(false);
|
|
3693
|
+
}
|
|
3694
|
+
};
|
|
3695
|
+
window.addEventListener("message", handleChallenge, false);
|
|
3696
|
+
});
|
|
3697
|
+
};
|
|
3698
|
+
AuthsignalClient.prototype.registerIdentity = function (request) {
|
|
3699
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3700
|
+
var result;
|
|
3701
|
+
return __generator(this, function (_a) {
|
|
3702
|
+
switch (_a.label) {
|
|
3703
|
+
case 0:
|
|
3704
|
+
console.log(request);
|
|
3705
|
+
return [4 /*yield*/, this.sendJson("/identity", request)];
|
|
3706
|
+
case 1:
|
|
3707
|
+
result = _a.sent();
|
|
3708
|
+
return [2 /*return*/, result];
|
|
3709
|
+
}
|
|
3710
|
+
});
|
|
3711
|
+
});
|
|
3712
|
+
};
|
|
3713
|
+
AuthsignalClient.prototype.registerAnonymousId = function (request) {
|
|
3714
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3715
|
+
var result;
|
|
3716
|
+
return __generator(this, function (_a) {
|
|
3717
|
+
switch (_a.label) {
|
|
3718
|
+
case 0:
|
|
3719
|
+
console.log(request);
|
|
3720
|
+
return [4 /*yield*/, this.sendJson("/register", request)];
|
|
3721
|
+
case 1:
|
|
3722
|
+
result = _a.sent();
|
|
3723
|
+
return [2 /*return*/, result];
|
|
3724
|
+
}
|
|
3725
|
+
});
|
|
3726
|
+
});
|
|
3727
|
+
};
|
|
3728
|
+
AuthsignalClient.prototype.buildRegisterAnonymousIdRequest = function () {
|
|
3729
|
+
var now = new Date();
|
|
3730
|
+
return {
|
|
3731
|
+
deviceFingerprint: this.deviceFingerprint || "",
|
|
3732
|
+
anonymousId: this.anonymousId,
|
|
3733
|
+
sourceHost: this.cookieDomain,
|
|
3734
|
+
utcTime: reformatDate(now.toISOString()),
|
|
3735
|
+
clientData: {
|
|
3736
|
+
userAgent: navigator.userAgent || "",
|
|
3737
|
+
fonts: screen.width + "x" + screen.height,
|
|
3738
|
+
language: navigator.language,
|
|
3739
|
+
tzOffset: now.getTimezoneOffset(),
|
|
3740
|
+
screenResolution: screen.width + "x" + screen.height,
|
|
3741
|
+
viewPort: Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0) +
|
|
3742
|
+
"x" +
|
|
3743
|
+
Math.max(document.documentElement.clientHeight || 0, window.innerHeight || 0)
|
|
3744
|
+
}
|
|
3745
|
+
};
|
|
3746
|
+
};
|
|
3747
|
+
AuthsignalClient.prototype.sendJson = function (path, payload) {
|
|
3748
|
+
var jsonString = JSON.stringify(payload);
|
|
3749
|
+
var url = "".concat(this.trackingHost, "/api/v1/client/").concat(path, "?publishableKey=").concat(this.publishableKey);
|
|
3750
|
+
// Think about encapsulating the payloads around a message contract
|
|
3751
|
+
// SDK client versions, additional meta data
|
|
3752
|
+
return this.xmlHttpReqTransport(url, jsonString);
|
|
3753
|
+
};
|
|
3754
|
+
AuthsignalClient.prototype.xmlHttpReqTransport = function (url, json) {
|
|
3755
|
+
var req = new XMLHttpRequest();
|
|
3756
|
+
return new Promise(function (resolve, reject) {
|
|
3757
|
+
req.onerror = function () {
|
|
3758
|
+
reject(new Error("Failed to send JSON. See console logs"));
|
|
3759
|
+
};
|
|
3760
|
+
req.onload = function () {
|
|
3761
|
+
if (req.status !== 200) {
|
|
3762
|
+
reject(new Error("Failed to send JSON. Error code: ".concat(req.status, ". See logs for details")));
|
|
3763
|
+
}
|
|
3764
|
+
resolve();
|
|
3765
|
+
};
|
|
3766
|
+
req.open("POST", url);
|
|
3767
|
+
req.setRequestHeader("Content-Type", "application/json");
|
|
3768
|
+
req.send(json);
|
|
3769
|
+
});
|
|
3770
|
+
};
|
|
3771
|
+
return AuthsignalClient;
|
|
3772
|
+
}());
|
|
3773
|
+
|
|
3774
|
+
exports.AuthsignalClient = AuthsignalClient;
|
|
3775
|
+
exports.authsignalClient = authsignalClient;
|
|
3776
|
+
//# sourceMappingURL=index.js.map
|