@fingerly/web-js 0.2.0 → 0.3.0

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/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { SOURCE, hash64, UnsupportedSignal, BlockedSignal, valueOf, FingerlyClient } from '@fingerly/core';
1
+ import { SOURCE, UnsupportedSignal, TimedOutSignal, BlockedSignal, hash64, own, EMBEDDED_SAFE_SOURCES, valueOf, FingerlyClient } from '@fingerly/core';
2
2
  export { ConsentError, FingerlyClient, SOURCE, TransportError, isSuspiciousLevel } from '@fingerly/core';
3
3
 
4
4
  // src/index.ts
@@ -87,8 +87,471 @@ function asBlockedIfRefused(error) {
87
87
  throw error;
88
88
  }
89
89
 
90
+ // src/lies/natives.ts
91
+ var INITIAL_FN_TO_STRING = Function.prototype.toString;
92
+ var INITIAL_GET_OWN_PROP_DESC = Object.getOwnPropertyDescriptor;
93
+ var INITIAL_GET_PROTOTYPE_OF = Object.getPrototypeOf;
94
+ var INITIAL_REFLECT_APPLY = Reflect.apply;
95
+ function createRealmStringifier(toStringFn = INITIAL_FN_TO_STRING) {
96
+ return (fn) => {
97
+ try {
98
+ const source = INITIAL_REFLECT_APPLY(toStringFn, fn, []);
99
+ return typeof source === "string" ? { ok: true, source } : { ok: false };
100
+ } catch {
101
+ return { ok: false };
102
+ }
103
+ };
104
+ }
105
+ function escapeRegExp(text) {
106
+ return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
107
+ }
108
+ function isNativeFunctionSource(fn, source, expectedName, isGetter = false) {
109
+ const fnName = attempt(() => fn.name);
110
+ if (typeof fnName === "string" && fnName.startsWith("bound ")) {
111
+ return false;
112
+ }
113
+ const escaped = escapeRegExp(expectedName);
114
+ const pattern = isGetter ? new RegExp(`^\\s*function\\s+(?:get\\s+)?${escaped}\\s*\\(\\s*\\)\\s*\\{\\s*\\[native code\\]\\s*\\}\\s*$`) : new RegExp(`^\\s*function\\s+${escaped}\\s*\\(\\s*\\)\\s*\\{\\s*\\[native code\\]\\s*\\}\\s*$`);
115
+ return pattern.test(source);
116
+ }
117
+ function isTypeErrorLike(error) {
118
+ if (error instanceof TypeError) return true;
119
+ return typeof error === "object" && error !== null && error.name === "TypeError";
120
+ }
121
+ function passesWebIdlBrandCheck(fn, argsList) {
122
+ for (const args of argsList) {
123
+ let threwTypeError = false;
124
+ try {
125
+ INITIAL_REFLECT_APPLY(fn, {}, [...args]);
126
+ } catch (error) {
127
+ threwTypeError = isTypeErrorLike(error);
128
+ }
129
+ if (!threwTypeError) return false;
130
+ }
131
+ return true;
132
+ }
133
+ function prototypeGetter(proto, prop) {
134
+ if (!proto) return void 0;
135
+ return attempt(() => INITIAL_GET_OWN_PROP_DESC(proto, prop)?.get);
136
+ }
137
+ function accessorOf(holder, prop) {
138
+ let current = holder;
139
+ for (let depth = 0; depth < 8 && current !== null && current !== void 0; depth++) {
140
+ const desc = attempt(() => INITIAL_GET_OWN_PROP_DESC(current, prop));
141
+ if (desc) return desc.get ?? ("value" in desc ? desc.value : void 0);
142
+ current = attempt(() => INITIAL_GET_PROTOTYPE_OF(current));
143
+ }
144
+ return void 0;
145
+ }
146
+ var GL_BRAND_ARGS = [[7936], [37445], [37446]];
147
+ var MATH_FUNCTIONS = [
148
+ "acos",
149
+ "acosh",
150
+ "asin",
151
+ "asinh",
152
+ "atan",
153
+ "atanh",
154
+ "cbrt",
155
+ "cos",
156
+ "cosh",
157
+ "exp",
158
+ "expm1",
159
+ "log",
160
+ "log1p",
161
+ "pow",
162
+ "sin",
163
+ "sinh",
164
+ "sqrt",
165
+ "tan",
166
+ "tanh"
167
+ ];
168
+ function member(w, ctor, prop) {
169
+ const holder = w[ctor];
170
+ return holder?.prototype?.[prop];
171
+ }
172
+ var TARGETS = [
173
+ // The primitives this layer itself depends on to borrow a fresh realm.
174
+ {
175
+ path: "Document.prototype.createElement",
176
+ expectedName: "createElement",
177
+ brandArgsList: [["div"]],
178
+ resolve: (w) => member(w, "Document", "createElement")
179
+ },
180
+ {
181
+ path: "Node.prototype.appendChild",
182
+ expectedName: "appendChild",
183
+ brandArgsList: [[]],
184
+ resolve: (w) => member(w, "Node", "appendChild")
185
+ },
186
+ {
187
+ path: "HTMLIFrameElement.prototype.contentWindow",
188
+ expectedName: "contentWindow",
189
+ isGetter: true,
190
+ brandArgsList: [[]],
191
+ resolve: (w) => prototypeGetter(
192
+ w.HTMLIFrameElement?.prototype,
193
+ "contentWindow"
194
+ )
195
+ },
196
+ // The window accessors every navigator and screen read goes through.
197
+ {
198
+ path: "window.navigator",
199
+ expectedName: "navigator",
200
+ isGetter: true,
201
+ resolve: (w) => accessorOf(w, "navigator")
202
+ },
203
+ {
204
+ path: "window.screen",
205
+ expectedName: "screen",
206
+ isGetter: true,
207
+ resolve: (w) => accessorOf(w, "screen")
208
+ },
209
+ {
210
+ path: "window.devicePixelRatio",
211
+ expectedName: "devicePixelRatio",
212
+ isGetter: true,
213
+ resolve: (w) => accessorOf(w, "devicePixelRatio")
214
+ },
215
+ {
216
+ path: "window.matchMedia",
217
+ expectedName: "matchMedia",
218
+ resolve: (w) => w.matchMedia
219
+ },
220
+ // What `worker_realm` builds its worker from (`WEB-03`).
221
+ {
222
+ path: "Worker",
223
+ expectedName: "Worker",
224
+ resolve: (w) => w.Worker
225
+ },
226
+ {
227
+ path: "Blob",
228
+ expectedName: "Blob",
229
+ resolve: (w) => w.Blob
230
+ },
231
+ {
232
+ path: "URL.createObjectURL",
233
+ expectedName: "createObjectURL",
234
+ resolve: (w) => w.URL?.createObjectURL
235
+ },
236
+ {
237
+ path: "OffscreenCanvas",
238
+ expectedName: "OffscreenCanvas",
239
+ resolve: (w) => w.OffscreenCanvas
240
+ },
241
+ ...MATH_FUNCTIONS.map(
242
+ (name) => ({
243
+ path: `Math.${name}`,
244
+ expectedName: name,
245
+ resolve: () => Math[name]
246
+ })
247
+ ),
248
+ {
249
+ path: "Intl.DateTimeFormat.prototype.resolvedOptions",
250
+ expectedName: "resolvedOptions",
251
+ brandArgsList: [[]],
252
+ resolve: () => Intl?.DateTimeFormat?.prototype?.resolvedOptions
253
+ },
254
+ {
255
+ path: "NavigatorUAData.prototype.getHighEntropyValues",
256
+ expectedName: "getHighEntropyValues",
257
+ resolve: (w) => member(w, "NavigatorUAData", "getHighEntropyValues")
258
+ },
259
+ {
260
+ path: "StorageManager.prototype.getDirectory",
261
+ expectedName: "getDirectory",
262
+ resolve: (w) => member(w, "StorageManager", "getDirectory")
263
+ },
264
+ {
265
+ path: "WebGLRenderingContext.prototype.getShaderPrecisionFormat",
266
+ expectedName: "getShaderPrecisionFormat",
267
+ brandArgsList: [[35633, 36338]],
268
+ resolve: (w) => member(w, "WebGLRenderingContext", "getShaderPrecisionFormat")
269
+ },
270
+ {
271
+ path: "WebGLRenderingContext.prototype.getSupportedExtensions",
272
+ expectedName: "getSupportedExtensions",
273
+ brandArgsList: [[]],
274
+ resolve: (w) => member(w, "WebGLRenderingContext", "getSupportedExtensions")
275
+ },
276
+ {
277
+ path: "Function.prototype.toString",
278
+ expectedName: "toString",
279
+ resolve: () => Function.prototype.toString
280
+ },
281
+ {
282
+ path: "Function.prototype.bind",
283
+ expectedName: "bind",
284
+ resolve: () => Function.prototype.bind
285
+ },
286
+ {
287
+ path: "Object.getOwnPropertyDescriptor",
288
+ expectedName: "getOwnPropertyDescriptor",
289
+ resolve: () => Object.getOwnPropertyDescriptor
290
+ },
291
+ {
292
+ path: "Object.defineProperty",
293
+ expectedName: "defineProperty",
294
+ resolve: () => Object.defineProperty
295
+ },
296
+ {
297
+ path: "Date.prototype.getTimezoneOffset",
298
+ expectedName: "getTimezoneOffset",
299
+ resolve: () => Date.prototype.getTimezoneOffset
300
+ },
301
+ {
302
+ path: "Number.prototype.toFixed",
303
+ expectedName: "toFixed",
304
+ resolve: () => Number.prototype.toFixed
305
+ },
306
+ {
307
+ path: "Error.prototype.toString",
308
+ expectedName: "toString",
309
+ resolve: () => Error.prototype.toString
310
+ },
311
+ {
312
+ path: "Intl.DateTimeFormat",
313
+ expectedName: "DateTimeFormat",
314
+ resolve: () => Intl?.DateTimeFormat
315
+ },
316
+ {
317
+ path: "Navigator.prototype.javaEnabled",
318
+ expectedName: "javaEnabled",
319
+ resolve: (w) => w.Navigator?.prototype?.javaEnabled
320
+ },
321
+ {
322
+ path: "Permissions.prototype.query",
323
+ expectedName: "query",
324
+ resolve: (w) => w.Permissions?.prototype?.query
325
+ },
326
+ {
327
+ path: "MediaDevices.prototype.enumerateDevices",
328
+ expectedName: "enumerateDevices",
329
+ resolve: (w) => w.MediaDevices?.prototype?.enumerateDevices
330
+ },
331
+ {
332
+ path: "HTMLCanvasElement.prototype.getContext",
333
+ expectedName: "getContext",
334
+ brandArgsList: [["2d"]],
335
+ resolve: (w) => w.HTMLCanvasElement?.prototype?.getContext
336
+ },
337
+ {
338
+ path: "HTMLCanvasElement.prototype.toDataURL",
339
+ expectedName: "toDataURL",
340
+ resolve: (w) => w.HTMLCanvasElement?.prototype?.toDataURL
341
+ },
342
+ {
343
+ path: "CanvasRenderingContext2D.prototype.getImageData",
344
+ expectedName: "getImageData",
345
+ resolve: (w) => w.CanvasRenderingContext2D?.prototype?.getImageData
346
+ },
347
+ {
348
+ path: "WebGLRenderingContext.prototype.getParameter",
349
+ expectedName: "getParameter",
350
+ brandArgsList: GL_BRAND_ARGS,
351
+ resolve: (w) => w.WebGLRenderingContext?.prototype?.getParameter
352
+ },
353
+ {
354
+ path: "WebGLRenderingContext.prototype.getExtension",
355
+ expectedName: "getExtension",
356
+ brandArgsList: [["WEBGL_lose_context"]],
357
+ resolve: (w) => w.WebGLRenderingContext?.prototype?.getExtension
358
+ },
359
+ {
360
+ path: "WebGL2RenderingContext.prototype.getParameter",
361
+ expectedName: "getParameter",
362
+ brandArgsList: GL_BRAND_ARGS,
363
+ resolve: (w) => w.WebGL2RenderingContext?.prototype?.getParameter
364
+ },
365
+ {
366
+ path: "OfflineAudioContext.prototype.startRendering",
367
+ expectedName: "startRendering",
368
+ resolve: (w) => w.OfflineAudioContext?.prototype?.startRendering
369
+ },
370
+ {
371
+ path: "AudioBuffer.prototype.getChannelData",
372
+ expectedName: "getChannelData",
373
+ brandArgsList: [[0]],
374
+ resolve: (w) => w.AudioBuffer?.prototype?.getChannelData
375
+ },
376
+ {
377
+ path: "StorageManager.prototype.estimate",
378
+ expectedName: "estimate",
379
+ resolve: (w) => w.StorageManager?.prototype?.estimate
380
+ },
381
+ {
382
+ path: "Element.prototype.getBoundingClientRect",
383
+ expectedName: "getBoundingClientRect",
384
+ resolve: (w) => w.Element?.prototype?.getBoundingClientRect
385
+ },
386
+ {
387
+ path: "HTMLElement.prototype.offsetWidth",
388
+ expectedName: "offsetWidth",
389
+ isGetter: true,
390
+ brandArgsList: [[]],
391
+ resolve: (w) => prototypeGetter(w.HTMLElement?.prototype, "offsetWidth")
392
+ },
393
+ {
394
+ path: "HTMLElement.prototype.offsetHeight",
395
+ expectedName: "offsetHeight",
396
+ isGetter: true,
397
+ brandArgsList: [[]],
398
+ resolve: (w) => prototypeGetter(w.HTMLElement?.prototype, "offsetHeight")
399
+ },
400
+ {
401
+ path: "Performance.prototype.now",
402
+ expectedName: "now",
403
+ resolve: (w) => w.Performance?.prototype?.now
404
+ },
405
+ {
406
+ path: "Screen.prototype.constructor",
407
+ expectedName: "Screen",
408
+ resolve: (w) => w.Screen
409
+ }
410
+ ];
411
+ function unverified(reason) {
412
+ return {
413
+ stringify: createRealmStringifier(INITIAL_FN_TO_STRING),
414
+ clean: false,
415
+ ...reason === void 0 ? {} : { reason }
416
+ };
417
+ }
418
+ function fingerlyRealmProbe() {
419
+ return "fingerly-realm-probe-7c1e";
420
+ }
421
+ function looksNative(fn, name, isGetter = false) {
422
+ if (typeof fn !== "function") return false;
423
+ const source = attempt(() => INITIAL_REFLECT_APPLY(INITIAL_FN_TO_STRING, fn, []));
424
+ return typeof source === "string" && isNativeFunctionSource(fn, source, name, isGetter);
425
+ }
426
+ function plausibleStringifier(stringify, own2) {
427
+ const probe = stringify(fingerlyRealmProbe);
428
+ if (!probe.ok || !probe.source.includes("fingerly-realm-probe-7c1e")) return false;
429
+ if (probe.source.includes("[native code]")) return false;
430
+ const self = stringify(own2);
431
+ return self.ok && isNativeFunctionSource(own2, self.source, "toString", false);
432
+ }
433
+ function borrowRealmToString() {
434
+ try {
435
+ return borrowRealm();
436
+ } catch {
437
+ return unverified("inspection-threw");
438
+ }
439
+ }
440
+ function borrowRealm() {
441
+ if (typeof document === "undefined") return unverified();
442
+ const g = globalThis;
443
+ const doc = document;
444
+ const createElement = attempt(() => member(g, "Document", "createElement"));
445
+ const appendChild = attempt(() => member(g, "Node", "appendChild"));
446
+ const iframeProto = attempt(
447
+ () => g.HTMLIFrameElement?.prototype
448
+ );
449
+ const contentWindowGetter = prototypeGetter(iframeProto, "contentWindow");
450
+ if (typeof createElement !== "function" || typeof appendChild !== "function" || typeof contentWindowGetter !== "function") {
451
+ return unverified();
452
+ }
453
+ if (!looksNative(createElement, "createElement") || !looksNative(appendChild, "appendChild") || !looksNative(contentWindowGetter, "contentWindow", true)) {
454
+ return unverified("borrow-primitive-not-native");
455
+ }
456
+ const host = attempt(() => doc.body ?? doc.documentElement);
457
+ if (!host) return unverified();
458
+ const frame = attempt(() => {
459
+ const element = INITIAL_REFLECT_APPLY(createElement, doc, ["iframe"]);
460
+ element.setAttribute("sandbox", "allow-same-origin");
461
+ element.style.display = "none";
462
+ INITIAL_REFLECT_APPLY(appendChild, host, [element]);
463
+ return element;
464
+ });
465
+ if (!frame) return unverified();
466
+ try {
467
+ const frameWindow = attempt(
468
+ () => INITIAL_REFLECT_APPLY(contentWindowGetter, frame, [])
469
+ );
470
+ if (!frameWindow) return unverified();
471
+ if (frameWindow === globalThis) return unverified("realm-not-distinct");
472
+ const borrowed = attempt(() => frameWindow.Function?.prototype?.toString);
473
+ if (typeof borrowed !== "function") return unverified();
474
+ if (borrowed === INITIAL_FN_TO_STRING) return unverified("realm-not-distinct");
475
+ const candidate = createRealmStringifier(borrowed);
476
+ if (!plausibleStringifier(candidate, borrowed)) return unverified("stringifier-implausible");
477
+ attempt(() => frame.remove());
478
+ if (!candidate(INITIAL_FN_TO_STRING).ok) return unverified();
479
+ return { stringify: candidate, clean: true };
480
+ } finally {
481
+ attempt(() => frame.remove());
482
+ }
483
+ }
484
+ function markPatched(patched, path) {
485
+ if (!patched.includes(path)) patched.push(path);
486
+ }
487
+ function findPatchedNatives(w, realm = borrowRealmToString()) {
488
+ const patched = [];
489
+ const lies = [];
490
+ const { stringify, clean, reason } = realm;
491
+ if (!clean) {
492
+ lies.push(
493
+ reason === void 0 ? { id: "realm", kind: "unverified_realm" } : { id: "realm", kind: "unverified_realm", detail: reason }
494
+ );
495
+ }
496
+ for (const targetSpec of TARGETS) {
497
+ const { path, expectedName, isGetter = false, brandArgsList, resolve } = targetSpec;
498
+ const target = attempt(() => resolve(w));
499
+ if (target === void 0 || target === null) {
500
+ lies.push({ id: path, kind: "missing" });
501
+ continue;
502
+ }
503
+ if (typeof target !== "function") {
504
+ markPatched(patched, path);
505
+ lies.push({ id: path, kind: "not-native" });
506
+ continue;
507
+ }
508
+ const stringified = stringify(target);
509
+ if (!stringified.ok) {
510
+ markPatched(patched, path);
511
+ lies.push({ id: path, kind: "to-string-threw" });
512
+ } else if (!isNativeFunctionSource(target, stringified.source, expectedName, isGetter)) {
513
+ markPatched(patched, path);
514
+ lies.push({ id: path, kind: "not-native" });
515
+ }
516
+ if (brandArgsList && !passesWebIdlBrandCheck(target, brandArgsList)) {
517
+ markPatched(patched, path);
518
+ lies.push({ id: path, kind: "brand" });
519
+ }
520
+ }
521
+ const currentOwn = attempt(() => Function.prototype.toString);
522
+ if (currentOwn !== INITIAL_FN_TO_STRING) {
523
+ markPatched(patched, "Function.prototype.toString");
524
+ if (!lies.some((lie) => lie.id === "Function.prototype.toString" && lie.kind !== "missing")) {
525
+ lies.push({
526
+ id: "Function.prototype.toString",
527
+ kind: "not-native",
528
+ detail: "replaced-after-init"
529
+ });
530
+ }
531
+ } else if (clean && typeof currentOwn === "function") {
532
+ const viaBorrowed = stringify(currentOwn);
533
+ if (!viaBorrowed.ok) {
534
+ markPatched(patched, "Function.prototype.toString");
535
+ lies.push({
536
+ id: "Function.prototype.toString",
537
+ kind: "to-string-threw",
538
+ detail: "caught-via-fresh-realm"
539
+ });
540
+ } else if (!isNativeFunctionSource(currentOwn, viaBorrowed.source, "toString", false)) {
541
+ markPatched(patched, "Function.prototype.toString");
542
+ if (!lies.some((lie) => lie.id === "Function.prototype.toString" && lie.kind === "not-native")) {
543
+ lies.push({
544
+ id: "Function.prototype.toString",
545
+ kind: "not-native",
546
+ detail: "caught-via-fresh-realm"
547
+ });
548
+ }
549
+ }
550
+ }
551
+ return { patched, lies, clean, stringify };
552
+ }
553
+
90
554
  // src/lies/descriptors.ts
