@fingerly/web-js 0.1.2 → 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
@@ -3,6 +3,60 @@
3
3
  var core = require('@fingerly/core');
4
4
 
5
5
  // src/index.ts
6
+
7
+ // src/embedding.ts
8
+ var THIRD_PARTY_IN_APP_BROWSERS = [
9
+ "fban/",
10
+ "fbav/",
11
+ "fb_iab",
12
+ "instagram",
13
+ "musical_ly",
14
+ "bytedancewebview",
15
+ "snapchat",
16
+ "linkedinapp",
17
+ "line/",
18
+ "micromessenger",
19
+ "pinterest/",
20
+ "gsa/"
21
+ ];
22
+ function pageEnvironment() {
23
+ const g = globalThis;
24
+ return {
25
+ ...typeof g.navigator?.userAgent === "string" ? { userAgent: g.navigator.userAgent } : {},
26
+ ...typeof g.location?.protocol === "string" ? { protocol: g.location.protocol } : {},
27
+ window: globalThis
28
+ };
29
+ }
30
+ function bridgeOf(win) {
31
+ try {
32
+ const capacitor = win["Capacitor"];
33
+ if (capacitor && typeof capacitor.isNativePlatform === "function" && capacitor.isNativePlatform() === true) {
34
+ return "capacitor";
35
+ }
36
+ if (win["cordova"] !== void 0 || win["_cordovaNative"] !== void 0) return "cordova";
37
+ if (win["ReactNativeWebView"] !== void 0) return "react-native-webview";
38
+ if (win["flutter_inappwebview"] !== void 0) return "flutter-webview";
39
+ } catch {
40
+ }
41
+ return void 0;
42
+ }
43
+ function userAgentEmbedding(userAgent) {
44
+ const ua = userAgent.toLowerCase();
45
+ if (ua === "") return void 0;
46
+ if (ua.includes("electron/")) return "electron";
47
+ if (THIRD_PARTY_IN_APP_BROWSERS.some((needle) => ua.includes(needle))) return void 0;
48
+ if (ua.includes("android") && ua.includes("; wv)")) return "android-webview";
49
+ const appleDevice = ["iphone", "ipad", "ipod", "macintosh"].some((device) => ua.includes(device));
50
+ if (appleDevice && ua.includes("applewebkit/") && !ua.includes("safari/")) return "apple-webview";
51
+ return void 0;
52
+ }
53
+ function detectEmbedding(environment = pageEnvironment()) {
54
+ const protocol = (environment.protocol ?? "").toLowerCase();
55
+ if (protocol !== "" && !["http:", "https:", "about:", "blob:"].includes(protocol)) return "app-scheme";
56
+ const bridge = environment.window ? bridgeOf(environment.window) : void 0;
57
+ if (bridge) return bridge;
58
+ return userAgentEmbedding(environment.userAgent ?? "");
59
+ }
6
60
  function compact(value) {
7
61
  const out = {};
8
62
  for (const [key, entry] of Object.entries(value)) {
@@ -34,8 +88,471 @@ function asBlockedIfRefused(error) {
34
88
  throw error;
35
89
  }
36
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
+
37
555
  // src/lies/descriptors.ts
38
- var NATIVE_PATTERN = /\{\s*\[native code\]\s*\}\s*$/;
39
556
  var INSTANCE_SHOULD_NOT_OWN = [
40
557
  ["navigator", "webdriver"],
41
558
  ["navigator", "userAgent"],
@@ -54,15 +571,52 @@ var INSTANCE_SHOULD_NOT_OWN = [
54
571
  ["screen", "height"],
55
572
  ["screen", "availWidth"],
56
573
  ["screen", "availHeight"],
57
- ["screen", "colorDepth"]
574
+ ["screen", "colorDepth"],
575
+ ["screen", "pixelDepth"],
576
+ ["screen", "orientation"]
58
577
  ];
59
- 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;
60
610
  const lies = [];
611
+ const holders = {
612
+ navigator: attempt(() => w.navigator),
613
+ screen: attempt(() => w.screen)
614
+ };
61
615
  for (const [holderName, property] of INSTANCE_SHOULD_NOT_OWN) {
62
- const holder = holderName === "navigator" ? w.navigator : w.screen;
616
+ const holder = holders[holderName];
63
617
  if (!holder) continue;
64
- const own = attempt(() => Object.getOwnPropertyDescriptor(holder, property));
65
- if (own) {
618
+ const own2 = attempt(() => INITIAL_GET_OWN_PROP_DESC(holder, property));
619
+ if (own2) {
66
620
  lies.push({
67
621
  id: `${holderName}.${property}`,
68
622
  kind: "descriptor",
@@ -70,118 +624,60 @@ function findRedefinedProperties(w) {
70
624
  });
71
625
  continue;
72
626
  }
73
- const proto = attempt(() => Object.getPrototypeOf(holder));
627
+ const proto = attempt(() => INITIAL_GET_PROTOTYPE_OF(holder));
74
628
  if (!proto) continue;
75
- const inherited = attempt(() => Object.getOwnPropertyDescriptor(proto, property));
76
- if (!inherited?.get) continue;
77
- const source = attempt(() => Function.prototype.toString.call(inherited.get));
78
- 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) {
633
+ lies.push({
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) {
79
644
  lies.push({
80
- id: `${holderName}.${property}.getter`,
645
+ id: getterId,
646
+ kind: "to-string-threw"
647
+ });
648
+ } else if (!isNativeFunctionSource(getter, stringified.source, property, true)) {
649
+ lies.push({
650
+ id: getterId,
81
651
  kind: "descriptor",
82
652
  detail: "getter-is-not-native"
83
653
  });
84
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
+ }
85
665
  }
86
- const navigatorProto = attempt(() => Object.getPrototypeOf(w.navigator));
87
- 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) {
88
670
  lies.push({ id: "navigator", kind: "prototype", detail: "not-Navigator.prototype" });
89
671
  }
90
- const screenProto = attempt(() => Object.getPrototypeOf(w.screen));
91
- 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) {
92
676
  lies.push({ id: "screen", kind: "prototype", detail: "not-Screen.prototype" });
93
677
  }
94
678
  return lies;
95
679
  }
96
680
 
97
- // src/lies/natives.ts
98
- var NATIVE_PATTERN2 = /\{\s*\[native code\]\s*\}\s*$/;
99
- var TARGETS = [
100
- ["Function.prototype.toString", () => Function.prototype.toString],
101
- ["Function.prototype.bind", () => Function.prototype.bind],
102
- ["Object.getOwnPropertyDescriptor", () => Object.getOwnPropertyDescriptor],
103
- ["Object.defineProperty", () => Object.defineProperty],
104
- ["Date.prototype.getTimezoneOffset", () => Date.prototype.getTimezoneOffset],
105
- ["Number.prototype.toFixed", () => Number.prototype.toFixed],
106
- ["Error.prototype.toString", () => Error.prototype.toString],
107
- ["Intl.DateTimeFormat", () => Intl?.DateTimeFormat],
108
- ["Navigator.prototype.javaEnabled", (w) => w.Navigator?.prototype?.javaEnabled],
109
- ["Permissions.prototype.query", (w) => w.Permissions?.prototype?.query],
110
- ["MediaDevices.prototype.enumerateDevices", (w) => w.MediaDevices?.prototype?.enumerateDevices],
111
- ["HTMLCanvasElement.prototype.toDataURL", (w) => w.HTMLCanvasElement?.prototype?.toDataURL],
112
- [
113
- "CanvasRenderingContext2D.prototype.getImageData",
114
- (w) => w.CanvasRenderingContext2D?.prototype?.getImageData
115
- ],
116
- [
117
- "WebGLRenderingContext.prototype.getParameter",
118
- (w) => w.WebGLRenderingContext?.prototype?.getParameter
119
- ],
120
- [
121
- "WebGLRenderingContext.prototype.getExtension",
122
- (w) => w.WebGLRenderingContext?.prototype?.getExtension
123
- ],
124
- ["AudioBuffer.prototype.getChannelData", (w) => w.AudioBuffer?.prototype?.getChannelData],
125
- ["Element.prototype.getBoundingClientRect", (w) => w.Element?.prototype?.getBoundingClientRect],
126
- ["Performance.prototype.now", (w) => w.Performance?.prototype?.now],
127
- ["Screen.prototype.constructor", (w) => w.Screen]
128
- ];
129
- function borrowToString() {
130
- const own = Function.prototype.toString;
131
- if (typeof document === "undefined" || !document.body) return { fn: own, clean: false };
132
- const frame = attempt(() => {
133
- const element = document.createElement("iframe");
134
- element.setAttribute("sandbox", "allow-same-origin");
135
- element.style.display = "none";
136
- document.body.appendChild(element);
137
- return element;
138
- });
139
- if (!frame) return { fn: own, clean: false };
140
- try {
141
- const borrowed = attempt(
142
- () => frame.contentWindow?.Function?.prototype?.toString
143
- );
144
- return borrowed ? { fn: borrowed, clean: true } : { fn: own, clean: false };
145
- } finally {
146
- frame.remove();
147
- }
148
- }
149
- function findPatchedNatives(w) {
150
- const patched = [];
151
- const lies = [];
152
- const { fn: toString, clean } = borrowToString();
153
- const stringify = (value) => attempt(() => toString.call(value));
154
- for (const [path, resolve] of TARGETS) {
155
- const target = attempt(() => resolve(w));
156
- if (target === void 0 || target === null) {
157
- lies.push({ id: path, kind: "missing" });
158
- continue;
159
- }
160
- if (typeof target !== "function") continue;
161
- const source = stringify(target);
162
- if (source === void 0) continue;
163
- if (!NATIVE_PATTERN2.test(source)) {
164
- patched.push(path);
165
- lies.push({ id: path, kind: "not-native" });
166
- }
167
- }
168
- if (clean) {
169
- const own = Function.prototype.toString;
170
- const viaBorrowed = stringify(own);
171
- if (viaBorrowed !== void 0 && !NATIVE_PATTERN2.test(viaBorrowed)) {
172
- if (!patched.includes("Function.prototype.toString")) {
173
- patched.push("Function.prototype.toString");
174
- }
175
- lies.push({
176
- id: "Function.prototype.toString",
177
- kind: "not-native",
178
- detail: "caught-via-fresh-realm"
179
- });
180
- }
181
- }
182
- return { patched, lies };
183
- }
184
-
185
681
  // src/lies/index.ts
186
682
  function inspectIntegrity(sources) {
187
683
  const w = windowOrNull();
@@ -190,7 +686,6 @@ function inspectIntegrity(sources) {
190
686
  schema: 1,
191
687
  budget_ms: 0,
192
688
  elapsed_ms: 0,
193
- tiers: [],
194
689
  sources,
195
690
  integrity: { patched_natives: [], lies: [], engine: {} }
196
691
  },
@@ -203,11 +698,24 @@ function inspectIntegrity(sources) {
203
698
  if (!w) {
204
699
  return { patched_natives: [], lies: [], engine: identity };
205
700
  }
206
- const natives = findPatchedNatives(w);
207
- 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
+ }
208
716
  return {
209
- patched_natives: natives.patched,
210
- lies: [...natives.lies, ...descriptors],
717
+ patched_natives: patched,
718
+ lies,
211
719
  engine: identity
212
720
  };
213
721
  }
@@ -249,8 +757,8 @@ async function render(ctx) {
249
757
  }
250
758
  var audioSource = {
251
759
  id: core.SOURCE.audio,
252
- tier: "deferred",
253
- timeoutMs: 500,
760
+ stage: "collect",
761
+ timeoutMs: 250,
254
762
  async run(ctx) {
255
763
  const first = await render(ctx);
256
764
  if (first === 0) throw new core.BlockedSignal("audio-silent");
@@ -264,7 +772,7 @@ var audioSource = {
264
772
  };
265
773
  var audioLatencySource = {
266
774
  id: core.SOURCE.audioLatency,
267
- tier: "deferred",
775
+ stage: "collect",
268
776
  timeoutMs: 200,
269
777
  run() {
270
778
  const w = globalThis;
@@ -284,7 +792,7 @@ var audioLatencySource = {
284
792
  };
285
793
  var hardwareSource = {
286
794
  id: core.SOURCE.hardware,
287
- tier: "fast",
795
+ stage: "collect",
288
796
  run() {
289
797
  if (typeof navigator === "undefined") throw new core.UnsupportedSignal("no-navigator");
290
798
  const nav = navigator;
@@ -296,7 +804,7 @@ var hardwareSource = {
296
804
  };
297
805
  var touchSource = {
298
806
  id: core.SOURCE.touch,
299
- tier: "fast",
807
+ stage: "collect",
300
808
  run() {
301
809
  const w = requireWindow();
302
810
  return compact({
@@ -308,58 +816,14 @@ var touchSource = {
308
816
  }),
309
817
  pointer_coarse: attempt(() => w.matchMedia?.("(pointer: coarse)").matches),
310
818
  any_hover: attempt(() => w.matchMedia?.("(any-hover: hover)").matches),
311
- // Presence only, and in the fast tier for that reason: the deferred
312
- // `sensors` source is what waits to see whether an event fires. This is
313
- // what the server's mobile-UA-with-no-motion-sensors rule reads.
314
819
  device_motion: attempt(() => "DeviceMotionEvent" in w),
315
820
  device_orientation: attempt(() => "DeviceOrientationEvent" in w)
316
821
  });
317
822
  }
318
823
  };
319
- var sensorsSource = {
320
- id: core.SOURCE.sensors,
321
- tier: "deferred",
322
- // 150ms, not the 250 this started at. A real accelerometer delivers
323
- // `devicemotion` at 60Hz, so anything past the first few frames is waiting
324
- // for an event that is not coming.
325
- timeoutMs: 150,
326
- async run(ctx) {
327
- const w = requireWindow();
328
- const hasMotion = "DeviceMotionEvent" in w;
329
- const hasOrientation = "DeviceOrientationEvent" in w;
330
- if (!hasMotion && !hasOrientation) {
331
- return compact({ device_motion: false, device_orientation: false });
332
- }
333
- if (typeof document !== "undefined" && document.visibilityState === "hidden") {
334
- return compact({
335
- device_motion: hasMotion,
336
- device_orientation: hasOrientation
337
- });
338
- }
339
- const observed = await new Promise((resolve) => {
340
- let settled = false;
341
- const finish = (value) => {
342
- if (settled) return;
343
- settled = true;
344
- w.removeEventListener("devicemotion", onMotion);
345
- clearTimeout(timer);
346
- resolve(value);
347
- };
348
- const onMotion = () => finish(true);
349
- const timer = setTimeout(() => finish(false), 100);
350
- ctx.signal.addEventListener("abort", () => finish(false), { once: true });
351
- w.addEventListener("devicemotion", onMotion, { once: true });
352
- });
353
- return compact({
354
- device_motion: hasMotion,
355
- device_orientation: hasOrientation,
356
- motion_observed: observed
357
- });
358
- }
359
- };
360
824
  var mediaDevicesSource = {
361
825
  id: core.SOURCE.mediaDevices,
362
- tier: "fast",
826
+ stage: "collect",
363
827
  timeoutMs: 120,
364
828
  async run() {
365
829
  if (typeof navigator === "undefined") throw new core.UnsupportedSignal("no-navigator");
@@ -377,7 +841,7 @@ var mediaDevicesSource = {
377
841
  };
378
842
  var networkSource = {
379
843
  id: core.SOURCE.network,
380
- tier: "fast",
844
+ stage: "collect",
381
845
  run() {
382
846
  const connection = navigator.connection;
383
847
  if (!connection) throw new core.UnsupportedSignal("no-network-information");
@@ -391,22 +855,16 @@ var networkSource = {
391
855
  };
392
856
  var intlSource = {
393
857
  id: core.SOURCE.intl,
394
- tier: "fast",
858
+ stage: "collect",
395
859
  run() {
396
860
  if (typeof Intl === "undefined") throw new core.UnsupportedSignal("no-intl");
397
861
  const resolved = attempt(() => new Intl.DateTimeFormat().resolvedOptions());
398
862
  return compact({
399
863
  timezone: resolved?.timeZone,
400
- // Kept alongside the zone name because resistFingerprinting reports UTC
401
- // for both, while an ordinary browser in London reports Europe/London
402
- // with the same zero offset in winter. The pair separates them.
403
864
  timezone_offset: attempt(() => (/* @__PURE__ */ new Date()).getTimezoneOffset()),
404
865
  locale: resolved?.locale,
405
866
  calendar: resolved?.calendar,
406
867
  numbering_system: resolved?.numberingSystem,
407
- // A fixed instant formatted in the visitor's locale. Catches differences
408
- // in the ICU data the browser was built with, which the locale name alone
409
- // does not.
410
868
  formatted: attempt(
411
869
  () => new Intl.DateTimeFormat(void 0, {
412
870
  dateStyle: "full",
@@ -418,7 +876,7 @@ var intlSource = {
418
876
  };
419
877
  var timezoneSource = {
420
878
  id: core.SOURCE.timezone,
421
- tier: "fast",
879
+ stage: "collect",
422
880
  run() {
423
881
  if (typeof Intl === "undefined") throw new core.UnsupportedSignal("no-intl");
424
882
  return compact({
@@ -427,59 +885,9 @@ var timezoneSource = {
427
885
  });
428
886
  }
429
887
  };
430
- var batterySource = {
431
- id: core.SOURCE.battery,
432
- tier: "deferred",
433
- timeoutMs: 250,
434
- async run() {
435
- if (typeof navigator === "undefined") throw new core.UnsupportedSignal("no-navigator");
436
- const getBattery = navigator.getBattery;
437
- if (typeof getBattery !== "function") throw new core.UnsupportedSignal("no-battery-api");
438
- const battery = await getBattery.call(navigator);
439
- const finiteOrNull = (value) => value === void 0 ? void 0 : Number.isFinite(value) ? value : null;
440
- return compact({
441
- charging: battery.charging,
442
- charging_time: finiteOrNull(battery.chargingTime),
443
- discharging_time: finiteOrNull(battery.dischargingTime),
444
- level: battery.level
445
- });
446
- }
447
- };
448
- var speechSource = {
449
- id: core.SOURCE.speech,
450
- tier: "deferred",
451
- timeoutMs: 250,
452
- async run(ctx) {
453
- if (typeof speechSynthesis === "undefined") throw new core.UnsupportedSignal("no-speech-synthesis");
454
- let voices = speechSynthesis.getVoices();
455
- if (voices.length === 0) {
456
- voices = await new Promise((resolve) => {
457
- const finish = () => {
458
- speechSynthesis.removeEventListener("voiceschanged", changed);
459
- ctx.signal.removeEventListener("abort", aborted);
460
- resolve(speechSynthesis.getVoices());
461
- };
462
- const changed = () => finish();
463
- const aborted = () => finish();
464
- speechSynthesis.addEventListener("voiceschanged", changed, { once: true });
465
- ctx.signal.addEventListener("abort", aborted, { once: true });
466
- setTimeout(finish, Math.min(100, ctx.budgetRemainingMs()));
467
- });
468
- }
469
- return {
470
- voices: voices.map((voice) => ({
471
- name: voice.name,
472
- language: voice.lang,
473
- local_service: voice.localService,
474
- default: voice.default,
475
- uri: voice.voiceURI
476
- }))
477
- };
478
- }
479
- };
480
888
  var screenSource = {
481
889
  id: core.SOURCE.screen,
482
- tier: "fast",
890
+ stage: "collect",
483
891
  run() {
484
892
  const w = requireWindow();
485
893
  const s = w.screen;
@@ -518,7 +926,7 @@ function readFrame(w) {
518
926
  }
519
927
  var screenFrameSource = {
520
928
  id: core.SOURCE.screenFrame,
521
- tier: "fast",
929
+ stage: "collect",
522
930
  run() {
523
931
  const w = requireWindow();
524
932
  const frame = readFrame(w);
@@ -541,7 +949,7 @@ function matchFirst(w, queries) {
541
949
  }
542
950
  var mediaQueriesSource = {
543
951
  id: core.SOURCE.mediaQueries,
544
- tier: "fast",
952
+ stage: "collect",
545
953
  run() {
546
954
  const w = requireWindow();
547
955
  if (typeof w.matchMedia !== "function") throw new core.UnsupportedSignal("no-match-media");
@@ -572,7 +980,7 @@ var mediaQueriesSource = {
572
980
  };
573
981
  var colorGamutSource = {
574
982
  id: core.SOURCE.colorGamut,
575
- tier: "fast",
983
+ stage: "collect",
576
984
  run() {
577
985
  const w = requireWindow();
578
986
  if (typeof w.matchMedia !== "function") throw new core.UnsupportedSignal("no-match-media");
@@ -586,10 +994,9 @@ var colorGamutSource = {
586
994
  }
587
995
  };
588
996
  var PAYLOAD_BYTES = 16384;
589
- var WRITES_PER_BLOCK = 15;
590
- var MAX_ROUNDS = 9;
591
- var BUDGET_RESERVE_MS = 250;
592
- var CAP_MS = 600;
997
+ var WRITES_PER_BLOCK = 4;
998
+ var MAX_ROUNDS = 3;
999
+ var CAP_MS = 60;
593
1000
  function openDatabase(name) {
594
1001
  return new Promise((resolve, reject) => {
595
1002
  const request = indexedDB.open(name, 1);
@@ -633,9 +1040,9 @@ function timeBlock(db, durability, payload) {
633
1040
  }
634
1041
  var storageDurabilitySource = {
635
1042
  id: core.SOURCE.storageDurability,
636
- tier: "deferred",
637
- // One round may overshoot the soft deadline; the slice has to cover that.
638
- timeoutMs: CAP_MS + 400,
1043
+ stage: "collect",
1044
+ optIn: "extended-incognito",
1045
+ timeoutMs: 80,
639
1046
  async run(ctx) {
640
1047
  requireWindow();
641
1048
  if (typeof indexedDB !== "object" || indexedDB === null) {
@@ -648,20 +1055,19 @@ var storageDurabilitySource = {
648
1055
  const payload = new Uint8Array(PAYLOAD_BYTES);
649
1056
  let db;
650
1057
  try {
1058
+ const started = performance.now();
1059
+ const deadline = started + Math.min(CAP_MS, Math.max(0, ctx.budgetRemainingMs()));
651
1060
  db = await openDatabase(name);
652
1061
  if (!durabilityHonored(db)) return { honored: false };
653
- await timeBlock(db, "relaxed", payload);
654
- await timeBlock(db, "strict", payload);
655
- const started = performance.now();
656
- const deadline = started + Math.min(CAP_MS, Math.max(0, ctx.budgetRemainingMs() - BUDGET_RESERVE_MS));
657
1062
  const ratios = [];
658
1063
  while (ratios.length < MAX_ROUNDS) {
659
- if (ctx.signal.aborted) break;
1064
+ if (ctx.signal.aborted || performance.now() >= deadline) break;
660
1065
  if (ratios.length > 0) {
661
1066
  const perRound = (performance.now() - started) / ratios.length;
662
1067
  if (performance.now() + perRound > deadline) break;
663
1068
  }
664
1069
  const relaxed = await timeBlock(db, "relaxed", payload);
1070
+ if (ctx.signal.aborted || performance.now() >= deadline) break;
665
1071
  const strict = await timeBlock(db, "strict", payload);
666
1072
  if (relaxed > 0) ratios.push(strict / relaxed);
667
1073
  else break;
@@ -682,90 +1088,6 @@ var storageDurabilitySource = {
682
1088
  }
683
1089
  }
684
1090
  };
685
- var FILTER_LISTS = [
686
- ["easylist", ".ad_300x250", ".textads"],
687
- ["easylist_germany", ".werbung1", ".werbeblock"],
688
- ["easylist_italy", ".pubbl", ".banner_pubblicita"],
689
- ["easylist_dutch", ".advertentie-container", ".reclame"],
690
- ["easyprivacy", ".trackingpixel", "#tracking-pixel"],
691
- ["fanboy_annoyances", "#newsletter-signup-modal", ".cookie-consent-banner"],
692
- ["fanboy_social", ".social-share-buttons", ".facebook-like-box"],
693
- ["adguard_base", "#adsense_widget", ".adsbygoogle-container"],
694
- ["adguard_annoyances", ".push-notification-prompt", "#app-install-banner"],
695
- ["listekr", "#ad_wrapper_top", ".ad_zone"],
696
- ["liste_fr", ".pub_300x250", "#pubfooter"],
697
- ["ro_list", ".reclama-mare", "#reclama"]
698
- ];
699
- var SETTLE_MS = 60;
700
- function nextPaint() {
701
- return new Promise((resolve) => {
702
- let settled = false;
703
- const done = () => {
704
- if (!settled) {
705
- settled = true;
706
- resolve();
707
- }
708
- };
709
- setTimeout(done, SETTLE_MS);
710
- if (typeof requestAnimationFrame === "function") requestAnimationFrame(() => setTimeout(done, 0));
711
- });
712
- }
713
- function hidden(element) {
714
- if (element.offsetParent === null) return true;
715
- if (element.offsetHeight === 0 || element.offsetWidth === 0) return true;
716
- const style = getComputedStyle(element);
717
- return style.display === "none" || style.visibility === "hidden";
718
- }
719
- function probe(document2, selector) {
720
- const element = document2.createElement("div");
721
- if (selector.startsWith("#")) element.id = selector.slice(1);
722
- else element.className = selector.slice(1);
723
- element.style.position = "absolute";
724
- element.style.top = "-9999px";
725
- element.style.left = "-9999px";
726
- element.style.width = "1px";
727
- element.style.height = "1px";
728
- return element;
729
- }
730
- var domBlockersSource = {
731
- id: core.SOURCE.domBlockers,
732
- // Deferred: it inserts elements, waits for a paint and reads back layout,
733
- // which is the most intrusive thing any source here does and has no business
734
- // competing with the fast tier for the budget.
735
- tier: "deferred",
736
- timeoutMs: 300,
737
- async run() {
738
- requireWindow();
739
- if (typeof document === "undefined" || !document.body) {
740
- throw new core.UnsupportedSignal("no-document-body");
741
- }
742
- const container = document.createElement("div");
743
- container.style.position = "absolute";
744
- container.style.top = "-9999px";
745
- container.style.left = "-9999px";
746
- container.style.width = "1px";
747
- container.style.height = "1px";
748
- const control = probe(document, ".fingerly-control-element");
749
- container.appendChild(control);
750
- const elements = FILTER_LISTS.map(([name, ...selectors]) => ({
751
- name,
752
- nodes: selectors.map((selector) => {
753
- const element = probe(document, selector);
754
- container.appendChild(element);
755
- return element;
756
- })
757
- }));
758
- document.body.appendChild(container);
759
- try {
760
- await nextPaint();
761
- if (hidden(control)) return {};
762
- const blocked = elements.filter(({ nodes }) => nodes.some(hidden)).map(({ name }) => name);
763
- return compact({ blocked, probed: FILTER_LISTS.length });
764
- } finally {
765
- container.remove();
766
- }
767
- }
768
- };
769
1091
  function toFixedErrorLength() {
770
1092
  return attempt(() => {
771
1093
  try {
@@ -820,9 +1142,44 @@ function claimedEngine(userAgent) {
820
1142
  if (/Safari\//.test(userAgent)) return "webkit";
821
1143
  return void 0;
822
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
+ }
823
1179
  var engineSource = {
824
1180
  id: core.SOURCE.engine,
825
- tier: "fast",
1181
+ stage: "prerequisite",
1182
+ embeddedSafe: true,
826
1183
  run() {
827
1184
  const toFixed = toFixedErrorLength();
828
1185
  const evalLen = evalLength();
@@ -836,9 +1193,10 @@ var engineSource = {
836
1193
  eval_length: evalLen,
837
1194
  stack_style: stack,
838
1195
  observed,
839
- // Compared on the server, where "we could not tell" and "they disagree"
840
- // are kept apart by which of the two is missing.
841
- 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")
842
1200
  });
843
1201
  }
844
1202
  };
@@ -868,28 +1226,21 @@ function identitiesHold() {
868
1226
  }
869
1227
  var mathSource = {
870
1228
  id: core.SOURCE.math,
871
- tier: "fast",
1229
+ stage: "collect",
1230
+ embeddedSafe: true,
872
1231
  timeoutMs: 50,
873
1232
  run() {
874
- const results = [];
875
1233
  let probed = 0;
876
1234
  const values = /* @__PURE__ */ new Map();
877
- for (const [name, probe2] of MATH_PROBES) {
878
- const value = attempt(probe2);
1235
+ for (const [name, probe] of MATH_PROBES) {
1236
+ const value = attempt(probe);
879
1237
  if (typeof value === "number" && Number.isFinite(value)) {
880
1238
  probed += 1;
881
1239
  values.set(name, value);
882
- results.push(`${name}:${value}`);
883
- } else {
884
- results.push(`${name}:`);
885
1240
  }
886
1241
  }
887
1242
  return compact({
888
- hash: core.hash64(results.join("|")),
889
1243
  probed,
890
- // The two the engines were measured to disagree about. See MathSignal
891
- // for the numbers; the other seventeen agreed to the last bit on the
892
- // machine they were measured on, which is why they are only in the hash.
893
1244
  atanh_half: values.get("atanh"),
894
1245
  expm1_1: values.get("expm1"),
895
1246
  identities_hold: attempt(identitiesHold)
@@ -907,26 +1258,26 @@ function thrownMessageLength(throwing) {
907
1258
  return void 0;
908
1259
  });
909
1260
  }
910
- function evalAllowed() {
911
- try {
912
- new Function("");
913
- return true;
914
- } catch {
915
- return false;
916
- }
1261
+ function regexpSyntaxError() {
1262
+ return new RegExp("(");
1263
+ }
1264
+ function redefineFrozen() {
1265
+ return Object.defineProperty(Object.freeze({ x: 1 }), "x", { value: 2 });
917
1266
  }
918
1267
  function observedFromErrors(errors) {
919
1268
  const votes = [];
920
- const own = errors.own_properties;
921
- if (own !== void 0) {
922
- if (own.includes("sourceURL")) votes.push("webkit", "webkit");
923
- else if (own.includes("lineNumber")) votes.push("gecko", "gecko");
924
- 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");
925
1274
  }
926
1275
  if (errors.null_property_length === 44) votes.push("chromium");
927
1276
  else if (errors.null_property_length === 33) votes.push("gecko");
928
- if (errors.syntax_length === 20) votes.push("chromium");
929
- 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");
930
1281
  if (votes.length === 0) return void 0;
931
1282
  const tally = /* @__PURE__ */ new Map();
932
1283
  for (const vote of votes) tally.set(vote, (tally.get(vote) ?? 0) + 1);
@@ -955,24 +1306,23 @@ function errorOwnProperties() {
955
1306
  }
956
1307
  var errorsSource = {
957
1308
  id: core.SOURCE.errors,
958
- tier: "fast",
1309
+ stage: "collect",
1310
+ embeddedSafe: true,
959
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.
960
1316
  run() {
961
- const compiles = evalAllowed();
962
1317
  const shapes = compact({
963
1318
  null_property_length: thrownMessageLength(() => null.x),
964
- // `new Function` rather than `eval`, because a page with a strict
965
- // Content-Security-Policy blocks both and this way the failure is one
966
- // probe reporting nothing rather than the source throwing.
967
- syntax_length: compiles ? thrownMessageLength(() => new Function("!")) : void 0,
968
1319
  json_parse_length: thrownMessageLength(() => JSON.parse("{")),
969
1320
  invalid_array_length: thrownMessageLength(() => {
970
1321
  const array = [];
971
1322
  array.length = -1;
972
1323
  }),
973
- const_assign_length: compiles ? thrownMessageLength(() => {
974
- new Function("const c = 1; c = 2")();
975
- }) : void 0,
1324
+ regexp_syntax_length: thrownMessageLength(regexpSyntaxError),
1325
+ redefine_length: thrownMessageLength(redefineFrozen),
976
1326
  own_properties: errorOwnProperties(),
977
1327
  capture_stack_trace: attempt(
978
1328
  () => typeof Error.captureStackTrace === "function"
@@ -984,10 +1334,18 @@ var errorsSource = {
984
1334
  };
985
1335
  var navigatorSource = {
986
1336
  id: core.SOURCE.navigator,
987
- tier: "fast",
1337
+ stage: "collect",
1338
+ embeddedSafe: true,
988
1339
  run() {
989
1340
  if (typeof navigator === "undefined") throw new core.UnsupportedSignal("no-navigator");
990
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
+ }
991
1349
  return compact({
992
1350
  user_agent: attempt(() => nav.userAgent),
993
1351
  platform: attempt(() => nav.platform),
@@ -1001,10 +1359,6 @@ var navigatorSource = {
1001
1359
  cookie_enabled: attempt(() => nav.cookieEnabled),
1002
1360
  pdf_viewer_enabled: attempt(() => nav.pdfViewerEnabled),
1003
1361
  do_not_track: attempt(() => nav.doNotTrack),
1004
- // The count rather than the list. The names are long, largely constant,
1005
- // and the only thing any detector reads is whether there are none - a
1006
- // desktop Chromium with zero plugins has no built-in PDF viewer, which
1007
- // means it was built headless.
1008
1362
  plugin_count: attempt(() => nav.plugins?.length),
1009
1363
  mime_type_count: attempt(() => nav.mimeTypes?.length),
1010
1364
  language: attempt(() => nav.language),
@@ -1014,7 +1368,7 @@ var navigatorSource = {
1014
1368
  };
1015
1369
  var languagesSource = {
1016
1370
  id: core.SOURCE.languages,
1017
- tier: "fast",
1371
+ stage: "collect",
1018
1372
  run() {
1019
1373
  if (typeof navigator === "undefined") throw new core.UnsupportedSignal("no-navigator");
1020
1374
  return compact({
@@ -1025,37 +1379,16 @@ var languagesSource = {
1025
1379
  };
1026
1380
  var vendorSource = {
1027
1381
  id: core.SOURCE.vendor,
1028
- tier: "fast",
1382
+ stage: "collect",
1029
1383
  run() {
1030
1384
  if (typeof navigator === "undefined") throw new core.UnsupportedSignal("no-navigator");
1031
1385
  return compact({ vendor: attempt(() => navigator.vendor) });
1032
1386
  }
1033
1387
  };
1034
- var pluginsSource = {
1035
- id: core.SOURCE.plugins,
1036
- tier: "fast",
1037
- run() {
1038
- if (typeof navigator === "undefined") throw new core.UnsupportedSignal("no-navigator");
1039
- const plugins = navigator.plugins;
1040
- if (!plugins) throw new core.UnsupportedSignal("no-plugins");
1041
- return {
1042
- plugins: Array.from(plugins, (plugin) => ({
1043
- name: plugin.name,
1044
- filename: plugin.filename,
1045
- description: plugin.description,
1046
- mime_types: Array.from(plugin, (mime) => ({
1047
- type: mime.type,
1048
- suffixes: mime.suffixes,
1049
- description: mime.description
1050
- }))
1051
- }))
1052
- };
1053
- }
1054
- };
1055
1388
  var userAgentDataSource = {
1056
1389
  id: core.SOURCE.userAgentData,
1057
- tier: "deferred",
1058
- timeoutMs: 200,
1390
+ stage: "collect",
1391
+ timeoutMs: 150,
1059
1392
  async run() {
1060
1393
  if (typeof navigator === "undefined") throw new core.UnsupportedSignal("no-navigator");
1061
1394
  const data = navigator.userAgentData;
@@ -1066,208 +1399,92 @@ var userAgentDataSource = {
1066
1399
  platform: data.platform
1067
1400
  });
1068
1401
  if (typeof data.getHighEntropyValues !== "function") return low;
1069
- const high = await data.getHighEntropyValues([
1070
- "architecture",
1071
- "bitness",
1072
- "model",
1073
- "platformVersion",
1074
- // Not uaFullVersion: deprecated in the client hints spec, and
1075
- // fullVersionList already carries the same version per brand.
1076
- "fullVersionList",
1077
- "wow64"
1078
- ]);
1079
- return { ...low, ...high };
1402
+ const high = await data.getHighEntropyValues(["architecture"]);
1403
+ const architecture = attempt(() => high.architecture);
1404
+ return typeof architecture === "string" ? { ...low, architecture } : low;
1080
1405
  }
1081
1406
  };
1082
- function makeCanvas(width, height) {
1083
- const canvas = document.createElement("canvas");
1084
- canvas.width = width;
1085
- canvas.height = height;
1086
- const context = canvas.getContext("2d");
1087
- if (!context) throw new core.UnsupportedSignal("no-2d-context");
1088
- 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;
1089
1413
  }
1090
- function renderGeometry() {
1091
- const [canvas, ctx] = makeCanvas(240, 60);
1092
- ctx.globalCompositeOperation = "multiply";
1093
- for (const [colour, x, y] of [
1094
- ["#f2f", 40, 40],
1095
- ["#2ff", 80, 40],
1096
- ["#ff2", 60, 80]
1097
- ]) {
1098
- ctx.fillStyle = colour;
1099
- ctx.beginPath();
1100
- ctx.arc(x, y, 40, 0, Math.PI * 2, true);
1101
- ctx.closePath();
1102
- ctx.fill();
1103
- }
1104
- ctx.fillStyle = "#f9c";
1105
- ctx.arc(100, 50, 50, 0, Math.PI * 2, true);
1106
- ctx.arc(100, 50, 20, 0, Math.PI * 2, true);
1107
- ctx.fill("evenodd");
1108
- return canvas.toDataURL();
1109
- }
1110
- function renderText() {
1111
- const [canvas, ctx] = makeCanvas(300, 60);
1112
- ctx.textBaseline = "alphabetic";
1113
- ctx.fillStyle = "#f60";
1114
- ctx.fillRect(100, 1, 62, 20);
1115
- ctx.fillStyle = "#069";
1116
- ctx.font = '11pt "Times New Roman"';
1117
- ctx.fillText("Fingerly <canvas> 1.0 \u{1F512}\u0416\u4E2D", 2, 15);
1118
- ctx.font = "18pt Arial";
1119
- ctx.fillStyle = "rgba(102, 204, 0, 0.7)";
1120
- ctx.fillText("Fingerly <canvas> 1.0", 4, 45);
1121
- return canvas.toDataURL();
1122
- }
1123
- function supportsWinding() {
1124
- const [, ctx] = makeCanvas(1, 1);
1125
- ctx.rect(0, 0, 10, 10);
1126
- ctx.rect(2, 2, 6, 6);
1127
- return ctx.isPointInPath(5, 5, "evenodd") === false;
1128
- }
1129
- function resistFingerprintingActive(ctx) {
1130
- const timing = ctx.completed(core.SOURCE.timing);
1131
- if (timing?.status !== "ok") return false;
1132
- const resolution = timing.value?.now_resolution;
1133
- return typeof resolution === "number" && resolution >= 16;
1134
- }
1135
- var canvasSource = {
1136
- id: core.SOURCE.canvas,
1137
- tier: "deferred",
1138
- timeoutMs: 400,
1139
- run(ctx) {
1140
- requireWindow();
1141
- if (typeof document === "undefined") throw new core.UnsupportedSignal("no-document");
1142
- if (resistFingerprintingActive(ctx)) {
1143
- throw new core.BlockedSignal("rfp-canvas-prompt-avoided");
1144
- }
1145
- try {
1146
- const geometryFirst = renderGeometry();
1147
- const geometrySecond = renderGeometry();
1148
- const textFirst = renderText();
1149
- const textSecond = renderText();
1150
- const unstable = geometryFirst !== geometrySecond || textFirst !== textSecond;
1151
- return compact({
1152
- geometry: core.hash64(geometryFirst),
1153
- text: core.hash64(textFirst),
1154
- winding: attempt(supportsWinding),
1155
- unstable
1156
- });
1157
- } catch (error) {
1158
- asBlockedIfRefused(error);
1159
- }
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();
1160
1421
  }
1161
- };
1162
- function webglContext() {
1163
- if (typeof document === "undefined") throw new core.UnsupportedSignal("no-document");
1164
- const canvas = document.createElement("canvas");
1165
- const gl = canvas.getContext("webgl") ?? canvas.getContext("experimental-webgl");
1166
- if (!gl) throw new core.UnsupportedSignal("no-webgl-context");
1167
- return gl;
1168
- }
1169
- var webglSource = {
1170
- id: core.SOURCE.webgl,
1171
- // Renderer and GPU strings are hard identity components, and context setup
1172
- // is synchronous; keep them in the authoritative initial report.
1173
- tier: "fast",
1174
- timeoutMs: 400,
1175
- run() {
1176
- const gl = webglContext();
1177
- const debug = attempt(() => gl.getExtension("WEBGL_debug_renderer_info"));
1178
- const parameters = {};
1179
- for (const name of [
1180
- "MAX_TEXTURE_SIZE",
1181
- "MAX_VIEWPORT_DIMS",
1182
- "MAX_VERTEX_ATTRIBS",
1183
- "MAX_VARYING_VECTORS",
1184
- "MAX_COMBINED_TEXTURE_IMAGE_UNITS",
1185
- "MAX_CUBE_MAP_TEXTURE_SIZE",
1186
- "MAX_FRAGMENT_UNIFORM_VECTORS",
1187
- "MAX_RENDERBUFFER_SIZE",
1188
- "MAX_TEXTURE_IMAGE_UNITS",
1189
- "MAX_VERTEX_TEXTURE_IMAGE_UNITS",
1190
- "MAX_VERTEX_UNIFORM_VECTORS",
1191
- "ALIASED_LINE_WIDTH_RANGE",
1192
- "ALIASED_POINT_SIZE_RANGE",
1193
- "RED_BITS",
1194
- "GREEN_BITS",
1195
- "BLUE_BITS",
1196
- "ALPHA_BITS",
1197
- "DEPTH_BITS",
1198
- "STENCIL_BITS"
1199
- ]) {
1200
- const constant = gl[name];
1201
- if (typeof constant !== "number") continue;
1202
- const value = attempt(() => gl.getParameter(constant));
1203
- if (value !== void 0 && value !== null) {
1204
- parameters[name] = ArrayBuffer.isView(value) ? Array.from(value) : value;
1205
- }
1206
- }
1207
- const precisions = [];
1208
- for (const shader of [gl.VERTEX_SHADER, gl.FRAGMENT_SHADER]) {
1209
- for (const precision of [gl.LOW_FLOAT, gl.MEDIUM_FLOAT, gl.HIGH_FLOAT]) {
1210
- const format = attempt(() => gl.getShaderPrecisionFormat(shader, precision));
1211
- if (format) precisions.push(format.rangeMin, format.rangeMax, format.precision);
1212
- }
1213
- }
1214
- return compact({
1215
- vendor: attempt(() => gl.getParameter(gl.VENDOR)),
1216
- renderer: attempt(() => gl.getParameter(gl.RENDERER)),
1217
- unmasked_vendor: debug ? attempt(() => gl.getParameter(debug.UNMASKED_VENDOR_WEBGL)) : void 0,
1218
- unmasked_renderer: debug ? attempt(() => gl.getParameter(debug.UNMASKED_RENDERER_WEBGL)) : void 0,
1219
- version: attempt(() => gl.getParameter(gl.VERSION)),
1220
- shading_language_version: attempt(
1221
- () => gl.getParameter(gl.SHADING_LANGUAGE_VERSION)
1222
- ),
1223
- max_texture_size: attempt(() => gl.getParameter(gl.MAX_TEXTURE_SIZE)),
1224
- max_render_buffer_size: attempt(() => gl.getParameter(gl.MAX_RENDERBUFFER_SIZE)),
1225
- // Hashed rather than sent whole: twenty parameters is a kilobyte of JSON
1226
- // that no detector reads field by field, and the report has a budget.
1227
- parameters_hash: Object.keys(parameters).length > 0 ? core.hash64(JSON.stringify(parameters)) : void 0,
1228
- shader_precision_hash: precisions.length > 0 ? core.hash64(precisions.join(",")) : void 0
1229
- });
1422
+ const delta = end - start;
1423
+ if (delta === 0) {
1424
+ return { resolution: CLAMPED_STALL_RESOLUTION_MS, rfpBlocked: true };
1230
1425
  }
1231
- };
1232
- var webglExtensionsSource = {
1233
- id: core.SOURCE.webglExtensions,
1234
- tier: "deferred",
1235
- timeoutMs: 200,
1236
- run() {
1237
- const gl = webglContext();
1238
- const extensions = gl.getSupportedExtensions();
1239
- if (!extensions) throw new core.BlockedSignal("extensions-withheld");
1240
- 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
+ };
1241
1431
  }
1242
- };
1243
- function clockResolution(now) {
1244
- const deltas = [];
1245
- const deadline = Date.now() + 12;
1246
- while (deltas.length < 25 && Date.now() < deadline) {
1247
- const start = now();
1248
- let end = now();
1249
- let guard = 0;
1250
- while (end === start && guard++ < 1e5 && Date.now() < deadline) end = now();
1251
- 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;
1252
1449
  }
1253
- if (deltas.length === 0) {
1254
- 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;
1255
1456
  }
1256
- return Math.round(Math.min(...deltas) * 1e6) / 1e6;
1457
+ return false;
1257
1458
  }
1258
1459
  var timingSource = {
1259
1460
  id: core.SOURCE.timing,
1260
- tier: "fast",
1261
- timeoutMs: 150,
1262
- run() {
1461
+ stage: "prerequisite",
1462
+ timeoutMs: 50,
1463
+ run(ctx) {
1263
1464
  const w = requireWindow();
1264
1465
  const perf = w.performance;
1265
1466
  if (typeof perf?.now !== "function") {
1266
- 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
+ });
1267
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
+ });
1481
+ }
1482
+ const probed = probeGeckoRfp(() => perf.now());
1483
+ ctx?.shared?.set(RFP_SHARED_KEY, probed.rfpBlocked);
1268
1484
  return compact({
1269
1485
  has_performance: true,
1270
- now_resolution: clockResolution(() => perf.now())
1486
+ now_resolution: probed.resolution,
1487
+ rfp_canvas_blocked: probed.rfpBlocked
1271
1488
  });
1272
1489
  }
1273
1490
  };
@@ -1287,8 +1504,8 @@ function permissionStatus(w, name) {
1287
1504
  }
1288
1505
  var permissionsSource = {
1289
1506
  id: core.SOURCE.permissions,
1290
- tier: "fast",
1291
- timeoutMs: 200,
1507
+ stage: "collect",
1508
+ timeoutMs: 150,
1292
1509
  async run() {
1293
1510
  const w = requireWindow();
1294
1511
  if (!w.navigator.permissions?.query) throw new core.UnsupportedSignal("no-permissions-api");
@@ -1300,7 +1517,9 @@ var permissionsSource = {
1300
1517
  }
1301
1518
  };
1302
1519
  const notification = await query("notifications");
1303
- const legacy = attempt(() => w.Notification?.permission);
1520
+ const legacy = attempt(
1521
+ () => w.Notification?.permission
1522
+ );
1304
1523
  return compact({
1305
1524
  notification,
1306
1525
  notification_legacy: legacy,
@@ -1331,23 +1550,45 @@ var AUTOMATION_GLOBALS = [
1331
1550
  "domAutomationController",
1332
1551
  "__lastWatirAlert",
1333
1552
  "__playwright",
1553
+ "__playwright__binding__",
1554
+ "__pwInitScripts",
1334
1555
  "__puppeteer",
1335
1556
  "__pw_manual"
1336
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
+ }
1337
1578
  var automationSource = {
1338
1579
  id: core.SOURCE.automation,
1339
- tier: "fast",
1580
+ stage: "collect",
1581
+ embeddedSafe: true,
1340
1582
  run() {
1341
1583
  const w = requireWindow();
1342
- const present = AUTOMATION_GLOBALS.filter((name) => attempt(() => name in w) === true);
1343
- const cdp = attempt(
1344
- () => 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
1345
1586
  );
1587
+ const cdp = collectCdcMarkers(w);
1346
1588
  return compact({
1347
1589
  webdriver: attempt(() => navigator.webdriver),
1348
- cdp_artifacts: cdp && cdp.length > 0 ? cdp : void 0,
1590
+ cdp_artifacts: cdp.length > 0 ? cdp : void 0,
1349
1591
  distinctive_properties: present.length > 0 ? [...present] : void 0,
1350
- chrome_object: attempt(() => "chrome" in w),
1351
1592
  window_external: attempt(() => {
1352
1593
  const external = w.external;
1353
1594
  return external ? String(external) : void 0;
@@ -1355,38 +1596,220 @@ var automationSource = {
1355
1596
  });
1356
1597
  }
1357
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
+ };
1358
1779
  var VENDOR_API_MS = 50;
1359
1780
  var TIMED_OUT = /* @__PURE__ */ Symbol("timed-out");
1360
1781
  async function askBrave(nav) {
1361
- 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";
1362
1786
  try {
1363
1787
  const answer = await Promise.race([
1364
- nav.brave.isBrave(),
1788
+ isBrave.call(brave),
1365
1789
  new Promise((resolve) => setTimeout(() => resolve(TIMED_OUT), VENDOR_API_MS))
1366
1790
  ]);
1367
- return answer === TIMED_OUT ? void 0 : answer === true;
1791
+ if (answer === TIMED_OUT) return "timeout";
1792
+ return answer === true ? "true" : "false";
1368
1793
  } catch {
1369
- return void 0;
1794
+ return "threw";
1370
1795
  }
1371
1796
  }
1372
- function claimsBrave(nav) {
1373
- const brands = nav.userAgentData?.brands;
1797
+ function brandsOf(nav) {
1798
+ const brands = attempt(() => nav.userAgentData?.brands);
1374
1799
  if (!Array.isArray(brands)) return void 0;
1375
- return brands.some((entry) => entry?.brand === "Brave");
1800
+ return brands.map((entry) => attempt(() => entry?.brand)).filter((brand) => typeof brand === "string");
1376
1801
  }
1377
1802
  var CANARY_COLOURS = [
1378
1803
  [30, 60, 90],
1379
1804
  [210, 180, 140]
1380
1805
  ];
1381
1806
  var CANARY_SIZE = 8;
1382
- function canvasNoise() {
1807
+ function readCanary(ctx) {
1383
1808
  if (typeof document === "undefined") return void 0;
1384
1809
  try {
1385
- const canvas = document.createElement("canvas");
1386
- canvas.width = CANARY_SIZE;
1387
- canvas.height = CANARY_SIZE;
1388
- const context = canvas.getContext("2d", { willReadFrequently: true });
1389
- if (!context) return void 0;
1810
+ const pair = acquireCanvas2D(ctx, CANARY_SIZE, CANARY_SIZE);
1811
+ if (!pair) return void 0;
1812
+ const [, context] = pair;
1390
1813
  for (let y = 0; y < CANARY_SIZE; y++) {
1391
1814
  for (let x = 0; x < CANARY_SIZE; x++) {
1392
1815
  const [r, g, b] = CANARY_COLOURS[(x + y) % 2];
@@ -1395,31 +1818,51 @@ function canvasNoise() {
1395
1818
  }
1396
1819
  }
1397
1820
  const pixels = context.getImageData(0, 0, CANARY_SIZE, CANARY_SIZE).data;
1398
- 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++) {
1399
1825
  const x = index % CANARY_SIZE;
1400
1826
  const y = Math.floor(index / CANARY_SIZE);
1401
1827
  const [r, g, b] = CANARY_COLOURS[(x + y) % 2];
1402
1828
  const at = index * 4;
1403
- if (pixels[at] !== r || pixels[at + 1] !== g || pixels[at + 2] !== b || pixels[at + 3] !== 255) {
1404
- return true;
1405
- }
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;
1406
1838
  }
1407
- return false;
1839
+ return { pixels: total, mismatched, maxDelta };
1408
1840
  } catch {
1409
1841
  return void 0;
1410
1842
  }
1411
1843
  }
1412
1844
  var shieldsSource = {
1413
1845
  id: core.SOURCE.shields,
1414
- tier: "fast",
1846
+ stage: "collect",
1415
1847
  timeoutMs: 100,
1416
- async run() {
1848
+ async run(ctx) {
1849
+ if (isRfpCanvasBlocked(ctx)) {
1850
+ throw new core.BlockedSignal("rfp-canvas-prompt-avoided");
1851
+ }
1417
1852
  if (typeof navigator === "undefined") throw new core.UnsupportedSignal("no-navigator");
1418
1853
  const nav = navigator;
1854
+ const braveApi = await askBrave(nav);
1855
+ const brands = brandsOf(nav);
1856
+ const canary = readCanary(ctx);
1419
1857
  return compact({
1420
- brave: await askBrave(nav),
1421
- brave_claimed: claimsBrave(nav),
1422
- 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
1423
1866
  });
1424
1867
  }
1425
1868
  };
@@ -1489,7 +1932,7 @@ function serviceWorkerAvailable() {
1489
1932
  }
1490
1933
  var storageSource = {
1491
1934
  id: core.SOURCE.storage,
1492
- tier: "fast",
1935
+ stage: "collect",
1493
1936
  timeoutMs: 250,
1494
1937
  async run() {
1495
1938
  requireWindow();
@@ -1532,7 +1975,7 @@ var storageSource = {
1532
1975
  };
1533
1976
  var storageQuotaSource = {
1534
1977
  id: core.SOURCE.storageQuota,
1535
- tier: "fast",
1978
+ stage: "collect",
1536
1979
  run() {
1537
1980
  requireWindow();
1538
1981
  if (typeof document === "undefined") throw new core.UnsupportedSignal("no-document");
@@ -1641,10 +2084,10 @@ var CANDIDATES = [
1641
2084
  ];
1642
2085
  var fontsSource = {
1643
2086
  id: core.SOURCE.fonts,
1644
- tier: "deferred",
2087
+ stage: "collect",
1645
2088
  // Generous: this measures ~300 spans, and forcing layout on a busy page is
1646
2089
  // genuinely slow. Still bounded, which is the part that matters.
1647
- timeoutMs: 700,
2090
+ timeoutMs: 250,
1648
2091
  run() {
1649
2092
  if (typeof document === "undefined") throw new core.UnsupportedSignal("no-document");
1650
2093
  const holder = document.createElement("div");
@@ -1689,7 +2132,7 @@ var fontsSource = {
1689
2132
  };
1690
2133
  var fontPreferencesSource = {
1691
2134
  id: core.SOURCE.fontPreferences,
1692
- tier: "deferred",
2135
+ stage: "collect",
1693
2136
  timeoutMs: 250,
1694
2137
  run() {
1695
2138
  if (typeof document === "undefined" || !document.body) {
@@ -1726,17 +2169,229 @@ var fontPreferencesSource = {
1726
2169
  }
1727
2170
  }
1728
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
+ };
1729
2371
 
1730
2372
  // src/sources/index.ts
1731
- var browserSources = [
1732
- // fast
2373
+ function guarded(source) {
2374
+ const safeInEmbedded = core.own(source, "embeddedSafe") === true || core.EMBEDDED_SAFE_SOURCES.has(source.id);
2375
+ return {
2376
+ ...source,
2377
+ run: (ctx) => {
2378
+ if (!safeInEmbedded && detectEmbedding()) throw new core.UnsupportedSignal("embedded");
2379
+ return source.run(ctx);
2380
+ }
2381
+ };
2382
+ }
2383
+ var allBrowserSources = [
2384
+ // Stage 1: prerequisite barrier (completes before shields & canvas run)
1733
2385
  engineSource,
2386
+ timingSource,
2387
+ // Stage 2: single-pass collect
1734
2388
  errorsSource,
1735
2389
  mathSource,
1736
2390
  navigatorSource,
1737
2391
  languagesSource,
1738
- pluginsSource,
1739
2392
  vendorSource,
2393
+ userAgentDataSource,
2394
+ workerRealmSource,
1740
2395
  screenSource,
1741
2396
  screenFrameSource,
1742
2397
  mediaQueriesSource,
@@ -1748,26 +2403,20 @@ var browserSources = [
1748
2403
  timezoneSource,
1749
2404
  storageSource,
1750
2405
  storageQuotaSource,
2406
+ storageDurabilitySource,
1751
2407
  shieldsSource,
1752
- timingSource,
1753
2408
  permissionsSource,
1754
2409
  automationSource,
1755
2410
  webglSource,
2411
+ webglExtensionsSource,
1756
2412
  mediaDevicesSource,
1757
- // deferred
1758
2413
  canvasSource,
1759
- webglExtensionsSource,
1760
2414
  audioSource,
1761
2415
  audioLatencySource,
1762
2416
  fontsSource,
1763
- fontPreferencesSource,
1764
- batterySource,
1765
- speechSource,
1766
- sensorsSource,
1767
- userAgentDataSource,
1768
- domBlockersSource,
1769
- storageDurabilitySource
2417
+ fontPreferencesSource
1770
2418
  ];
2419
+ var browserSources = allBrowserSources.map(guarded);
1771
2420
  function load(options) {
1772
2421
  return new Promise(
1773
2422
  (resolve) => resolve(
@@ -1775,7 +2424,8 @@ function load(options) {
1775
2424
  ...options,
1776
2425
  platform: "web",
1777
2426
  sources: options.sources ?? browserSources,
1778
- integrity: (report) => inspectIntegrity(report.sources)
2427
+ integrity: (report) => inspectIntegrity(report.sources),
2428
+ embedding: () => detectEmbedding()
1779
2429
  })
1780
2430
  )
1781
2431
  );
@@ -1802,5 +2452,6 @@ Object.defineProperty(exports, "isSuspiciousLevel", {
1802
2452
  get: function () { return core.isSuspiciousLevel; }
1803
2453
  });
1804
2454
  exports.browserSources = browserSources;
2455
+ exports.detectEmbedding = detectEmbedding;
1805
2456
  exports.inspectIntegrity = inspectIntegrity;
1806
2457
  exports.load = load;