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