91
- var NATIVE_PATTERN = /\{\s*\[native code\]\s*\}\s*$/;
92
555
  var INSTANCE_SHOULD_NOT_OWN = [
93
556
  ["navigator", "webdriver"],
94
557
  ["navigator", "userAgent"],
@@ -107,15 +570,52 @@ var INSTANCE_SHOULD_NOT_OWN = [
107
570
  ["screen", "height"],
108
571
  ["screen", "availWidth"],
109
572
  ["screen", "availHeight"],
110
- ["screen", "colorDepth"]
573
+ ["screen", "colorDepth"],
574
+ ["screen", "pixelDepth"],
575
+ ["screen", "orientation"]
111
576
  ];
112
- function findRedefinedProperties(w) {
577
+ var EMPTY_BRAND_ARGS = [[]];
578
+ function sameReading(a, b) {
579
+ if (Object.is(a, b)) return true;
580
+ if (Array.isArray(a) && Array.isArray(b)) {
581
+ return a.length === b.length && a.every((item, index) => Object.is(item, b[index]));
582
+ }
583
+ return false;
584
+ }
585
+ function wrapperLies(holderName, holder, property, getter, lies) {
586
+ let viaGetter;
587
+ try {
588
+ viaGetter = INITIAL_REFLECT_APPLY(getter, holder, []);
589
+ } catch {
590
+ if (!lies.some((lie) => lie.id === holderName && lie.kind === "brand")) {
591
+ lies.push({ id: holderName, kind: "brand", detail: "receiver-rejected" });
592
+ }
593
+ return;
594
+ }
595
+ let viaRead;
596
+ try {
597
+ viaRead = holder[property];
598
+ } catch {
599
+ lies.push({ id: `${holderName}.${property}`, kind: "contradiction", detail: "read-threw" });
600
+ return;
601
+ }
602
+ const comparable = (viaGetter === null || typeof viaGetter !== "object" || Array.isArray(viaGetter)) && (viaRead === null || typeof viaRead !== "object" || Array.isArray(viaRead));
603
+ if (comparable && !sameReading(viaGetter, viaRead)) {
604
+ lies.push({ id: `${holderName}.${property}`, kind: "contradiction", detail: "read-differs-from-getter" });
605
+ }
606
+ }
607
+ function findRedefinedProperties(w, stringify = createRealmStringifier(), options = {}) {
608
+ const readValues = options.readValues !== false;
113
609
  const lies = [];
610
+ const holders = {
611
+ navigator: attempt(() => w.navigator),
612
+ screen: attempt(() => w.screen)
613
+ };
114
614
  for (const [holderName, property] of INSTANCE_SHOULD_NOT_OWN) {
115
- const holder = holderName === "navigator" ? w.navigator : w.screen;
615
+ const holder = holders[holderName];
116
616
  if (!holder) continue;
117
- const own = attempt(() => Object.getOwnPropertyDescriptor(holder, property));
118
- if (own) {
617
+ const own2 = attempt(() => INITIAL_GET_OWN_PROP_DESC(holder, property));
618
+ if (own2) {
119
619
  lies.push({
120
620
  id: `${holderName}.${property}`,
121
621
  kind: "descriptor",
@@ -123,118 +623,60 @@ function findRedefinedProperties(w) {
123
623
  });
124
624
  continue;
125
625
  }
126
- const proto = attempt(() => Object.getPrototypeOf(holder));
626
+ const proto = attempt(() => INITIAL_GET_PROTOTYPE_OF(holder));
127
627
  if (!proto) continue;
128
- const inherited = attempt(() => Object.getOwnPropertyDescriptor(proto, property));
129
- if (!inherited?.get) continue;
130
- const source = attempt(() => Function.prototype.toString.call(inherited.get));
131
- if (source !== void 0 && !NATIVE_PATTERN.test(source)) {
628
+ const inherited = attempt(() => INITIAL_GET_OWN_PROP_DESC(proto, property));
629
+ if (!inherited) continue;
630
+ const getterId = `${holderName}.${property}.getter`;
631
+ if ("value" in inherited && inherited.get === void 0) {
132
632
  lies.push({
133
- id: `${holderName}.${property}.getter`,
633
+ id: getterId,
634
+ kind: "descriptor",
635
+ detail: "data-property-replaces-getter"
636
+ });
637
+ continue;
638
+ }
639
+ const getter = inherited.get;
640
+ if (typeof getter !== "function") continue;
641
+ const stringified = stringify(getter);
642
+ if (!stringified.ok) {
643
+ lies.push({
644
+ id: getterId,
645
+ kind: "to-string-threw"
646
+ });
647
+ } else if (!isNativeFunctionSource(getter, stringified.source, property, true)) {
648
+ lies.push({
649
+ id: getterId,
134
650
  kind: "descriptor",
135
651
  detail: "getter-is-not-native"
136
652
  });
137
653
  }
654
+ if (!passesWebIdlBrandCheck(getter, EMPTY_BRAND_ARGS)) {
655
+ lies.push({
656
+ id: getterId,
657
+ kind: "brand",
658
+ detail: "getter-accepted-invalid-receiver"
659
+ });
660
+ }
661
+ if (readValues) {
662
+ wrapperLies(holderName, holder, property, getter, lies);
663
+ }
138
664
  }
139
- const navigatorProto = attempt(() => Object.getPrototypeOf(w.navigator));
140
- if (w.Navigator && navigatorProto !== void 0 && navigatorProto !== w.Navigator.prototype) {
665
+ const NavigatorCtor = attempt(() => w.Navigator);
666
+ const navigatorProto = holders.navigator ? attempt(() => INITIAL_GET_PROTOTYPE_OF(holders.navigator)) : void 0;
667
+ const navigatorPrototype = attempt(() => NavigatorCtor?.prototype);
668
+ if (NavigatorCtor && navigatorProto !== void 0 && navigatorProto !== navigatorPrototype) {
141
669
  lies.push({ id: "navigator", kind: "prototype", detail: "not-Navigator.prototype" });
142
670
  }
143
- const screenProto = attempt(() => Object.getPrototypeOf(w.screen));
144
- if (w.Screen && screenProto !== void 0 && screenProto !== w.Screen.prototype) {
671
+ const ScreenCtor = attempt(() => w.Screen);
672
+ const screenProto = holders.screen ? attempt(() => INITIAL_GET_PROTOTYPE_OF(holders.screen)) : void 0;
673
+ const screenPrototype = attempt(() => ScreenCtor?.prototype);
674
+ if (ScreenCtor && screenProto !== void 0 && screenProto !== screenPrototype) {
145
675
  lies.push({ id: "screen", kind: "prototype", detail: "not-Screen.prototype" });
146
676
  }
147
677
  return lies;
148
678
  }
149
679
 
150
- // src/lies/natives.ts
151
- var NATIVE_PATTERN2 = /\{\s*\[native code\]\s*\}\s*$/;
152
- var TARGETS = [
153
- ["Function.prototype.toString", () => Function.prototype.toString],
154
- ["Function.prototype.bind", () => Function.prototype.bind],
155
- ["Object.getOwnPropertyDescriptor", () => Object.getOwnPropertyDescriptor],
156
- ["Object.defineProperty", () => Object.defineProperty],
157
- ["Date.prototype.getTimezoneOffset", () => Date.prototype.getTimezoneOffset],
158
- ["Number.prototype.toFixed", () => Number.prototype.toFixed],
159
- ["Error.prototype.toString", () => Error.prototype.toString],
160
- ["Intl.DateTimeFormat", () => Intl?.DateTimeFormat],
161
- ["Navigator.prototype.javaEnabled", (w) => w.Navigator?.prototype?.javaEnabled],
162
- ["Permissions.prototype.query", (w) => w.Permissions?.prototype?.query],
163
- ["MediaDevices.prototype.enumerateDevices", (w) => w.MediaDevices?.prototype?.enumerateDevices],
164
- ["HTMLCanvasElement.prototype.toDataURL", (w) => w.HTMLCanvasElement?.prototype?.toDataURL],
165
- [
166
- "CanvasRenderingContext2D.prototype.getImageData",
167
- (w) => w.CanvasRenderingContext2D?.prototype?.getImageData
168
- ],
169
- [
170
- "WebGLRenderingContext.prototype.getParameter",
171
- (w) => w.WebGLRenderingContext?.prototype?.getParameter
172
- ],
173
- [
174
- "WebGLRenderingContext.prototype.getExtension",
175
- (w) => w.WebGLRenderingContext?.prototype?.getExtension
176
- ],
177
- ["AudioBuffer.prototype.getChannelData", (w) => w.AudioBuffer?.prototype?.getChannelData],
178
- ["Element.prototype.getBoundingClientRect", (w) => w.Element?.prototype?.getBoundingClientRect],
179
- ["Performance.prototype.now", (w) => w.Performance?.prototype?.now],
180
- ["Screen.prototype.constructor", (w) => w.Screen]
181
- ];
182
- function borrowToString() {
183
- const own = Function.prototype.toString;
184
- if (typeof document === "undefined" || !document.body) return { fn: own, clean: false };
185
- const frame = attempt(() => {
186
- const element = document.createElement("iframe");
187
- element.setAttribute("sandbox", "allow-same-origin");
188
- element.style.display = "none";
189
- document.body.appendChild(element);
190
- return element;
191
- });
192
- if (!frame) return { fn: own, clean: false };
193
- try {
194
- const borrowed = attempt(
195
- () => frame.contentWindow?.Function?.prototype?.toString
196
- );
197
- return borrowed ? { fn: borrowed, clean: true } : { fn: own, clean: false };
198
- } finally {
199
- frame.remove();
200
- }
201
- }
202
- function findPatchedNatives(w) {
203
- const patched = [];
204
- const lies = [];
205
- const { fn: toString, clean } = borrowToString();
206
- const stringify = (value) => attempt(() => toString.call(value));
207
- for (const [path, resolve] of TARGETS) {
208
- const target = attempt(() => resolve(w));
209
- if (target === void 0 || target === null) {
210
- lies.push({ id: path, kind: "missing" });
211
- continue;
212
- }
213
- if (typeof target !== "function") continue;
214
- const source = stringify(target);
215
- if (source === void 0) continue;
216
- if (!NATIVE_PATTERN2.test(source)) {
217
- patched.push(path);
218
- lies.push({ id: path, kind: "not-native" });
219
- }
220
- }
221
- if (clean) {
222
- const own = Function.prototype.toString;
223
- const viaBorrowed = stringify(own);
224
- if (viaBorrowed !== void 0 && !NATIVE_PATTERN2.test(viaBorrowed)) {
225
- if (!patched.includes("Function.prototype.toString")) {
226
- patched.push("Function.prototype.toString");
227
- }
228
- lies.push({
229
- id: "Function.prototype.toString",
230
- kind: "not-native",
231
- detail: "caught-via-fresh-realm"
232
- });
233
- }
234
- }
235
- return { patched, lies };
236
- }
237
-
238
680
  // src/lies/index.ts
239
681
  function inspectIntegrity(sources) {
240
682
  const w = windowOrNull();
@@ -243,7 +685,6 @@ function inspectIntegrity(sources) {
243
685
  schema: 1,
244
686
  budget_ms: 0,
245
687
  elapsed_ms: 0,
246
- tiers: [],
247
688
  sources,
248
689
  integrity: { patched_natives: [], lies: [], engine: {} }
249
690
  },
@@ -256,11 +697,24 @@ function inspectIntegrity(sources) {
256
697
  if (!w) {
257
698
  return { patched_natives: [], lies: [], engine: identity };
258
699
  }
259
- const natives = findPatchedNatives(w);
260
- const descriptors = findRedefinedProperties(w);
700
+ const realm = borrowRealmToString();
701
+ let patched = [];
702
+ const lies = [];
703
+ try {
704
+ const natives = findPatchedNatives(w, realm);
705
+ patched = natives.patched;
706
+ lies.push(...natives.lies);
707
+ } catch {
708
+ lies.push({ id: "natives", kind: "unverified_realm", detail: "inspection-threw" });
709
+ }
710
+ try {
711
+ lies.push(...findRedefinedProperties(w, realm.stringify, { readValues: !detectEmbedding() }));
712
+ } catch {
713
+ lies.push({ id: "descriptors", kind: "unverified_realm", detail: "inspection-threw" });
714
+ }
261
715
  return {
262
- patched_natives: natives.patched,
263
- lies: [...natives.lies, ...descriptors],
716
+ patched_natives: patched,
717
+ lies,
264
718
  engine: identity
265
719
  };
266
720
  }
@@ -302,8 +756,8 @@ async function render(ctx) {
302
756
  }
303
757
  var audioSource = {
304
758
  id: SOURCE.audio,
305
- tier: "deferred",
306
- timeoutMs: 500,
759
+ stage: "collect",
760
+ timeoutMs: 250,
307
761
  async run(ctx) {
308
762
  const first = await render(ctx);
309
763
  if (first === 0) throw new BlockedSignal("audio-silent");
@@ -317,7 +771,7 @@ var audioSource = {
317
771
  };
318
772
  var audioLatencySource = {
319
773
  id: SOURCE.audioLatency,
320
- tier: "deferred",
774
+ stage: "collect",
321
775
  timeoutMs: 200,
322
776
  run() {
323
777
  const w = globalThis;
@@ -337,7 +791,7 @@ var audioLatencySource = {
337
791
  };
338
792
  var hardwareSource = {
339
793
  id: SOURCE.hardware,
340
- tier: "fast",
794
+ stage: "collect",
341
795
  run() {
342
796
  if (typeof navigator === "undefined") throw new UnsupportedSignal("no-navigator");
343
797
  const nav = navigator;
@@ -349,7 +803,7 @@ var hardwareSource = {
349
803
  };
350
804
  var touchSource = {
351
805
  id: SOURCE.touch,
352
- tier: "fast",
806
+ stage: "collect",
353
807
  run() {
354
808
  const w = requireWindow();
355
809
  return compact({
@@ -361,58 +815,14 @@ var touchSource = {
361
815
  }),
362
816
  pointer_coarse: attempt(() => w.matchMedia?.("(pointer: coarse)").matches),
363
817
  any_hover: attempt(() => w.matchMedia?.("(any-hover: hover)").matches),
364
- // Presence only, and in the fast tier for that reason: the deferred
365
- // `sensors` source is what waits to see whether an event fires. This is
366
- // what the server's mobile-UA-with-no-motion-sensors rule reads.
367
818
  device_motion: attempt(() => "DeviceMotionEvent" in w),
368
819
  device_orientation: attempt(() => "DeviceOrientationEvent" in w)
369
820
  });
370
821
  }
371
822
  };
372
- var sensorsSource = {
373
- id: SOURCE.sensors,
374
- tier: "deferred",
375
- // 150ms, not the 250 this started at. A real accelerometer delivers
376
- // `devicemotion` at 60Hz, so anything past the first few frames is waiting
377
- // for an event that is not coming.
378
- timeoutMs: 150,
379
- async run(ctx) {
380
- const w = requireWindow();
381
- const hasMotion = "DeviceMotionEvent" in w;
382
- const hasOrientation = "DeviceOrientationEvent" in w;
383
- if (!hasMotion && !hasOrientation) {
384
- return compact({ device_motion: false, device_orientation: false });
385
- }
386
- if (typeof document !== "undefined" && document.visibilityState === "hidden") {
387
- return compact({
388
- device_motion: hasMotion,
389
- device_orientation: hasOrientation
390
- });
391
- }
392
- const observed = await new Promise((resolve) => {
393
- let settled = false;
394
- const finish = (value) => {
395
- if (settled) return;
396
- settled = true;
397
- w.removeEventListener("devicemotion", onMotion);
398
- clearTimeout(timer);
399
- resolve(value);
400
- };
401
- const onMotion = () => finish(true);
402
- const timer = setTimeout(() => finish(false), 100);
403
- ctx.signal.addEventListener("abort", () => finish(false), { once: true });
404
- w.addEventListener("devicemotion", onMotion, { once: true });
405
- });
406
- return compact({
407
- device_motion: hasMotion,
408
- device_orientation: hasOrientation,
409
- motion_observed: observed
410
- });
411
- }
412
- };
413
823
  var mediaDevicesSource = {
414
824
  id: SOURCE.mediaDevices,
415
- tier: "fast",
825
+ stage: "collect",
416
826
  timeoutMs: 120,
417
827
  async run() {
418
828
  if (typeof navigator === "undefined") throw new UnsupportedSignal("no-navigator");
@@ -430,7 +840,7 @@ var mediaDevicesSource = {
430
840
  };
431
841
  var networkSource = {
432
842
  id: SOURCE.network,
433
- tier: "fast",
843
+ stage: "collect",
434
844
  run() {
435
845
  const connection = navigator.connection;
436
846
  if (!connection) throw new UnsupportedSignal("no-network-information");
@@ -444,22 +854,16 @@ var networkSource = {
444
854
  };
445
855
  var intlSource = {
446
856
  id: SOURCE.intl,
447
- tier: "fast",
857
+ stage: "collect",
448
858
  run() {
449
859
  if (typeof Intl === "undefined") throw new UnsupportedSignal("no-intl");
450
860
  const resolved = attempt(() => new Intl.DateTimeFormat().resolvedOptions());
451
861
  return compact({
452
862
  timezone: resolved?.timeZone,
453
- // Kept alongside the zone name because resistFingerprinting reports UTC
454
- // for both, while an ordinary browser in London reports Europe/London
455
- // with the same zero offset in winter. The pair separates them.
456
863
  timezone_offset: attempt(() => (/* @__PURE__ */ new Date()).getTimezoneOffset()),
457
864
  locale: resolved?.locale,
458
865
  calendar: resolved?.calendar,
459
866
  numbering_system: resolved?.numberingSystem,
460
- // A fixed instant formatted in the visitor's locale. Catches differences
461
- // in the ICU data the browser was built with, which the locale name alone
462
- // does not.
463
867
  formatted: attempt(
464
868
  () => new Intl.DateTimeFormat(void 0, {
465
869
  dateStyle: "full",
@@ -471,7 +875,7 @@ var intlSource = {
471
875
  };
472
876
  var timezoneSource = {
473
877
  id: SOURCE.timezone,
474
- tier: "fast",
878
+ stage: "collect",
475
879
  run() {
476
880
  if (typeof Intl === "undefined") throw new UnsupportedSignal("no-intl");
477
881
  return compact({
@@ -480,59 +884,9 @@ var timezoneSource = {
480
884
  });
481
885
  }
482
886
  };
483
- var batterySource = {
484
- id: SOURCE.battery,
485
- tier: "deferred",
486
- timeoutMs: 250,
487
- async run() {
488
- if (typeof navigator === "undefined") throw new UnsupportedSignal("no-navigator");
489
- const getBattery = navigator.getBattery;
490
- if (typeof getBattery !== "function") throw new UnsupportedSignal("no-battery-api");
491
- const battery = await getBattery.call(navigator);
492
- const finiteOrNull = (value) => value === void 0 ? void 0 : Number.isFinite(value) ? value : null;
493
- return compact({
494
- charging: battery.charging,
495
- charging_time: finiteOrNull(battery.chargingTime),
496
- discharging_time: finiteOrNull(battery.dischargingTime),
497
- level: battery.level
498
- });
499
- }
500
- };
501
- var speechSource = {
502
- id: SOURCE.speech,
503
- tier: "deferred",
504
- timeoutMs: 250,
505
- async run(ctx) {
506
- if (typeof speechSynthesis === "undefined") throw new UnsupportedSignal("no-speech-synthesis");
507
- let voices = speechSynthesis.getVoices();
508
- if (voices.length === 0) {
509
- voices = await new Promise((resolve) => {
510
- const finish = () => {
511
- speechSynthesis.removeEventListener("voiceschanged", changed);
512
- ctx.signal.removeEventListener("abort", aborted);
513
- resolve(speechSynthesis.getVoices());
514
- };
515
- const changed = () => finish();
516
- const aborted = () => finish();
517
- speechSynthesis.addEventListener("voiceschanged", changed, { once: true });
518
- ctx.signal.addEventListener("abort", aborted, { once: true });
519
- setTimeout(finish, Math.min(100, ctx.budgetRemainingMs()));
520
- });
521
- }
522
- return {
523
- voices: voices.map((voice) => ({
524
- name: voice.name,
525
- language: voice.lang,
526
- local_service: voice.localService,
527
- default: voice.default,
528
- uri: voice.voiceURI
529
- }))
530
- };
531
- }
532
- };
533
887
  var screenSource = {
534
888
  id: SOURCE.screen,
535
- tier: "fast",
889
+ stage: "collect",
536
890
  run() {
537
891
  const w = requireWindow();
538
892
  const s = w.screen;
@@ -571,7 +925,7 @@ function readFrame(w) {
571
925
  }
572
926
  var screenFrameSource = {
573
927
  id: SOURCE.screenFrame,
574
- tier: "fast",
928
+ stage: "collect",
575
929
  run() {
576
930
  const w = requireWindow();
577
931
  const frame = readFrame(w);
@@ -594,7 +948,7 @@ function matchFirst(w, queries) {
594
948
  }
595
949
  var mediaQueriesSource = {
596
950
  id: SOURCE.mediaQueries,
597
- tier: "fast",
951
+ stage: "collect",
598
952
  run() {
599
953
  const w = requireWindow();
600
954
  if (typeof w.matchMedia !== "function") throw new UnsupportedSignal("no-match-media");
@@ -625,7 +979,7 @@ var mediaQueriesSource = {
625
979
  };
626
980
  var colorGamutSource = {
627
981
  id: SOURCE.colorGamut,
628
- tier: "fast",
982
+ stage: "collect",
629
983
  run() {
630
984
  const w = requireWindow();
631
985
  if (typeof w.matchMedia !== "function") throw new UnsupportedSignal("no-match-media");
@@ -639,10 +993,9 @@ var colorGamutSource = {
639
993
  }
640
994
  };
641
995
  var PAYLOAD_BYTES = 16384;
642
- var WRITES_PER_BLOCK = 15;
643
- var MAX_ROUNDS = 9;
644
- var BUDGET_RESERVE_MS = 250;
645
- var CAP_MS = 600;
996
+ var WRITES_PER_BLOCK = 4;
997
+ var MAX_ROUNDS = 3;
998
+ var CAP_MS = 60;
646
999
  function openDatabase(name) {
647
1000
  return new Promise((resolve, reject) => {
648
1001
  const request = indexedDB.open(name, 1);
@@ -686,9 +1039,9 @@ function timeBlock(db, durability, payload) {
686
1039
  }
687
1040
  var storageDurabilitySource = {
688
1041
  id: SOURCE.storageDurability,
689
- tier: "deferred",
690
- // One round may overshoot the soft deadline; the slice has to cover that.
691
- timeoutMs: CAP_MS + 400,
1042
+ stage: "collect",
1043
+ optIn: "extended-incognito",
1044
+ timeoutMs: 80,
692
1045
  async run(ctx) {
693
1046
  requireWindow();
694
1047
  if (typeof indexedDB !== "object" || indexedDB === null) {
@@ -701,20 +1054,19 @@ var storageDurabilitySource = {
701
1054
  const payload = new Uint8Array(PAYLOAD_BYTES);
702
1055
  let db;
703
1056
  try {
1057
+ const started = performance.now();
1058
+ const deadline = started + Math.min(CAP_MS, Math.max(0, ctx.budgetRemainingMs()));
704
1059
  db = await openDatabase(name);
705
1060
  if (!durabilityHonored(db)) return { honored: false };
706
- await timeBlock(db, "relaxed", payload);
707
- await timeBlock(db, "strict", payload);
708
- const started = performance.now();
709
- const deadline = started + Math.min(CAP_MS, Math.max(0, ctx.budgetRemainingMs() - BUDGET_RESERVE_MS));
710
1061
  const ratios = [];
711
1062
  while (ratios.length < MAX_ROUNDS) {
712
- if (ctx.signal.aborted) break;
1063
+ if (ctx.signal.aborted || performance.now() >= deadline) break;
713
1064
  if (ratios.length > 0) {
714
1065
  const perRound = (performance.now() - started) / ratios.length;
715
1066
  if (performance.now() + perRound > deadline) break;
716
1067
  }
717
1068
  const relaxed = await timeBlock(db, "relaxed", payload);
1069
+ if (ctx.signal.aborted || performance.now() >= deadline) break;
718
1070
  const strict = await timeBlock(db, "strict", payload);
719
1071
  if (relaxed > 0) ratios.push(strict / relaxed);
720
1072
  else break;
@@ -735,90 +1087,6 @@ var storageDurabilitySource = {
735
1087
  }
736
1088
  }
737
1089
  };
738
- var FILTER_LISTS = [
739
- ["easylist", ".ad_300x250", ".textads"],
740
- ["easylist_germany", ".werbung1", ".werbeblock"],
741
- ["easylist_italy", ".pubbl", ".banner_pubblicita"],
742
- ["easylist_dutch", ".advertentie-container", ".reclame"],
743
- ["easyprivacy", ".trackingpixel", "#tracking-pixel"],
744
- ["fanboy_annoyances", "#newsletter-signup-modal", ".cookie-consent-banner"],
745
- ["fanboy_social", ".social-share-buttons", ".facebook-like-box"],
746
- ["adguard_base", "#adsense_widget", ".adsbygoogle-container"],
747
- ["adguard_annoyances", ".push-notification-prompt", "#app-install-banner"],
748
- ["listekr", "#ad_wrapper_top", ".ad_zone"],
749
- ["liste_fr", ".pub_300x250", "#pubfooter"],
750
- ["ro_list", ".reclama-mare", "#reclama"]
751
- ];
752
- var SETTLE_MS = 60;
753
- function nextPaint() {
754
- return new Promise((resolve) => {
755
- let settled = false;
756
- const done = () => {
757
- if (!settled) {
758
- settled = true;
759
- resolve();
760
- }
761
- };
762
- setTimeout(done, SETTLE_MS);
763
- if (typeof requestAnimationFrame === "function") requestAnimationFrame(() => setTimeout(done, 0));
764
- });
765
- }
766
- function hidden(element) {
767
- if (element.offsetParent === null) return true;
768
- if (element.offsetHeight === 0 || element.offsetWidth === 0) return true;
769
- const style = getComputedStyle(element);
770
- return style.display === "none" || style.visibility === "hidden";
771
- }
772
- function probe(document2, selector) {
773
- const element = document2.createElement("div");
774
- if (selector.startsWith("#")) element.id = selector.slice(1);
775
- else element.className = selector.slice(1);
776
- element.style.position = "absolute";
777
- element.style.top = "-9999px";
778
- element.style.left = "-9999px";
779
- element.style.width = "1px";
780
- element.style.height = "1px";
781
- return element;
782
- }
783
- var domBlockersSource = {
784
- id: SOURCE.domBlockers,
785
- // Deferred: it inserts elements, waits for a paint and reads back layout,
786
- // which is the most intrusive thing any source here does and has no business
787
- // competing with the fast tier for the budget.
788
- tier: "deferred",
789
- timeoutMs: 300,
790
- async run() {
791
- requireWindow();
792
- if (typeof document === "undefined" || !document.body) {
793
- throw new UnsupportedSignal("no-document-body");
794
- }
795
- const container = document.createElement("div");
796
- container.style.position = "absolute";
797
- container.style.top = "-9999px";
798
- container.style.left = "-9999px";
799
- container.style.width = "1px";
800
- container.style.height = "1px";
801
- const control = probe(document, ".fingerly-control-element");
802
- container.appendChild(control);
803
- const elements = FILTER_LISTS.map(([name, ...selectors]) => ({
804
- name,
805
- nodes: selectors.map((selector) => {
806
- const element = probe(document, selector);
807
- container.appendChild(element);
808
- return element;
809
- })
810
- }));
811
- document.body.appendChild(container);
812
- try {
813
- await nextPaint();
814
- if (hidden(control)) return {};
815
- const blocked = elements.filter(({ nodes }) => nodes.some(hidden)).map(({ name }) => name);
816
- return compact({ blocked, probed: FILTER_LISTS.length });
817
- } finally {
818
- container.remove();
819
- }
820
- }
821
- };
822
1090
  function toFixedErrorLength() {
823
1091
  return attempt(() => {
824
1092
  try {
@@ -873,9 +1141,44 @@ function claimedEngine(userAgent) {
873
1141
  if (/Safari\//.test(userAgent)) return "webkit";
874
1142
  return void 0;
875
1143
  }
1144
+ function cssSupports(property, value) {
1145
+ return attempt(
1146
+ () => typeof CSS !== "undefined" && typeof CSS.supports === "function" ? CSS.supports(property, value) : void 0
1147
+ );
1148
+ }
1149
+ function hasMotionPermissionFn() {
1150
+ return typeof DeviceMotionEvent !== "undefined" && typeof DeviceMotionEvent.requestPermission === "function";
1151
+ }
1152
+ function isGeckoEngine(ctx) {
1153
+ const completed = ctx?.completed?.(SOURCE.engine);
1154
+ if (completed?.status === "ok") {
1155
+ const val = completed.value;
1156
+ if (val?.observed === "gecko" || val?.claimed === "gecko") return true;
1157
+ if (val?.moz_appearance === true && cssSupports("-fingerly-nonexistent", "none") !== true) {
1158
+ return true;
1159
+ }
1160
+ }
1161
+ if (observedEngine(toFixedErrorLength(), evalLength(), stackStyle()) === "gecko") {
1162
+ return true;
1163
+ }
1164
+ const ua = attempt(() => typeof navigator === "undefined" ? void 0 : navigator.userAgent);
1165
+ if (claimedEngine(ua) === "gecko") return true;
1166
+ if (ua && /\bGecko\/\d/i.test(ua) && !/like Gecko|FxiOS/i.test(ua)) return true;
1167
+ if (cssSupports("-moz-appearance", "none") === true && cssSupports("-fingerly-nonexistent", "none") !== true) {
1168
+ return true;
1169
+ }
1170
+ const rootStyle = attempt(
1171
+ () => typeof document === "undefined" ? void 0 : document.documentElement?.style
1172
+ );
1173
+ if (rootStyle && "MozAppearance" in rootStyle && !("FingerlyNonexistent" in rootStyle)) {
1174
+ return true;
1175
+ }
1176
+ return false;
1177
+ }
876
1178
  var engineSource = {
877
1179
  id: SOURCE.engine,
878
- tier: "fast",
1180
+ stage: "prerequisite",
1181
+ embeddedSafe: true,
879
1182
  run() {
880
1183
  const toFixed = toFixedErrorLength();
881
1184
  const evalLen = evalLength();
@@ -889,9 +1192,10 @@ var engineSource = {
889
1192
  eval_length: evalLen,
890
1193
  stack_style: stack,
891
1194
  observed,
892
- // Compared on the server, where "we could not tell" and "they disagree"
893
- // are kept apart by which of the two is missing.
894
- claimed
1195
+ claimed,
1196
+ has_motion_permission_fn: attempt(hasMotionPermissionFn),
1197
+ moz_appearance: cssSupports("-moz-appearance", "none"),
1198
+ webkit_touch_callout: cssSupports("-webkit-touch-callout", "none")
895
1199
  });
896
1200
  }
897
1201
  };
@@ -921,28 +1225,21 @@ function identitiesHold() {
921
1225
  }
922
1226
  var mathSource = {
923
1227
  id: SOURCE.math,
924
- tier: "fast",
1228
+ stage: "collect",
1229
+ embeddedSafe: true,
925
1230
  timeoutMs: 50,
926
1231
  run() {
927
- const results = [];
928
1232
  let probed = 0;
929
1233
  const values = /* @__PURE__ */ new Map();
930
- for (const [name, probe2] of MATH_PROBES) {
931
- const value = attempt(probe2);
1234
+ for (const [name, probe] of MATH_PROBES) {
1235
+ const value = attempt(probe);
932
1236
  if (typeof value === "number" && Number.isFinite(value)) {
933
1237
  probed += 1;
934
1238
  values.set(name, value);
935
- results.push(`${name}:${value}`);
936
- } else {
937
- results.push(`${name}:`);
938
1239
  }
939
1240
  }
940
1241
  return compact({
941
- hash: hash64(results.join("|")),
942
1242
  probed,
943
- // The two the engines were measured to disagree about. See MathSignal
944
- // for the numbers; the other seventeen agreed to the last bit on the
945
- // machine they were measured on, which is why they are only in the hash.
946
1243
  atanh_half: values.get("atanh"),
947
1244
  expm1_1: values.get("expm1"),
948
1245
  identities_hold: attempt(identitiesHold)
@@ -960,26 +1257,26 @@ function thrownMessageLength(throwing) {
960
1257
  return void 0;
961
1258
  });
962
1259
  }
963
- function evalAllowed() {
964
- try {
965
- new Function("");
966
- return true;
967
- } catch {
968
- return false;
969
- }
1260
+ function regexpSyntaxError() {
1261
+ return new RegExp("(");
1262
+ }
1263
+ function redefineFrozen() {
1264
+ return Object.defineProperty(Object.freeze({ x: 1 }), "x", { value: 2 });
970
1265
  }
971
1266
  function observedFromErrors(errors) {
972
1267
  const votes = [];
973
- const own = errors.own_properties;
974
- if (own !== void 0) {
975
- if (own.includes("sourceURL")) votes.push("webkit", "webkit");
976
- else if (own.includes("lineNumber")) votes.push("gecko", "gecko");
977
- else if (own === "message,stack") votes.push("chromium", "chromium");
1268
+ const own2 = errors.own_properties;
1269
+ if (own2 !== void 0) {
1270
+ if (own2.includes("sourceURL")) votes.push("webkit", "webkit");
1271
+ else if (own2.includes("lineNumber")) votes.push("gecko", "gecko");
1272
+ else if (own2 === "message,stack") votes.push("chromium", "chromium");
978
1273
  }
979
1274
  if (errors.null_property_length === 44) votes.push("chromium");
980
1275
  else if (errors.null_property_length === 33) votes.push("gecko");
981
- if (errors.syntax_length === 20) votes.push("chromium");
982
- else if (errors.syntax_length === 28) votes.push("gecko");
1276
+ if (errors.regexp_syntax_length === 51) votes.push("chromium");
1277
+ else if (errors.regexp_syntax_length === 37) votes.push("webkit");
1278
+ if (errors.redefine_length === 27) votes.push("chromium");
1279
+ else if (errors.redefine_length === 50) votes.push("webkit");
983
1280
  if (votes.length === 0) return void 0;
984
1281
  const tally = /* @__PURE__ */ new Map();
985
1282
  for (const vote of votes) tally.set(vote, (tally.get(vote) ?? 0) + 1);
@@ -1008,24 +1305,23 @@ function errorOwnProperties() {
1008
1305
  }
1009
1306
  var errorsSource = {
1010
1307
  id: SOURCE.errors,
1011
- tier: "fast",
1308
+ stage: "collect",
1309
+ embeddedSafe: true,
1012
1310
  timeoutMs: 50,
1311
+ // No `new Function` or `eval` call (`WEB-10`): under a policy without
1312
+ // 'unsafe-eval' each one raised a CSP violation report on every run, and
1313
+ // three per run in report-only mode. Every probe here throws without
1314
+ // evaluating code.
1013
1315
  run() {
1014
- const compiles = evalAllowed();
1015
1316
  const shapes = compact({
1016
1317
  null_property_length: thrownMessageLength(() => null.x),
1017
- // `new Function` rather than `eval`, because a page with a strict
1018
- // Content-Security-Policy blocks both and this way the failure is one
1019
- // probe reporting nothing rather than the source throwing.
1020
- syntax_length: compiles ? thrownMessageLength(() => new Function("!")) : void 0,
1021
1318
  json_parse_length: thrownMessageLength(() => JSON.parse("{")),
1022
1319
  invalid_array_length: thrownMessageLength(() => {
1023
1320
  const array = [];
1024
1321
  array.length = -1;
1025
1322
  }),
1026
- const_assign_length: compiles ? thrownMessageLength(() => {
1027
- new Function("const c = 1; c = 2")();
1028
- }) : void 0,
1323
+ regexp_syntax_length: thrownMessageLength(regexpSyntaxError),
1324
+ redefine_length: thrownMessageLength(redefineFrozen),
1029
1325
  own_properties: errorOwnProperties(),
1030
1326
  capture_stack_trace: attempt(
1031
1327
  () => typeof Error.captureStackTrace === "function"
@@ -1037,10 +1333,18 @@ var errorsSource = {
1037
1333
  };
1038
1334
  var navigatorSource = {
1039
1335
  id: SOURCE.navigator,
1040
- tier: "fast",
1336
+ stage: "collect",
1337
+ embeddedSafe: true,
1041
1338
  run() {
1042
1339
  if (typeof navigator === "undefined") throw new UnsupportedSignal("no-navigator");
1043
1340
  const nav = navigator;
1341
+ if (detectEmbedding()) {
1342
+ return compact({
1343
+ user_agent: attempt(() => nav.userAgent),
1344
+ platform: attempt(() => nav.platform),
1345
+ webdriver: attempt(() => nav.webdriver)
1346
+ });
1347
+ }
1044
1348
  return compact({
1045
1349
  user_agent: attempt(() => nav.userAgent),
1046
1350
  platform: attempt(() => nav.platform),
@@ -1054,10 +1358,6 @@ var navigatorSource = {
1054
1358
  cookie_enabled: attempt(() => nav.cookieEnabled),
1055
1359
  pdf_viewer_enabled: attempt(() => nav.pdfViewerEnabled),
1056
1360
  do_not_track: attempt(() => nav.doNotTrack),
1057
- // The count rather than the list. The names are long, largely constant,
1058
- // and the only thing any detector reads is whether there are none - a
1059
- // desktop Chromium with zero plugins has no built-in PDF viewer, which
1060
- // means it was built headless.
1061
1361
  plugin_count: attempt(() => nav.plugins?.length),
1062
1362
  mime_type_count: attempt(() => nav.mimeTypes?.length),
1063
1363
  language: attempt(() => nav.language),
@@ -1067,7 +1367,7 @@ var navigatorSource = {
1067
1367
  };
1068
1368
  var languagesSource = {
1069
1369
  id: SOURCE.languages,
1070
- tier: "fast",
1370
+ stage: "collect",
1071
1371
  run() {
1072
1372
  if (typeof navigator === "undefined") throw new UnsupportedSignal("no-navigator");
1073
1373
  return compact({
@@ -1078,37 +1378,16 @@ var languagesSource = {
1078
1378
  };
1079
1379
  var vendorSource = {
1080
1380
  id: SOURCE.vendor,
1081
- tier: "fast",
1381
+ stage: "collect",
1082
1382
  run() {
1083
1383
  if (typeof navigator === "undefined") throw new UnsupportedSignal("no-navigator");
1084
1384
  return compact({ vendor: attempt(() => navigator.vendor) });
1085
1385
  }
1086
1386
  };
1087
- var pluginsSource = {
1088
- id: SOURCE.plugins,
1089
- tier: "fast",
1090
- run() {
1091
- if (typeof navigator === "undefined") throw new UnsupportedSignal("no-navigator");
1092
- const plugins = navigator.plugins;
1093
- if (!plugins) throw new UnsupportedSignal("no-plugins");
1094
- return {
1095
- plugins: Array.from(plugins, (plugin) => ({
1096
- name: plugin.name,
1097
- filename: plugin.filename,
1098
- description: plugin.description,
1099
- mime_types: Array.from(plugin, (mime) => ({
1100
- type: mime.type,
1101
- suffixes: mime.suffixes,
1102
- description: mime.description
1103
- }))
1104
- }))
1105
- };
1106
- }
1107
- };
1108
1387
  var userAgentDataSource = {
1109
1388
  id: SOURCE.userAgentData,
1110
- tier: "deferred",
1111
- timeoutMs: 200,
1389
+ stage: "collect",
1390
+ timeoutMs: 150,
1112
1391
  async run() {
1113
1392
  if (typeof navigator === "undefined") throw new UnsupportedSignal("no-navigator");
1114
1393
  const data = navigator.userAgentData;
@@ -1119,208 +1398,92 @@ var userAgentDataSource = {
1119
1398
  platform: data.platform
1120
1399
  });
1121
1400
  if (typeof data.getHighEntropyValues !== "function") return low;
1122
- const high = await data.getHighEntropyValues([
1123
- "architecture",
1124
- "bitness",
1125
- "model",
1126
- "platformVersion",
1127
- // Not uaFullVersion: deprecated in the client hints spec, and
1128
- // fullVersionList already carries the same version per brand.
1129
- "fullVersionList",
1130
- "wow64"
1131
- ]);
1132
- return { ...low, ...high };
1401
+ const high = await data.getHighEntropyValues(["architecture"]);
1402
+ const architecture = attempt(() => high.architecture);
1403
+ return typeof architecture === "string" ? { ...low, architecture } : low;
1133
1404
  }
1134
1405
  };
1135
- function makeCanvas(width, height) {
1136
- const canvas = document.createElement("canvas");
1137
- canvas.width = width;
1138
- canvas.height = height;
1139
- const context = canvas.getContext("2d");
1140
- if (!context) throw new UnsupportedSignal("no-2d-context");
1141
- return [canvas, context];
1406
+ var RFP_SHARED_KEY = "rfpCanvasBlocked";
1407
+ var GECKO_PROBE_MAX_MS = 2.8;
1408
+ var GECKO_SPIN_GUARD = 25e4;
1409
+ var CLAMPED_STALL_RESOLUTION_MS = 16.67;
1410
+ function roundResolution(ms) {
1411
+ return Math.round(ms * 1e6) / 1e6;
1142
1412
  }
1143
- function renderGeometry() {
1144
- const [canvas, ctx] = makeCanvas(240, 60);
1145
- ctx.globalCompositeOperation = "multiply";
1146
- for (const [colour, x, y] of [
1147
- ["#f2f", 40, 40],
1148
- ["#2ff", 80, 40],
1149
- ["#ff2", 60, 80]
1150
- ]) {
1151
- ctx.fillStyle = colour;
1152
- ctx.beginPath();
1153
- ctx.arc(x, y, 40, 0, Math.PI * 2, true);
1154
- ctx.closePath();
1155
- ctx.fill();
1156
- }
1157
- ctx.fillStyle = "#f9c";
1158
- ctx.arc(100, 50, 50, 0, Math.PI * 2, true);
1159
- ctx.arc(100, 50, 20, 0, Math.PI * 2, true);
1160
- ctx.fill("evenodd");
1161
- return canvas.toDataURL();
1162
- }
1163
- function renderText() {
1164
- const [canvas, ctx] = makeCanvas(300, 60);
1165
- ctx.textBaseline = "alphabetic";
1166
- ctx.fillStyle = "#f60";
1167
- ctx.fillRect(100, 1, 62, 20);
1168
- ctx.fillStyle = "#069";
1169
- ctx.font = '11pt "Times New Roman"';
1170
- ctx.fillText("Fingerly <canvas> 1.0 \u{1F512}\u0416\u4E2D", 2, 15);
1171
- ctx.font = "18pt Arial";
1172
- ctx.fillStyle = "rgba(102, 204, 0, 0.7)";
1173
- ctx.fillText("Fingerly <canvas> 1.0", 4, 45);
1174
- return canvas.toDataURL();
1175
- }
1176
- function supportsWinding() {
1177
- const [, ctx] = makeCanvas(1, 1);
1178
- ctx.rect(0, 0, 10, 10);
1179
- ctx.rect(2, 2, 6, 6);
1180
- return ctx.isPointInPath(5, 5, "evenodd") === false;
1181
- }
1182
- function resistFingerprintingActive(ctx) {
1183
- const timing = ctx.completed(SOURCE.timing);
1184
- if (timing?.status !== "ok") return false;
1185
- const resolution = timing.value?.now_resolution;
1186
- return typeof resolution === "number" && resolution >= 16;
1187
- }
1188
- var canvasSource = {
1189
- id: SOURCE.canvas,
1190
- tier: "deferred",
1191
- timeoutMs: 400,
1192
- run(ctx) {
1193
- requireWindow();
1194
- if (typeof document === "undefined") throw new UnsupportedSignal("no-document");
1195
- if (resistFingerprintingActive(ctx)) {
1196
- throw new BlockedSignal("rfp-canvas-prompt-avoided");
1197
- }
1198
- try {
1199
- const geometryFirst = renderGeometry();
1200
- const geometrySecond = renderGeometry();
1201
- const textFirst = renderText();
1202
- const textSecond = renderText();
1203
- const unstable = geometryFirst !== geometrySecond || textFirst !== textSecond;
1204
- return compact({
1205
- geometry: hash64(geometryFirst),
1206
- text: hash64(textFirst),
1207
- winding: attempt(supportsWinding),
1208
- unstable
1209
- });
1210
- } catch (error) {
1211
- asBlockedIfRefused(error);
1212
- }
1413
+ function probeGeckoRfp(now) {
1414
+ const wallDeadline = Date.now() + GECKO_PROBE_MAX_MS;
1415
+ const start = now();
1416
+ let end = now();
1417
+ let guard = 0;
1418
+ while (end === start && guard++ < GECKO_SPIN_GUARD && Date.now() < wallDeadline) {
1419
+ end = now();
1213
1420
  }
1214
- };
1215
- function webglContext() {
1216
- if (typeof document === "undefined") throw new UnsupportedSignal("no-document");
1217
- const canvas = document.createElement("canvas");
1218
- const gl = canvas.getContext("webgl") ?? canvas.getContext("experimental-webgl");
1219
- if (!gl) throw new UnsupportedSignal("no-webgl-context");
1220
- return gl;
1221
- }
1222
- var webglSource = {
1223
- id: SOURCE.webgl,
1224
- // Renderer and GPU strings are hard identity components, and context setup
1225
- // is synchronous; keep them in the authoritative initial report.
1226
- tier: "fast",
1227
- timeoutMs: 400,
1228
- run() {
1229
- const gl = webglContext();
1230
- const debug = attempt(() => gl.getExtension("WEBGL_debug_renderer_info"));
1231
- const parameters = {};
1232
- for (const name of [
1233
- "MAX_TEXTURE_SIZE",
1234
- "MAX_VIEWPORT_DIMS",
1235
- "MAX_VERTEX_ATTRIBS",
1236
- "MAX_VARYING_VECTORS",
1237
- "MAX_COMBINED_TEXTURE_IMAGE_UNITS",
1238
- "MAX_CUBE_MAP_TEXTURE_SIZE",
1239
- "MAX_FRAGMENT_UNIFORM_VECTORS",
1240
- "MAX_RENDERBUFFER_SIZE",
1241
- "MAX_TEXTURE_IMAGE_UNITS",
1242
- "MAX_VERTEX_TEXTURE_IMAGE_UNITS",
1243
- "MAX_VERTEX_UNIFORM_VECTORS",
1244
- "ALIASED_LINE_WIDTH_RANGE",
1245
- "ALIASED_POINT_SIZE_RANGE",
1246
- "RED_BITS",
1247
- "GREEN_BITS",
1248
- "BLUE_BITS",
1249
- "ALPHA_BITS",
1250
- "DEPTH_BITS",
1251
- "STENCIL_BITS"
1252
- ]) {
1253
- const constant = gl[name];
1254
- if (typeof constant !== "number") continue;
1255
- const value = attempt(() => gl.getParameter(constant));
1256
- if (value !== void 0 && value !== null) {
1257
- parameters[name] = ArrayBuffer.isView(value) ? Array.from(value) : value;
1258
- }
1259
- }
1260
- const precisions = [];
1261
- for (const shader of [gl.VERTEX_SHADER, gl.FRAGMENT_SHADER]) {
1262
- for (const precision of [gl.LOW_FLOAT, gl.MEDIUM_FLOAT, gl.HIGH_FLOAT]) {
1263
- const format = attempt(() => gl.getShaderPrecisionFormat(shader, precision));
1264
- if (format) precisions.push(format.rangeMin, format.rangeMax, format.precision);
1265
- }
1266
- }
1267
- return compact({
1268
- vendor: attempt(() => gl.getParameter(gl.VENDOR)),
1269
- renderer: attempt(() => gl.getParameter(gl.RENDERER)),
1270
- unmasked_vendor: debug ? attempt(() => gl.getParameter(debug.UNMASKED_VENDOR_WEBGL)) : void 0,
1271
- unmasked_renderer: debug ? attempt(() => gl.getParameter(debug.UNMASKED_RENDERER_WEBGL)) : void 0,
1272
- version: attempt(() => gl.getParameter(gl.VERSION)),
1273
- shading_language_version: attempt(
1274
- () => gl.getParameter(gl.SHADING_LANGUAGE_VERSION)
1275
- ),
1276
- max_texture_size: attempt(() => gl.getParameter(gl.MAX_TEXTURE_SIZE)),
1277
- max_render_buffer_size: attempt(() => gl.getParameter(gl.MAX_RENDERBUFFER_SIZE)),
1278
- // Hashed rather than sent whole: twenty parameters is a kilobyte of JSON
1279
- // that no detector reads field by field, and the report has a budget.
1280
- parameters_hash: Object.keys(parameters).length > 0 ? hash64(JSON.stringify(parameters)) : void 0,
1281
- shader_precision_hash: precisions.length > 0 ? hash64(precisions.join(",")) : void 0
1282
- });
1421
+ const delta = end - start;
1422
+ if (delta === 0) {
1423
+ return { resolution: CLAMPED_STALL_RESOLUTION_MS, rfpBlocked: true };
1283
1424
  }
1284
- };
1285
- var webglExtensionsSource = {
1286
- id: SOURCE.webglExtensions,
1287
- tier: "deferred",
1288
- timeoutMs: 200,
1289
- run() {
1290
- const gl = webglContext();
1291
- const extensions = gl.getSupportedExtensions();
1292
- if (!extensions) throw new BlockedSignal("extensions-withheld");
1293
- return [...extensions].sort();
1425
+ if (delta >= 1.5 || !(delta > 0 && delta <= 1.2)) {
1426
+ return {
1427
+ resolution: delta > 0 ? roundResolution(delta) : CLAMPED_STALL_RESOLUTION_MS,
1428
+ rfpBlocked: true
1429
+ };
1294
1430
  }
1295
- };
1296
- function clockResolution(now) {
1297
- const deltas = [];
1298
- const deadline = Date.now() + 12;
1299
- while (deltas.length < 25 && Date.now() < deadline) {
1300
- const start = now();
1301
- let end = now();
1302
- let guard = 0;
1303
- while (end === start && guard++ < 1e5 && Date.now() < deadline) end = now();
1304
- if (end !== start) deltas.push(end - start);
1431
+ return { resolution: roundResolution(delta), rfpBlocked: false };
1432
+ }
1433
+ function sampleNonGeckoClock(now) {
1434
+ const first = now();
1435
+ const second = now();
1436
+ return second > first ? roundResolution(second - first) : 0;
1437
+ }
1438
+ function isRfpCanvasBlocked(ctx) {
1439
+ const cached = ctx?.shared?.get(RFP_SHARED_KEY);
1440
+ if (typeof cached === "boolean") return cached;
1441
+ const timing = ctx?.completed?.(SOURCE.timing);
1442
+ if (timing?.status === "ok") {
1443
+ const val = timing.value;
1444
+ if (val?.rfp_canvas_blocked === true) return true;
1445
+ if (typeof val?.now_resolution === "number" && val.now_resolution >= 1.5) return true;
1446
+ if (typeof val?.rfp_canvas_blocked === "boolean") return val.rfp_canvas_blocked;
1447
+ if (typeof val?.now_resolution === "number") return false;
1305
1448
  }
1306
- if (deltas.length === 0) {
1307
- return 100;
1449
+ if (isGeckoEngine(ctx)) {
1450
+ const w = typeof window === "undefined" ? void 0 : window;
1451
+ if (typeof w?.performance?.now !== "function") return true;
1452
+ const probed = probeGeckoRfp(() => w.performance.now());
1453
+ ctx?.shared?.set(RFP_SHARED_KEY, probed.rfpBlocked);
1454
+ return probed.rfpBlocked;
1308
1455
  }
1309
- return Math.round(Math.min(...deltas) * 1e6) / 1e6;
1456
+ return false;
1310
1457
  }
1311
1458
  var timingSource = {
1312
1459
  id: SOURCE.timing,
1313
- tier: "fast",
1314
- timeoutMs: 150,
1315
- run() {
1460
+ stage: "prerequisite",
1461
+ timeoutMs: 50,
1462
+ run(ctx) {
1316
1463
  const w = requireWindow();
1317
1464
  const perf = w.performance;
1318
1465
  if (typeof perf?.now !== "function") {
1319
- return compact({ has_performance: false });
1466
+ const gecko = isGeckoEngine(ctx);
1467
+ ctx?.shared?.set(RFP_SHARED_KEY, gecko);
1468
+ return compact({
1469
+ has_performance: false,
1470
+ rfp_canvas_blocked: gecko
1471
+ });
1472
+ }
1473
+ if (!isGeckoEngine(ctx)) {
1474
+ ctx?.shared?.set(RFP_SHARED_KEY, false);
1475
+ return compact({
1476
+ has_performance: true,
1477
+ now_resolution: sampleNonGeckoClock(() => perf.now()),
1478
+ rfp_canvas_blocked: false
1479
+ });
1320
1480
  }
1481
+ const probed = probeGeckoRfp(() => perf.now());
1482
+ ctx?.shared?.set(RFP_SHARED_KEY, probed.rfpBlocked);
1321
1483
  return compact({
1322
1484
  has_performance: true,
1323
- now_resolution: clockResolution(() => perf.now())
1485
+ now_resolution: probed.resolution,
1486
+ rfp_canvas_blocked: probed.rfpBlocked
1324
1487
  });
1325
1488
  }
1326
1489
  };
@@ -1340,8 +1503,8 @@ function permissionStatus(w, name) {
1340
1503
  }
1341
1504
  var permissionsSource = {
1342
1505
  id: SOURCE.permissions,
1343
- tier: "fast",
1344
- timeoutMs: 200,
1506
+ stage: "collect",
1507
+ timeoutMs: 150,
1345
1508
  async run() {
1346
1509
  const w = requireWindow();
1347
1510
  if (!w.navigator.permissions?.query) throw new UnsupportedSignal("no-permissions-api");
@@ -1353,7 +1516,9 @@ var permissionsSource = {
1353
1516
  }
1354
1517
  };
1355
1518
  const notification = await query("notifications");
1356
- const legacy = attempt(() => w.Notification?.permission);
1519
+ const legacy = attempt(
1520
+ () => w.Notification?.permission
1521
+ );
1357
1522
  return compact({
1358
1523
  notification,
1359
1524
  notification_legacy: legacy,
@@ -1384,23 +1549,45 @@ var AUTOMATION_GLOBALS = [
1384
1549
  "domAutomationController",
1385
1550
  "__lastWatirAlert",
1386
1551
  "__playwright",
1552
+ "__playwright__binding__",
1553
+ "__pwInitScripts",
1387
1554
  "__puppeteer",
1388
1555
  "__pw_manual"
1389
1556
  ];
1557
+ var CDC_PATTERN = /^cdc_|^\$cdc_/;
1558
+ function collectCdcMarkers(w) {
1559
+ const found = /* @__PURE__ */ new Set();
1560
+ const windowProps = attempt(() => Object.getOwnPropertyNames(w));
1561
+ if (windowProps) {
1562
+ for (const name of windowProps) {
1563
+ if (CDC_PATTERN.test(name)) found.add(name);
1564
+ }
1565
+ }
1566
+ const doc = attempt(() => w.document);
1567
+ if (doc) {
1568
+ const docProps = attempt(() => Object.getOwnPropertyNames(doc));
1569
+ if (docProps) {
1570
+ for (const name of docProps) {
1571
+ if (CDC_PATTERN.test(name)) found.add(name);
1572
+ }
1573
+ }
1574
+ }
1575
+ return [...found];
1576
+ }
1390
1577
  var automationSource = {
1391
1578
  id: SOURCE.automation,
1392
- tier: "fast",
1579
+ stage: "collect",
1580
+ embeddedSafe: true,
1393
1581
  run() {
1394
1582
  const w = requireWindow();
1395
- const present = AUTOMATION_GLOBALS.filter((name) => attempt(() => name in w) === true);
1396
- const cdp = attempt(
1397
- () => Object.getOwnPropertyNames(w).filter((name) => /^cdc_|^\$cdc_/.test(name))
1583
+ const present = AUTOMATION_GLOBALS.filter(
1584
+ (name) => attempt(() => name in w || w.document != null && name in w.document) === true
1398
1585
  );
1586
+ const cdp = collectCdcMarkers(w);
1399
1587
  return compact({
1400
1588
  webdriver: attempt(() => navigator.webdriver),
1401
- cdp_artifacts: cdp && cdp.length > 0 ? cdp : void 0,
1589
+ cdp_artifacts: cdp.length > 0 ? cdp : void 0,
1402
1590
  distinctive_properties: present.length > 0 ? [...present] : void 0,
1403
- chrome_object: attempt(() => "chrome" in w),
1404
1591
  window_external: attempt(() => {
1405
1592
  const external = w.external;
1406
1593
  return external ? String(external) : void 0;
@@ -1408,38 +1595,220 @@ var automationSource = {
1408
1595
  });
1409
1596
  }
1410
1597
  };
1598
+
1599
+ // src/sources/render.ts
1600
+ var SHARED_CANVAS_KEY = "canvas2d";
1601
+ function acquireCanvas2D(ctx, width, height) {
1602
+ if (typeof document === "undefined") return void 0;
1603
+ const shared = ctx?.shared;
1604
+ const existing = shared?.get(SHARED_CANVAS_KEY);
1605
+ if (existing) {
1606
+ existing.canvas.width = width;
1607
+ existing.canvas.height = height;
1608
+ return [existing.canvas, existing.context];
1609
+ }
1610
+ const canvas = document.createElement("canvas");
1611
+ canvas.width = width;
1612
+ canvas.height = height;
1613
+ const context = canvas.getContext("2d", { willReadFrequently: true }) ?? canvas.getContext("2d");
1614
+ if (!context) return void 0;
1615
+ shared?.set(SHARED_CANVAS_KEY, { canvas, context });
1616
+ return [canvas, context];
1617
+ }
1618
+ function requireCanvas2D(ctx, width, height) {
1619
+ const pair = acquireCanvas2D(ctx, width, height);
1620
+ if (!pair) throw new UnsupportedSignal("no-2d-context");
1621
+ return pair;
1622
+ }
1623
+ function renderGeometryHash(ctx) {
1624
+ const width = 240;
1625
+ const height = 60;
1626
+ const [, context] = requireCanvas2D(ctx, width, height);
1627
+ context.globalCompositeOperation = "multiply";
1628
+ for (const [colour, x, y] of [
1629
+ ["#f2f", 40, 40],
1630
+ ["#2ff", 80, 40],
1631
+ ["#ff2", 60, 80]
1632
+ ]) {
1633
+ context.fillStyle = colour;
1634
+ context.beginPath();
1635
+ context.arc(x, y, 40, 0, Math.PI * 2, true);
1636
+ context.closePath();
1637
+ context.fill();
1638
+ }
1639
+ context.fillStyle = "#f9c";
1640
+ context.arc(100, 50, 50, 0, Math.PI * 2, true);
1641
+ context.arc(100, 50, 20, 0, Math.PI * 2, true);
1642
+ context.fill("evenodd");
1643
+ return hash64(context.getImageData(0, 0, width, height).data);
1644
+ }
1645
+ function renderTextHash(ctx) {
1646
+ const width = 300;
1647
+ const height = 60;
1648
+ const [, context] = requireCanvas2D(ctx, width, height);
1649
+ context.textBaseline = "alphabetic";
1650
+ context.fillStyle = "#f60";
1651
+ context.fillRect(100, 1, 62, 20);
1652
+ context.fillStyle = "#069";
1653
+ context.font = '11pt "Times New Roman"';
1654
+ context.fillText("Fingerly <canvas> 1.0 \u{1F512}\u0416\u4E2D", 2, 15);
1655
+ context.font = "18pt Arial";
1656
+ context.fillStyle = "rgba(102, 204, 0, 0.7)";
1657
+ context.fillText("Fingerly <canvas> 1.0", 4, 45);
1658
+ return hash64(context.getImageData(0, 0, width, height).data);
1659
+ }
1660
+ function supportsWinding(ctx) {
1661
+ const [, context] = requireCanvas2D(ctx, 1, 1);
1662
+ context.rect(0, 0, 10, 10);
1663
+ context.rect(2, 2, 6, 6);
1664
+ return context.isPointInPath(5, 5, "evenodd") === false;
1665
+ }
1666
+ var canvasSource = {
1667
+ id: SOURCE.canvas,
1668
+ stage: "collect",
1669
+ timeoutMs: 250,
1670
+ run(ctx) {
1671
+ requireWindow();
1672
+ if (typeof document === "undefined") throw new UnsupportedSignal("no-document");
1673
+ if (isRfpCanvasBlocked(ctx)) {
1674
+ throw new BlockedSignal("rfp-canvas-prompt-avoided");
1675
+ }
1676
+ try {
1677
+ const geometryFirst = renderGeometryHash(ctx);
1678
+ const geometrySecond = renderGeometryHash(ctx);
1679
+ const textFirst = renderTextHash(ctx);
1680
+ const textSecond = renderTextHash(ctx);
1681
+ const unstable = geometryFirst !== geometrySecond || textFirst !== textSecond;
1682
+ return compact({
1683
+ geometry: geometryFirst,
1684
+ text: textFirst,
1685
+ winding: attempt(() => supportsWinding(ctx)),
1686
+ unstable
1687
+ });
1688
+ } catch (error) {
1689
+ asBlockedIfRefused(error);
1690
+ }
1691
+ }
1692
+ };
1693
+ function webglContext() {
1694
+ if (typeof document === "undefined") throw new UnsupportedSignal("no-document");
1695
+ const canvas = document.createElement("canvas");
1696
+ const gl = canvas.getContext("webgl") ?? canvas.getContext("experimental-webgl");
1697
+ if (!gl) throw new UnsupportedSignal("no-webgl-context");
1698
+ return gl;
1699
+ }
1700
+ var webglSource = {
1701
+ id: SOURCE.webgl,
1702
+ stage: "collect",
1703
+ timeoutMs: 250,
1704
+ run() {
1705
+ const gl = webglContext();
1706
+ try {
1707
+ const debug = attempt(() => gl.getExtension("WEBGL_debug_renderer_info"));
1708
+ const parameters = {};
1709
+ for (const name of [
1710
+ "MAX_TEXTURE_SIZE",
1711
+ "MAX_VIEWPORT_DIMS",
1712
+ "MAX_VERTEX_ATTRIBS",
1713
+ "MAX_VARYING_VECTORS",
1714
+ "MAX_COMBINED_TEXTURE_IMAGE_UNITS",
1715
+ "MAX_CUBE_MAP_TEXTURE_SIZE",
1716
+ "MAX_FRAGMENT_UNIFORM_VECTORS",
1717
+ "MAX_RENDERBUFFER_SIZE",
1718
+ "MAX_TEXTURE_IMAGE_UNITS",
1719
+ "MAX_VERTEX_TEXTURE_IMAGE_UNITS",
1720
+ "MAX_VERTEX_UNIFORM_VECTORS",
1721
+ "ALIASED_LINE_WIDTH_RANGE",
1722
+ "ALIASED_POINT_SIZE_RANGE",
1723
+ "RED_BITS",
1724
+ "GREEN_BITS",
1725
+ "BLUE_BITS",
1726
+ "ALPHA_BITS",
1727
+ "DEPTH_BITS",
1728
+ "STENCIL_BITS"
1729
+ ]) {
1730
+ const constant = gl[name];
1731
+ if (typeof constant !== "number") continue;
1732
+ const value = attempt(() => gl.getParameter(constant));
1733
+ if (value !== void 0 && value !== null) {
1734
+ parameters[name] = ArrayBuffer.isView(value) ? Array.from(value) : value;
1735
+ }
1736
+ }
1737
+ const precisions = [];
1738
+ for (const shader of [gl.VERTEX_SHADER, gl.FRAGMENT_SHADER]) {
1739
+ for (const precision of [gl.LOW_FLOAT, gl.MEDIUM_FLOAT, gl.HIGH_FLOAT]) {
1740
+ const format = attempt(() => gl.getShaderPrecisionFormat(shader, precision));
1741
+ if (format) precisions.push(format.rangeMin, format.rangeMax, format.precision);
1742
+ }
1743
+ }
1744
+ return compact({
1745
+ vendor: attempt(() => gl.getParameter(gl.VENDOR)),
1746
+ renderer: attempt(() => gl.getParameter(gl.RENDERER)),
1747
+ unmasked_vendor: debug ? attempt(() => gl.getParameter(debug.UNMASKED_VENDOR_WEBGL)) : void 0,
1748
+ unmasked_renderer: debug ? attempt(() => gl.getParameter(debug.UNMASKED_RENDERER_WEBGL)) : void 0,
1749
+ version: attempt(() => gl.getParameter(gl.VERSION)),
1750
+ shading_language_version: attempt(
1751
+ () => gl.getParameter(gl.SHADING_LANGUAGE_VERSION)
1752
+ ),
1753
+ max_texture_size: attempt(() => gl.getParameter(gl.MAX_TEXTURE_SIZE)),
1754
+ max_render_buffer_size: attempt(() => gl.getParameter(gl.MAX_RENDERBUFFER_SIZE)),
1755
+ parameters_hash: Object.keys(parameters).length > 0 ? hash64(JSON.stringify(parameters)) : void 0,
1756
+ shader_precision_hash: precisions.length > 0 ? hash64(precisions.join(",")) : void 0
1757
+ });
1758
+ } finally {
1759
+ attempt(() => gl.getExtension("WEBGL_lose_context")?.loseContext());
1760
+ }
1761
+ }
1762
+ };
1763
+ var webglExtensionsSource = {
1764
+ id: SOURCE.webglExtensions,
1765
+ stage: "collect",
1766
+ timeoutMs: 200,
1767
+ run() {
1768
+ const gl = webglContext();
1769
+ try {
1770
+ const extensions = gl.getSupportedExtensions();
1771
+ if (!extensions) throw new BlockedSignal("extensions-withheld");
1772
+ return [...extensions].sort();
1773
+ } finally {
1774
+ attempt(() => gl.getExtension("WEBGL_lose_context")?.loseContext());
1775
+ }
1776
+ }
1777
+ };
1411
1778
  var VENDOR_API_MS = 50;
1412
1779
  var TIMED_OUT = /* @__PURE__ */ Symbol("timed-out");
1413
1780
  async function askBrave(nav) {
1414
- if (typeof nav.brave?.isBrave !== "function") return void 0;
1781
+ const brave = attempt(() => nav.brave);
1782
+ if (brave === void 0 || brave === null) return "absent";
1783
+ const isBrave = attempt(() => brave.isBrave);
1784
+ if (typeof isBrave !== "function") return "not-function";
1415
1785
  try {
1416
1786
  const answer = await Promise.race([
1417
- nav.brave.isBrave(),
1787
+ isBrave.call(brave),
1418
1788
  new Promise((resolve) => setTimeout(() => resolve(TIMED_OUT), VENDOR_API_MS))
1419
1789
  ]);
1420
- return answer === TIMED_OUT ? void 0 : answer === true;
1790
+ if (answer === TIMED_OUT) return "timeout";
1791
+ return answer === true ? "true" : "false";
1421
1792
  } catch {
1422
- return void 0;
1793
+ return "threw";
1423
1794
  }
1424
1795
  }
1425
- function claimsBrave(nav) {
1426
- const brands = nav.userAgentData?.brands;
1796
+ function brandsOf(nav) {
1797
+ const brands = attempt(() => nav.userAgentData?.brands);
1427
1798
  if (!Array.isArray(brands)) return void 0;
1428
- return brands.some((entry) => entry?.brand === "Brave");
1799
+ return brands.map((entry) => attempt(() => entry?.brand)).filter((brand) => typeof brand === "string");
1429
1800
  }
1430
1801
  var CANARY_COLOURS = [
1431
1802
  [30, 60, 90],
1432
1803
  [210, 180, 140]
1433
1804
  ];
1434
1805
  var CANARY_SIZE = 8;
1435
- function canvasNoise() {
1806
+ function readCanary(ctx) {
1436
1807
  if (typeof document === "undefined") return void 0;
1437
1808
  try {
1438
- const canvas = document.createElement("canvas");
1439
- canvas.width = CANARY_SIZE;
1440
- canvas.height = CANARY_SIZE;
1441
- const context = canvas.getContext("2d", { willReadFrequently: true });
1442
- if (!context) return void 0;
1809
+ const pair = acquireCanvas2D(ctx, CANARY_SIZE, CANARY_SIZE);
1810
+ if (!pair) return void 0;
1811
+ const [, context] = pair;
1443
1812
  for (let y = 0; y < CANARY_SIZE; y++) {
1444
1813
  for (let x = 0; x < CANARY_SIZE; x++) {
1445
1814
  const [r, g, b] = CANARY_COLOURS[(x + y) % 2];
@@ -1448,31 +1817,51 @@ function canvasNoise() {
1448
1817
  }
1449
1818
  }
1450
1819
  const pixels = context.getImageData(0, 0, CANARY_SIZE, CANARY_SIZE).data;
1451
- for (let index = 0; index < CANARY_SIZE * CANARY_SIZE; index++) {
1820
+ let mismatched = 0;
1821
+ let maxDelta = 0;
1822
+ const total = CANARY_SIZE * CANARY_SIZE;
1823
+ for (let index = 0; index < total; index++) {
1452
1824
  const x = index % CANARY_SIZE;
1453
1825
  const y = Math.floor(index / CANARY_SIZE);
1454
1826
  const [r, g, b] = CANARY_COLOURS[(x + y) % 2];
1455
1827
  const at = index * 4;
1456
- if (pixels[at] !== r || pixels[at + 1] !== g || pixels[at + 2] !== b || pixels[at + 3] !== 255) {
1457
- return true;
1458
- }
1828
+ const deltas = [
1829
+ Math.abs((pixels[at] ?? 0) - r),
1830
+ Math.abs((pixels[at + 1] ?? 0) - g),
1831
+ Math.abs((pixels[at + 2] ?? 0) - b),
1832
+ Math.abs((pixels[at + 3] ?? 0) - 255)
1833
+ ];
1834
+ const worst = Math.max(...deltas);
1835
+ if (worst > 0) mismatched += 1;
1836
+ if (worst > maxDelta) maxDelta = worst;
1459
1837
  }
1460
- return false;
1838
+ return { pixels: total, mismatched, maxDelta };
1461
1839
  } catch {
1462
1840
  return void 0;
1463
1841
  }
1464
1842
  }
1465
1843
  var shieldsSource = {
1466
1844
  id: SOURCE.shields,
1467
- tier: "fast",
1845
+ stage: "collect",
1468
1846
  timeoutMs: 100,
1469
- async run() {
1847
+ async run(ctx) {
1848
+ if (isRfpCanvasBlocked(ctx)) {
1849
+ throw new BlockedSignal("rfp-canvas-prompt-avoided");
1850
+ }
1470
1851
  if (typeof navigator === "undefined") throw new UnsupportedSignal("no-navigator");
1471
1852
  const nav = navigator;
1853
+ const braveApi = await askBrave(nav);
1854
+ const brands = brandsOf(nav);
1855
+ const canary = readCanary(ctx);
1472
1856
  return compact({
1473
- brave: await askBrave(nav),
1474
- brave_claimed: claimsBrave(nav),
1475
- canvas_noise: canvasNoise()
1857
+ brave: braveApi === "true" ? true : braveApi === "false" ? false : void 0,
1858
+ brave_claimed: brands === void 0 ? void 0 : brands.includes("Brave"),
1859
+ canvas_noise: canary === void 0 ? void 0 : canary.mismatched > 0,
1860
+ brave_api: braveApi,
1861
+ brands,
1862
+ canary_pixels: canary?.pixels,
1863
+ canary_mismatched: canary?.mismatched,
1864
+ canary_max_delta: canary?.maxDelta
1476
1865
  });
1477
1866
  }
1478
1867
  };
@@ -1542,7 +1931,7 @@ function serviceWorkerAvailable() {
1542
1931
  }
1543
1932
  var storageSource = {
1544
1933
  id: SOURCE.storage,
1545
- tier: "fast",
1934
+ stage: "collect",
1546
1935
  timeoutMs: 250,
1547
1936
  async run() {
1548
1937
  requireWindow();
@@ -1585,7 +1974,7 @@ var storageSource = {
1585
1974
  };
1586
1975
  var storageQuotaSource = {
1587
1976
  id: SOURCE.storageQuota,
1588
- tier: "fast",
1977
+ stage: "collect",
1589
1978
  run() {
1590
1979
  requireWindow();
1591
1980
  if (typeof document === "undefined") throw new UnsupportedSignal("no-document");
@@ -1694,10 +2083,10 @@ var CANDIDATES = [
1694
2083
  ];
1695
2084
  var fontsSource = {
1696
2085
  id: SOURCE.fonts,
1697
- tier: "deferred",
2086
+ stage: "collect",
1698
2087
  // Generous: this measures ~300 spans, and forcing layout on a busy page is
1699
2088
  // genuinely slow. Still bounded, which is the part that matters.
1700
- timeoutMs: 700,
2089
+ timeoutMs: 250,
1701
2090
  run() {
1702
2091
  if (typeof document === "undefined") throw new UnsupportedSignal("no-document");
1703
2092
  const holder = document.createElement("div");
@@ -1742,7 +2131,7 @@ var fontsSource = {
1742
2131
  };
1743
2132
  var fontPreferencesSource = {
1744
2133
  id: SOURCE.fontPreferences,
1745
- tier: "deferred",
2134
+ stage: "collect",
1746
2135
  timeoutMs: 250,
1747
2136
  run() {
1748
2137
  if (typeof document === "undefined" || !document.body) {
@@ -1779,26 +2168,229 @@ var fontPreferencesSource = {
1779
2168
  }
1780
2169
  }
1781
2170
  };
2171
+ var WORKER_WAIT_MS = 330;
2172
+ var WORKER_WAIT_FLOOR_MS = 60;
2173
+ var WORKER_WAIT_MARGIN_MS = 15;
2174
+ function workerWaitMs(budgetRemainingMs) {
2175
+ const left = Number.isFinite(budgetRemainingMs) ? budgetRemainingMs - WORKER_WAIT_MARGIN_MS : WORKER_WAIT_MS;
2176
+ return Math.max(WORKER_WAIT_FLOOR_MS, Math.min(WORKER_WAIT_MS, left));
2177
+ }
2178
+ var sessionCspBlocked;
2179
+ function workerScript(full) {
2180
+ return `(function (full) {
2181
+ var out = {};
2182
+ try {
2183
+ if (typeof navigator !== 'undefined') {
2184
+ if (typeof navigator.userAgent === 'string') out.user_agent = navigator.userAgent;
2185
+ if (typeof navigator.platform === 'string') out.platform = navigator.platform;
2186
+ if (full && typeof navigator.hardwareConcurrency === 'number') out.hardware_concurrency = navigator.hardwareConcurrency;
2187
+ if (full && typeof navigator.deviceMemory === 'number') out.device_memory = navigator.deviceMemory;
2188
+ if (full && Array.isArray(navigator.languages)) out.languages = Array.prototype.slice.call(navigator.languages);
2189
+ }
2190
+ } catch (_) {}
2191
+ if (!full) { self.postMessage(out); return; }
2192
+ try {
2193
+ var tz0 = Intl.DateTimeFormat().resolvedOptions().timeZone;
2194
+ if (typeof tz0 === 'string' && tz0) out.timezone = tz0;
2195
+ } catch (_) {}
2196
+ // The navigator values first: a first WebGL context can take longer than
2197
+ // the whole collection budget on a cold page.
2198
+ self.postMessage({ partial: true, values: out });
2199
+ try {
2200
+ if (typeof OffscreenCanvas !== 'undefined') {
2201
+ var canvas = new OffscreenCanvas(1, 1);
2202
+ var gl = canvas.getContext('webgl') || canvas.getContext('webgl2');
2203
+ if (gl) {
2204
+ try {
2205
+ var dbg = gl.getExtension('WEBGL_debug_renderer_info');
2206
+ if (dbg) {
2207
+ var vendor = gl.getParameter(dbg.UNMASKED_VENDOR_WEBGL);
2208
+ var renderer = gl.getParameter(dbg.UNMASKED_RENDERER_WEBGL);
2209
+ if (typeof vendor === 'string' && vendor) out.unmasked_vendor = vendor;
2210
+ if (typeof renderer === 'string' && renderer) out.unmasked_renderer = renderer;
2211
+ }
2212
+ } finally {
2213
+ try {
2214
+ var lose = gl.getExtension('WEBGL_lose_context');
2215
+ if (lose && typeof lose.loseContext === 'function') lose.loseContext();
2216
+ } catch (_) {}
2217
+ }
2218
+ }
2219
+ }
2220
+ } catch (_) {}
2221
+ self.postMessage(out);
2222
+ })(${full ? "true" : "false"});`;
2223
+ }
2224
+ function policyAllowsBlobWorker(policyText) {
2225
+ const directives = /* @__PURE__ */ new Map();
2226
+ for (const rawPart of policyText.split(";")) {
2227
+ const trimmed = rawPart.trim();
2228
+ if (!trimmed) continue;
2229
+ const tokens = trimmed.split(/\s+/).map((token) => token.toLowerCase());
2230
+ const name = tokens[0];
2231
+ if (name && !directives.has(name)) {
2232
+ directives.set(name, tokens.slice(1));
2233
+ }
2234
+ }
2235
+ const effective = directives.get("worker-src") ?? directives.get("child-src") ?? directives.get("default-src");
2236
+ if (!effective) return true;
2237
+ return effective.some((token) => token === "blob:" || token.startsWith("blob:"));
2238
+ }
2239
+ function headMetaDisallowsBlobWorker(doc) {
2240
+ const head = attempt(() => doc?.head);
2241
+ if (!head) return false;
2242
+ const children = attempt(() => Array.from(head.children));
2243
+ if (!children) return false;
2244
+ for (const meta of children) {
2245
+ if (attempt(() => meta.tagName.toLowerCase()) !== "meta") continue;
2246
+ const equiv = attempt(() => meta.getAttribute("http-equiv")?.trim().toLowerCase());
2247
+ if (equiv !== "content-security-policy") continue;
2248
+ const content = attempt(() => meta.getAttribute("content"));
2249
+ if (typeof content === "string" && !policyAllowsBlobWorker(content)) {
2250
+ return true;
2251
+ }
2252
+ }
2253
+ return false;
2254
+ }
2255
+ function isCspSecurityError(error) {
2256
+ if (!(error instanceof Error)) return false;
2257
+ if (error.name === "SecurityError") return true;
2258
+ const msg = error.message.toLowerCase();
2259
+ return msg.includes("content security policy") || msg.includes("securityerror");
2260
+ }
2261
+ function normalizeWorkerPayload(raw, full) {
2262
+ if (!raw || typeof raw !== "object") return {};
2263
+ const data = raw;
2264
+ const user_agent = typeof data.user_agent === "string" ? data.user_agent : void 0;
2265
+ const platform = typeof data.platform === "string" ? data.platform : void 0;
2266
+ if (!full) return compact({ user_agent, platform });
2267
+ return compact({
2268
+ user_agent,
2269
+ platform,
2270
+ hardware_concurrency: typeof data.hardware_concurrency === "number" && Number.isFinite(data.hardware_concurrency) ? data.hardware_concurrency : void 0,
2271
+ device_memory: typeof data.device_memory === "number" && Number.isFinite(data.device_memory) ? data.device_memory : void 0,
2272
+ languages: Array.isArray(data.languages) ? data.languages.filter((item) => typeof item === "string") : void 0,
2273
+ timezone: typeof data.timezone === "string" ? data.timezone : void 0,
2274
+ unmasked_vendor: typeof data.unmasked_vendor === "string" ? data.unmasked_vendor : void 0,
2275
+ unmasked_renderer: typeof data.unmasked_renderer === "string" ? data.unmasked_renderer : void 0,
2276
+ gpu_unanswered: data.gpu_unanswered === true ? true : void 0
2277
+ });
2278
+ }
2279
+ var workerRealmSource = {
2280
+ id: SOURCE.workerRealm,
2281
+ stage: "collect",
2282
+ embeddedSafe: true,
2283
+ timeoutMs: WORKER_WAIT_MS + WORKER_WAIT_MARGIN_MS + 5,
2284
+ async run(ctx) {
2285
+ const w = requireWindow();
2286
+ const doc = attempt(() => w.document);
2287
+ if (sessionCspBlocked) {
2288
+ throw new BlockedSignal(sessionCspBlocked);
2289
+ }
2290
+ if (typeof Worker !== "function" || typeof Blob !== "function" || typeof URL === "undefined" || typeof URL.createObjectURL !== "function" || typeof URL.revokeObjectURL !== "function") {
2291
+ throw new UnsupportedSignal("no-worker");
2292
+ }
2293
+ const refusal = headMetaDisallowsBlobWorker(doc) ? "csp-meta" : "csp-blocked";
2294
+ const refused = () => {
2295
+ sessionCspBlocked = refusal;
2296
+ return new BlockedSignal(refusal);
2297
+ };
2298
+ const full = !detectEmbedding();
2299
+ const blobUrl = URL.createObjectURL(new Blob([workerScript(full)], { type: "text/javascript" }));
2300
+ let worker;
2301
+ let onCspViolation;
2302
+ try {
2303
+ try {
2304
+ worker = new Worker(blobUrl);
2305
+ } catch (error) {
2306
+ if (isCspSecurityError(error)) throw refused();
2307
+ throw error;
2308
+ }
2309
+ const activeWorker = worker;
2310
+ const raw = await new Promise((resolve, reject) => {
2311
+ let settled = false;
2312
+ const settle = (fn) => {
2313
+ if (settled) return;
2314
+ settled = true;
2315
+ clearTimeout(timer);
2316
+ ctx.signal?.removeEventListener("abort", onAbort);
2317
+ if (doc && onCspViolation) {
2318
+ doc.removeEventListener("securitypolicyviolation", onCspViolation);
2319
+ }
2320
+ fn();
2321
+ };
2322
+ const onAbort = () => settle(() => reject(ctx.signal?.reason ?? new TimedOutSignal("aborted")));
2323
+ let partial;
2324
+ const timer = setTimeout(() => {
2325
+ setTimeout(
2326
+ () => settle(
2327
+ () => partial ? resolve({ ...partial, gpu_unanswered: true }) : reject(new TimedOutSignal("worker-timeout"))
2328
+ ),
2329
+ 0
2330
+ );
2331
+ }, workerWaitMs(attempt(() => ctx.budgetRemainingMs()) ?? WORKER_WAIT_MS));
2332
+ ctx.signal?.addEventListener("abort", onAbort, { once: true });
2333
+ onCspViolation = (event) => {
2334
+ const spv = event;
2335
+ const directive = (spv.effectiveDirective || spv.violatedDirective || "").toLowerCase();
2336
+ const blockedUri = (spv.blockedURI || "").toLowerCase();
2337
+ if (blockedUri.startsWith("blob") || directive.startsWith("worker-src") || directive.startsWith("child-src") || directive.startsWith("default-src")) {
2338
+ settle(() => reject(refused()));
2339
+ }
2340
+ };
2341
+ doc?.addEventListener("securitypolicyviolation", onCspViolation);
2342
+ activeWorker.onmessage = (event) => {
2343
+ const data = event?.data;
2344
+ if (data && data.partial === true) {
2345
+ partial = data.values && typeof data.values === "object" ? data.values : {};
2346
+ return;
2347
+ }
2348
+ settle(() => resolve(event?.data));
2349
+ };
2350
+ activeWorker.onerror = (event) => {
2351
+ event?.preventDefault?.();
2352
+ const message = String(event?.message ?? "").toLowerCase();
2353
+ if (refusal === "csp-meta" || message.includes("content security policy") || message.includes("securityerror")) {
2354
+ settle(() => reject(refused()));
2355
+ return;
2356
+ }
2357
+ settle(() => reject(new BlockedSignal("worker-error")));
2358
+ };
2359
+ });
2360
+ return normalizeWorkerPayload(raw, full);
2361
+ } finally {
2362
+ if (doc && onCspViolation) {
2363
+ attempt(() => doc.removeEventListener("securitypolicyviolation", onCspViolation));
2364
+ }
2365
+ attempt(() => worker?.terminate());
2366
+ attempt(() => URL.revokeObjectURL(blobUrl));
2367
+ }
2368
+ }
2369
+ };
1782
2370
 
1783
2371
  // src/sources/index.ts
1784
2372
  function guarded(source) {
2373
+ const safeInEmbedded = own(source, "embeddedSafe") === true || EMBEDDED_SAFE_SOURCES.has(source.id);
1785
2374
  return {
1786
2375
  ...source,
1787
2376
  run: (ctx) => {
1788
- if (detectEmbedding()) throw new UnsupportedSignal("embedded");
2377
+ if (!safeInEmbedded && detectEmbedding()) throw new UnsupportedSignal("embedded");
1789
2378
  return source.run(ctx);
1790
2379
  }
1791
2380
  };
1792
2381
  }
1793
2382
  var allBrowserSources = [
1794
- // fast
2383
+ // Stage 1: prerequisite barrier (completes before shields & canvas run)
1795
2384
  engineSource,
2385
+ timingSource,
2386
+ // Stage 2: single-pass collect
1796
2387
  errorsSource,
1797
2388
  mathSource,
1798
2389
  navigatorSource,
1799
2390
  languagesSource,
1800
- pluginsSource,
1801
2391
  vendorSource,
2392
+ userAgentDataSource,
2393
+ workerRealmSource,
1802
2394
  screenSource,
1803
2395
  screenFrameSource,
1804
2396
  mediaQueriesSource,
@@ -1810,25 +2402,18 @@ var allBrowserSources = [
1810
2402
  timezoneSource,
1811
2403
  storageSource,
1812
2404
  storageQuotaSource,
2405
+ storageDurabilitySource,
1813
2406
  shieldsSource,
1814
- timingSource,
1815
2407
  permissionsSource,
1816
2408
  automationSource,
1817
2409
  webglSource,
2410
+ webglExtensionsSource,
1818
2411
  mediaDevicesSource,
1819
- // deferred
1820
2412
  canvasSource,
1821
- webglExtensionsSource,
1822
2413
  audioSource,
1823
2414
  audioLatencySource,
1824
2415
  fontsSource,
1825
- fontPreferencesSource,
1826
- batterySource,
1827
- speechSource,
1828
- sensorsSource,
1829
- userAgentDataSource,
1830
- domBlockersSource,
1831
- storageDurabilitySource
2416
+ fontPreferencesSource
1832
2417
  ];
1833
2418
  var browserSources = allBrowserSources.map(guarded);
1834
2419
  function load(options) {
@@ -1839,8 +2424,6 @@ function load(options) {
1839
2424
  platform: "web",
1840
2425
  sources: options.sources ?? browserSources,
1841
2426
  integrity: (report) => inspectIntegrity(report.sources),
1842
- // After the caller's options, so nothing passed to load() can turn
1843
- // detection off: there is no supported way to fingerprint in an app.
1844
2427
  embedding: () => detectEmbedding()
1845
2428
  })
1846
2429
  )