1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
((globalThis) => {
const ops = Deno && Deno.core && Deno.core.ops;
// -- Per-page secure-context gating (Phase 7) --------------------
// The V8 snapshot bootstraps with is_secure_context=true so all
// [SecureContext]-only Web Platform APIs are baked in. On insecure
// pages (data:/http:/about:blank) we strip them here to match real
// Chrome.
try {
const _ops = Deno && Deno.core && Deno.core.ops;
const _isSecure = _ops && _ops.op_is_secure_context && _ops.op_is_secure_context();
if (!_isSecure) {
// Methods + globals registered as values in the snapshot.
// Navigator getters (mediaDevices, clipboard, ...) gate
// themselves lazily so they don't need stripping.
try { delete globalThis.Navigator.prototype.getBattery; } catch (_e) {}
for (const k of ['caches', 'cookieStore', 'IdleDetector', 'EyeDropper', 'WebTransport']) {
try { delete globalThis[k]; } catch (_e) {}
}
// Phase 7 — also strip the constructor *interfaces* for the
// [SecureContext] APIs. Real Chrome 147 hides these from
// `Object.getOwnPropertyNames(window)` on insecure pages.
// Some scripts hash the global namespace.
// Also: ApplePaySession, SharedArrayBuffer, webkitAudioContext,
// DedicatedWorkerGlobalScope, WorkerGlobalScope, CSSPseudoElement
// are absent from Chrome 147's globalThis on insecure pages —
// verified against a real browser.
for (const k of [
"SharedArrayBuffer", "webkitAudioContext",
"DedicatedWorkerGlobalScope", "WorkerGlobalScope",
"CSSPseudoElement",
"ApplePaySession", "AuthenticatorAssertionResponse",
"AuthenticatorAttestationResponse", "AuthenticatorResponse",
"BatteryManager", "Bluetooth", "CacheStorage", "CookieStore",
"Credential", "CredentialsContainer", "DevicePosture",
"FederatedCredential", "FileSystemDirectoryHandle",
"FileSystemFileHandle", "FileSystemHandle",
"FileSystemWritableFileStream", "IdentityCredential",
"IdentityProvider", "Keyboard", "KeyboardLayoutMap",
"MediaDevices", "PasswordCredential", "PaymentRequest",
"Presentation", "PresentationConnection",
"PublicKeyCredential", "ServiceWorker",
"ServiceWorkerContainer", "StorageManager", "SubtleCrypto",
"VirtualKeyboard", "XRSession", "XRSystem",
// Generic Sensor API — also [SecureContext]
"Sensor", "Accelerometer", "AbsoluteOrientationSensor",
"GravitySensor", "Gyroscope", "LinearAccelerationSensor",
"Magnetometer", "OrientationSensor",
"RelativeOrientationSensor",
]) {
try { delete globalThis[k]; } catch (_e) {}
}
// crypto.subtle + crypto.randomUUID are [SecureContext]. They
// come from deno_core's crypto extension and are non-configurable
// own properties. `delete` fails — replace `globalThis.crypto`
// with a Proxy that hides those two keys.
if (globalThis.crypto) {
const _origCrypto = globalThis.crypto;
const _maskedCrypto = new Proxy(_origCrypto, {
get(target, prop, receiver) {
if (prop === 'subtle' || prop === 'randomUUID') return undefined;
const v = Reflect.get(target, prop, receiver);
return typeof v === 'function' ? v.bind(target) : v;
},
has(target, prop) {
if (prop === 'subtle' || prop === 'randomUUID') return false;
return Reflect.has(target, prop);
},
ownKeys(target) {
return Reflect.ownKeys(target).filter(
(k) => k !== 'subtle' && k !== 'randomUUID',
);
},
getOwnPropertyDescriptor(target, prop) {
if (prop === 'subtle' || prop === 'randomUUID') return undefined;
return Reflect.getOwnPropertyDescriptor(target, prop);
},
});
try {
Object.defineProperty(globalThis, 'crypto', {
value: _maskedCrypto, configurable: true, enumerable: true, writable: true,
});
} catch (_e) {}
}
}
} catch (_e) { /* secure-context cleanup is best-effort */ }
// -- Profile-conditional installs --------------------------------
// These run AFTER the V8 startup snapshot is restored, so the
// stealth profile is loaded and op-based reads return real values.
// (Snapshot-time bootstraps see profile=None and would mis-gate.)
try {
const _hasProfile = ops && ops.op_has_stealth_profile && ops.op_has_stealth_profile();
const _osName = (_hasProfile && ops.op_get_profile_value)
? (ops.op_get_profile_value("os_name") || "Linux")
: "Linux";
// ApplePaySession — present only on macOS Chrome AND only on
// secure contexts (Apple Pay requires https). A missing constructor
// on a macOS UA is a strong inconsistency versus a real browser.
// Constructor + statics shaped to match
// Chrome 147's ApplePaySession surface.
const _ops2 = Deno && Deno.core && Deno.core.ops;
const _isSecureForAP = _ops2 && _ops2.op_is_secure_context && _ops2.op_is_secure_context();
if (_osName === "macOS" && _isSecureForAP && typeof globalThis.ApplePaySession === "undefined") {
const _APP = function ApplePaySession(_version, _paymentRequest) {
this.onvalidatemerchant = null;
this.onpaymentauthorized = null;
this.onpaymentmethodselected = null;
this.onshippingcontactselected = null;
this.onshippingmethodselected = null;
this.oncouponcodechanged = null;
this.oncancel = null;
};
_APP.prototype = {
begin() {},
abort() {},
completeMerchantValidation() {},
completePayment() {},
completePaymentMethodSelection() {},
completeShippingContactSelection() {},
completeShippingMethodSelection() {},
completeCouponCodeChange() {},
addEventListener() {},
removeEventListener() {},
};
_APP.STATUS_SUCCESS = 0;
_APP.STATUS_FAILURE = 1;
_APP.STATUS_INVALID_BILLING_POSTAL_ADDRESS = 2;
_APP.STATUS_INVALID_SHIPPING_POSTAL_ADDRESS = 3;
_APP.STATUS_INVALID_SHIPPING_CONTACT = 4;
_APP.STATUS_PIN_REQUIRED = 5;
_APP.STATUS_PIN_INCORRECT = 6;
_APP.STATUS_PIN_LOCKOUT = 7;
_APP.canMakePayments = function canMakePayments() { return true; };
_APP.canMakePaymentsWithActiveCard = function canMakePaymentsWithActiveCard(_id) { return Promise.resolve(false); };
_APP.openPaymentSetup = function openPaymentSetup(_id) { return Promise.resolve(false); };
_APP.supportsVersion = function supportsVersion(version) { return version >= 1 && version <= 14; };
Object.defineProperty(globalThis, 'ApplePaySession', {
value: _APP,
configurable: true,
writable: true,
});
}
// -- iOS Safari profile: strip 16 declined APIs + add iOS globals --
// Per Apple's "16 web APIs declined for privacy" policy. The
// single highest-ROI mobile patch — many leaks vanish at once.
const _deviceClass = (_hasProfile && ops.op_get_profile_value)
? ops.op_get_profile_value("device_class")
: "Desktop";
if (_deviceClass === "MobileIOS") {
// 1. Delete 16 declined APIs from globalThis
const _iosDeleted = [
"Bluetooth", "USB", "USBAlternateInterface", "USBConfiguration",
"USBConnectionEvent", "USBDevice", "USBEndpoint",
"USBInTransferResult", "USBInterface",
"USBIsochronousInTransferPacket", "USBIsochronousInTransferResult",
"USBIsochronousOutPacket", "USBIsochronousOutTransferResult",
"USBOutTransferResult",
"HID", "HIDConnectionEvent", "HIDDevice", "HIDInputReportEvent",
"Serial", "SerialPort",
"NetworkInformation", "BatteryManager",
"IdleDetector", "EyeDropper",
// Chrome-only interfaces real Safari does NOT expose.
// A `'X' in window` check against an iOS UA would flag these.
"UserActivation", "Scheduling",
"Sensor", "Accelerometer", "AbsoluteOrientationSensor",
"GravitySensor", "Gyroscope", "LinearAccelerationSensor",
"Magnetometer", "OrientationSensor", "RelativeOrientationSensor",
// WebGPU is feature-flagged on iOS 18+ but defaults off
"GPU", "GPUAdapter", "GPUDevice", "GPUQueue", "GPUBuffer",
"GPUTexture", "GPUSampler", "GPUBindGroup", "GPUBindGroupLayout",
"GPUPipelineLayout", "GPUShaderModule", "GPURenderPipeline",
"GPUComputePipeline", "GPUCommandEncoder", "GPUCommandBuffer",
"GPURenderPassEncoder", "GPUComputePassEncoder",
"GPURenderBundleEncoder", "GPURenderBundle", "GPUCanvasContext",
"GPUColorWrite", "GPUMapMode", "GPUTextureUsage",
"GPUBufferUsage", "GPUShaderStage",
// Speech recognition has limited iOS support, but webkit-prefixed
// is the only form Safari ships
"SpeechRecognition", "SpeechRecognitionEvent",
"SpeechRecognitionErrorEvent",
];
for (const k of _iosDeleted) {
try { delete globalThis[k]; } catch (_e) {}
}
// 2. Strip Navigator.prototype methods/getters that iOS doesn't have.
// Defense in depth: window_bootstrap.js W1.5 gate avoids
// installing these on iOS profiles, but we also delete here in
// case any prior pass re-installed them. Use `delete` (not
// redefine-with-undefined-getter) so `'X' in navigator` returns
// false — the descriptor must not be present.
const _NavProto = globalThis.Navigator && globalThis.Navigator.prototype;
if (_NavProto) {
for (const k of [
"bluetooth", "usb", "serial", "hid", "requestMIDIAccess",
"getBattery", "connection", "getInstalledRelatedApps",
"scheduling", "userActivation",
// userAgentData absent on Safari (no UA-CH at all)
"userAgentData",
// deviceMemory absent on Safari
"deviceMemory",
]) {
try { delete _NavProto[k]; } catch (_e) {}
}
}
// 3. PaymentRequest.prototype.hasEnrolledInstrument is Chrome/Edge-only
// Safari MUST NOT have it.
if (globalThis.PaymentRequest && globalThis.PaymentRequest.prototype) {
try { delete globalThis.PaymentRequest.prototype.hasEnrolledInstrument; } catch (_e) {}
}
// 4. window.orientation — legacy iOS-only property. Desktop browsers
// do NOT have this. Setting to 0 = portrait.
try {
Object.defineProperty(globalThis, "orientation", {
get: function() { return 0; },
configurable: true, enumerable: true,
});
} catch (_e) {}
// 5. ontouchstart on window — every detection script's cheapest
// mobile-vs-desktop check
try {
Object.defineProperty(globalThis, "ontouchstart", {
value: null, configurable: true, writable: true, enumerable: true,
});
} catch (_e) {}
// 6. DeviceMotionEvent.requestPermission + DeviceOrientationEvent.requestPermission
// iOS 13+ requires user-gesture-gated permission for these. The presence
// of these static methods is itself a strong iOS signal — Android does NOT
// expose these statics.
if (globalThis.DeviceMotionEvent
&& typeof globalThis.DeviceMotionEvent.requestPermission !== "function") {
try {
globalThis.DeviceMotionEvent.requestPermission =
function requestPermission() { return Promise.resolve("denied"); };
} catch (_e) {}
}
if (globalThis.DeviceOrientationEvent
&& typeof globalThis.DeviceOrientationEvent.requestPermission !== "function") {
try {
globalThis.DeviceOrientationEvent.requestPermission =
function requestPermission() { return Promise.resolve("denied"); };
} catch (_e) {}
}
// 7. Sec-CH-UA-* JS surface absent on Safari — already handled
// above via userAgentData getter returning undefined.
// 8. window.chrome must be absent on iOS Safari. Some scripts
// explicitly probe `typeof window.chrome` — Chrome
// returns "object", Safari "undefined". A positive hit under
// an iOS UA is a strong inconsistency.
try { delete globalThis.chrome; } catch (_e) {}
// 8b. navigator.permissions.query() — Safari 18 supports a much
// narrower permission name set than Chrome. Per WebKit:
// allowed = notifications, push, camera, microphone,
// geolocation, persistent-storage.
// Chrome-only names (midi, accelerometer, gyroscope,
// magnetometer, ambient-light-sensor, background-fetch,
// background-sync, clipboard-read, clipboard-write,
// display-capture, screen-wake-lock, system-wake-lock,
// window-management) must reject with TypeError on Safari
// to match real WebKit behavior. PLAN W1.5 (Plan §0 #6).
try {
if (globalThis.navigator && globalThis.navigator.permissions) {
const _safariAllowed = new Set([
'notifications', 'push', 'camera', 'microphone',
'geolocation', 'persistent-storage',
]);
const _PProto = globalThis.navigator.permissions
&& Object.getPrototypeOf(globalThis.navigator.permissions);
if (_PProto && typeof _PProto.query === 'function') {
const _origQuery = _PProto.query;
const safariQuery = function query(desc) {
const name = desc && typeof desc === 'object' ? desc.name : undefined;
if (typeof name !== 'string' || !_safariAllowed.has(name)) {
return Promise.reject(new TypeError(
"Failed to execute 'query' on 'Permissions': "
+ (typeof name === 'string'
? "The provided value '" + name + "' is not a valid enum value of type PermissionName."
: "parameter 1 is not of type 'PermissionDescriptor'.")
));
}
return _origQuery.call(this, desc);
};
Object.defineProperty(_PProto, 'query', {
value: safariQuery, writable: true, enumerable: false, configurable: true,
});
// Preserve native-shape Function.prototype.toString output
// via the _nativeTag symbol installed by stealth_bootstrap.js.
const _tag = globalThis._nativeTag;
if (_tag) {
try { Object.defineProperty(safariQuery, _tag, { value: 'query', configurable: true }); } catch (_e) {}
try { Object.defineProperty(safariQuery, 'name', { value: 'query', configurable: true }); } catch (_e) {}
}
}
}
} catch (_e) {}
// 9. navigator.plugins / navigator.mimeTypes empty on iOS
// (PluginArray length 0 is the canonical mobile-Safari shape).
try {
if (globalThis.navigator) {
const _emptyPlugins = Object.create(globalThis.PluginArray ? globalThis.PluginArray.prototype : null);
Object.defineProperty(_emptyPlugins, 'length', { get: () => 0, enumerable: true });
Object.defineProperty(_emptyPlugins, 'item', {
value: function item() { return null; },
writable: true, enumerable: false, configurable: true,
});
Object.defineProperty(_emptyPlugins, 'namedItem', {
value: function namedItem() { return null; },
writable: true, enumerable: false, configurable: true,
});
Object.defineProperty(_emptyPlugins, 'refresh', {
value: function refresh() {},
writable: true, enumerable: false, configurable: true,
});
Object.defineProperty(_emptyPlugins, Symbol.iterator, {
value: function* () {},
writable: true, enumerable: false, configurable: true,
});
Object.defineProperty(_NavProto, 'plugins', {
get: function() { return _emptyPlugins; },
configurable: true, enumerable: false,
});
const _emptyMimeTypes = Object.create(globalThis.MimeTypeArray ? globalThis.MimeTypeArray.prototype : null);
Object.defineProperty(_emptyMimeTypes, 'length', { get: () => 0, enumerable: true });
Object.defineProperty(_emptyMimeTypes, 'item', {
value: function item() { return null; },
writable: true, enumerable: false, configurable: true,
});
Object.defineProperty(_emptyMimeTypes, 'namedItem', {
value: function namedItem() { return null; },
writable: true, enumerable: false, configurable: true,
});
Object.defineProperty(_NavProto, 'mimeTypes', {
get: function() { return _emptyMimeTypes; },
configurable: true, enumerable: false,
});
// pdfViewerEnabled is false on mobile (no integrated PDF viewer)
Object.defineProperty(_NavProto, 'pdfViewerEnabled', {
get: function() { return false; },
configurable: true, enumerable: false,
});
}
} catch (_e) {}
}
} catch (_e) { /* profile-conditional installs are best-effort */ }
// -- native-source masking of Web Platform constructors --------
// Some scripts dump `String(globalThis.<ctor>)` for a
// rotating list of Web Platform constructors/functions and feed
// the result into a browser-fingerprint score. Without masking,
// many probed names leak our polyfill source —
// raw `class Worker {…}` / `function(input, init){…}` bodies, or
// the wrong native name (constructors that extend our internal
// EventTarget reported `function EventTarget() { [native code] }`,
// `clearTimeout` reported `clearInterval`). Real Chrome returns
// `function <Name>() { [native code] }` for every one of these.
//
// This MUST run here, not in stealth_bootstrap.js: the constructors
// are defined by interfaces/shared_apis/streams/window/worker
// bootstraps that are concatenated AFTER stealth_bootstrap.js (and
// shared_apis/worker run at runtime, after the snapshot). This is
// the universal last pass — it runs always for the page (even from
// snapshot) and last for workers — and `_maskFunction` is still on
// globalThis here (the `internals` purge below removes it after).
try {
const _mask = globalThis._maskFunction;
if (typeof _mask === 'function') {
// De-alias Chrome-distinct pairs our impl points at one
// object. The fresh /tl `sfc` probe caught these: real
// Chrome has clearTimeout!==clearInterval,
// scroll!==scrollTo, DOMMatrix!==DOMMatrixReadOnly — each
// is its own named native, so a single shared object can't
// satisfy `String(globalThis[name])` for both names. We
// split the secondary into a distinct delegator/subclass
// (more Chrome-faithful; zero behavior change).
try {
if (typeof globalThis.clearTimeout === 'function'
&& globalThis.clearInterval === globalThis.clearTimeout) {
const _ct = globalThis.clearTimeout;
globalThis.clearInterval = { clearInterval(id) { return _ct(id); } }.clearInterval;
}
if (typeof globalThis.scrollTo === 'function'
&& globalThis.scroll === globalThis.scrollTo) {
const _st = globalThis.scrollTo;
globalThis.scroll = { scroll() { return _st.apply(this, arguments); } }.scroll;
}
if (typeof globalThis.DOMMatrix === 'function'
&& globalThis.DOMMatrixReadOnly === globalThis.DOMMatrix) {
globalThis.DOMMatrixReadOnly = class DOMMatrixReadOnly extends globalThis.DOMMatrix {};
}
} catch (_e) {}
// Native NON-constructor functions must have NO own
// `prototype` and must be non-constructable (`new fetch()`
// throws in Chrome). A CLEAN production probe
// (the challenge-vendor native-fn-shape clean probe — no capture shim)
// confirmed setTimeout/setInterval/clearTimeout/
// clearInterval/queueMicrotask/structuredClone are plain
// `function` decls → carry `.prototype` + are
// constructable (a real-browser inconsistency).
// `function f(){}`'s `.prototype` is non-configurable so
// `delete` fails — the only fix is to REPLACE with a
// method-shorthand (`{[k](){}}[k]`): no `.prototype`,
// non-constructable, name===k. Forwarding wrapper
// preserves behavior (none use `this`/`new`). Only the
// probe-confirmed-broken set is touched; already-correct
// async/shorthand natives (fetch/atob/btoa/scrollTo/
// reportError/console.*) are left alone.
const _natMethod = (holder, key, nm) => {
try {
const o = holder && holder[key];
if (typeof o !== 'function') return;
if (!Object.prototype.hasOwnProperty.call(o, 'prototype')) {
_mask(o, nm || key);
return;
}
const w = { [key]() { return o.apply(this, arguments); } }[key];
_mask(w, nm || key);
try { holder[key] = w; } catch (_e2) {}
} catch (_e2) {}
};
for (const _k of ['setTimeout', 'setInterval', 'clearTimeout',
'clearInterval', 'queueMicrotask', 'structuredClone']) {
_natMethod(globalThis, _k);
}
try {
const _ca = globalThis.chrome && globalThis.chrome.app;
if (_ca) {
for (const _m of ['getDetails', 'getIsInstalled',
'installState', 'runningState']) {
_natMethod(_ca, _m);
}
}
} catch (_e) {}
// (chrome.app.* are handled by _natMethod above — it both
// native-masks toString [otherwise a probe would leak
// "function getDetails() { return null; }"] and removes the
// illegal `.prototype`/constructability.)
// The commonly probed names, plus adjacent
// standard constructors — all are
// genuinely `[native code]` in real Chrome, so masking any
// that exist on this profile is correct (missing ones are a
// safe no-op via `_maskFunction`'s `if (!fn) return`).
// [globalKey, maskName]. maskName differs from globalKey
// only for the legacy webkit-prefixed aliases: in real
// Chrome `webkitAudioContext === AudioContext` (same object),
// so `String(webkitAudioContext)` is
// `function AudioContext() { [native code] }`. Masking them
// to their prefixed key would itself be a divergence.
const _sfcNames = [
['webkitMediaStream', 'MediaStream'],
['webkitAudioContext', 'AudioContext'],
['webkitRTCPeerConnection', 'RTCPeerConnection'],
'fetch', 'clearTimeout', 'clearInterval', 'setTimeout',
'setInterval', 'TouchEvent', 'AudioContext', 'OffscreenCanvas',
'Bluetooth', 'StorageManager', 'scrollTo', 'scroll', 'scrollBy',
'Worker', 'SharedWorker', 'ServiceWorker', 'WorkerGlobalScope',
'DedicatedWorkerGlobalScope', 'FileReader', 'ImageBitmap',
'DOMMatrix', 'DOMMatrixReadOnly', 'PerformanceObserver',
'PerformanceEntry', 'ReportingObserver', 'ReadableStream',
'WritableStream', 'TransformStream', 'ReadableStreamDefaultReader',
'WritableStreamDefaultWriter', 'ReadableStreamDefaultController',
'BroadcastChannel', 'MessagePort', 'MessageChannel',
'EventSource', 'CompressionStream', 'DecompressionStream',
'Crypto', 'SubtleCrypto', 'CloseEvent', 'AbortController',
'AbortSignal', 'DOMException', 'URL', 'URLSearchParams',
'FormData', 'Blob', 'File', 'FileList', 'RTCPeerConnection',
'PressureObserver', 'InputDeviceCapabilities', 'MediaSession',
'Touch', 'TouchList', 'EyeDropper', 'XMLHttpRequest',
'XMLHttpRequestUpload', 'WebSocket', 'Notification', 'Image',
'Audio', 'Headers', 'Request', 'Response', 'createImageBitmap',
'structuredClone', 'queueMicrotask', 'reportError', 'atob',
'btoa', 'ResizeObserver', 'IntersectionObserver',
'MutationObserver', 'TextEncoder', 'TextDecoder', 'EventTarget',
'Event', 'CustomEvent', 'MediaStream', 'MediaStreamTrack',
'MediaRecorder', 'DOMRect', 'DOMRectReadOnly', 'DOMPoint',
'DOMPointReadOnly', 'DOMQuad',
// The WebGL/Canvas context
// constructor OBJECTS themselves. Their prototype methods are
// masked by the universal sweep, but String(WebGLRenderingContext)
// is commonly enumerated and must be `[native code]`.
'WebGLRenderingContext', 'WebGL2RenderingContext',
'CanvasRenderingContext2D', 'WebGLContextEvent',
// Event-subclass constructor
// objects. event_bootstrap.js defines them as JS classes, so
// String(MouseEvent) leaked `class MouseEvent extends ...`,
// which differs from real Chrome. Masking sets `[native code]`
// + the correct own `.name`. Real Chrome: every one is native.
'UIEvent', 'MouseEvent', 'KeyboardEvent', 'InputEvent',
'FocusEvent', 'PointerEvent', 'WheelEvent', 'MessageEvent',
'ErrorEvent', 'ProgressEvent', 'AnimationEvent',
'TransitionEvent', 'ClipboardEvent', 'PopStateEvent',
'HashChangeEvent', 'StorageEvent', 'PageTransitionEvent',
'BeforeUnloadEvent', 'DragEvent', 'SecurityPolicyViolationEvent',
'CompositionEvent', 'DeviceMotionEvent', 'DeviceOrientationEvent',
];
for (const _e of _sfcNames) {
try {
const _key = Array.isArray(_e) ? _e[0] : _e;
const _nm = Array.isArray(_e) ? _e[1] : _e;
const _fn = globalThis[_key];
if (typeof _fn === 'function') _mask(_fn, _nm);
} catch (_e2) {}
}
}
} catch (_e) { /* sfc masking is best-effort */ }
// -- Universal prototype mask sweep ----------
// Many scripts inspect Function.prototype.toString
// on patched prototype methods (Headers/Request/Response, XHR,
// Observers, Streams, Event subclasses, IDB, Range, etc.). Walk
// every globalThis constructor that has a .prototype, mask every
// own-function method to `function NAME() { [native code] }`.
// Runs AFTER all bootstraps (interfaces / shared_apis / streams /
// events / canvas / window / worker) so it covers every prototype
// installed by them — including bootstraps that run post-snapshot.
// Safe on real V8 natives: `_maskAsNative` is idempotent — sets the
// Symbol(__browser_oxide_native__) tag; if the function was already
// native-toString-ing it stays so.
try {
const _mask = globalThis._maskAsNative;
if (typeof _mask === 'function') {
const _SKIP = new Set([Object.prototype, Function.prototype]);
for (const _gname of Object.getOwnPropertyNames(globalThis)) {
let _v;
try { _v = globalThis[_gname]; } catch (_e) { continue; }
if (typeof _v !== 'function') continue;
const _p = _v.prototype;
if (!_p || _SKIP.has(_p)) continue;
const _methods = [];
let _ns;
try { _ns = Object.getOwnPropertyNames(_p); } catch (_e) { continue; }
for (const _n of _ns) {
if (_n === 'constructor') continue;
let _d;
try { _d = Object.getOwnPropertyDescriptor(_p, _n); } catch (_e) { continue; }
// Collect ACCESSOR props too
// (get/set), not just data-value methods. _maskAsNative
// already masks desc.get/desc.set (stealth_bootstrap.js:94),
// but the sweep previously skipped accessor-only props, so
// ~15 injected getters/setters (Request.signal, Response.*,
// ReadableStream.locked, MessagePort.onmessage,
// URLSearchParams.size, WebSocket.*) leaked JS source under
// `getOwnPropertyDescriptor(proto,name).get.toString()` —
// a Function.toString integrity tell ~11 vendors probe.
if (
_d &&
(typeof _d.value === 'function' ||
typeof _d.get === 'function' ||
typeof _d.set === 'function')
) {
_methods.push(_n);
}
}
if (_methods.length) {
try { _mask(_p, ..._methods); } catch (_e) {}
}
}
}
} catch (_e) { /* universal mask sweep is best-effort */ }
const internals = [
'Deno',
'ops',
'_maskFunction',
'_maskAsNative',
'_nativeTag',
'_customElementsRegistry',
'__bootstrap',
'__browser_oxide',
'__syncCookiesFromNet',
'__documentReadyState',
'__drainCspViolations',
'__onNodeInserted',
'__errors',
];
// -- Worker Scope Isolation (Phase 8) ---------------------------
// Real Chrome Web Workers (DedicatedWorkerGlobalScope) have a very
// clean namespace. They do NOT expose DOM, CSSOM, or Hardware APIs.
// If we're in a worker, purge the illegal globals.
const _isWorker = typeof DedicatedWorkerGlobalScope !== 'undefined' &&
globalThis instanceof DedicatedWorkerGlobalScope;
if (_isWorker) {
const _workerPurge = [
'window', 'document', 'history', 'locationbar', 'menubar',
'personalbar', 'scrollbars', 'statusbar', 'toolbar', 'frames',
'parent', 'top', 'opener', 'frameElement', 'styleMedia',
'getComputedStyle', 'getSelection', 'matchMedia', 'alert',
'confirm', 'prompt', 'print', 'stop', 'open', 'close',
'focus', 'blur', 'moveBy', 'moveTo', 'resizeBy', 'resizeTo',
'scroll', 'scrollBy', 'scrollTo', 'requestAnimationFrame',
'cancelAnimationFrame', 'requestIdleCallback', 'cancelIdleCallback',
// Constructors
'Node', 'Element', 'HTMLElement', 'HTMLDocument', 'Document',
'CharacterData', 'Text', 'Comment', 'CDATASection', 'DocumentFragment',
'DocumentType', 'NamedNodeMap', 'Attr', 'NodeList', 'HTMLCollection',
'HTMLAllCollection', 'DOMTokenList', 'DOMImplementation', 'Range',
'Selection', 'DOMParser', 'XMLSerializer', 'XPathEvaluator',
'XPathExpression', 'XPathResult', 'XSLTProcessor', 'MutationObserver',
'MutationRecord', 'IntersectionObserver', 'ResizeObserver',
'PermissionStatus', 'Screen', 'ScreenOrientation', 'VisualViewport',
'ViewTransition', 'Highlight', 'HighlightRegistry',
// Hardware/Media (not allowed in workers)
'Bluetooth', 'USB', 'HID', 'Serial', 'Gamepad', 'GamepadButton',
'GamepadEvent', 'GamepadHapticActuator', 'MediaStream', 'MediaStreamTrack',
'MediaRecorder', 'RTCPeerConnection', 'RTCDataChannel', 'RTCSessionDescription',
'RTCIceCandidate', 'RTCCertificate', 'Presentation', 'PresentationRequest',
// CSS classes (100+)
'CSS', 'CSSStyleSheet', 'CSSRule', 'CSSStyleRule', 'CSSMediaRule',
'CSSImportRule', 'CSSFontFaceRule', 'CSSPageRule', 'CSSKeyframesRule',
'CSSKeyframeRule', 'CSSNamespaceRule', 'CSSSupportsRule', 'CSSCounterStyleRule',
// ... and all HTML*Element subclasses
];
for (const k of Object.keys(globalThis)) {
if (k.startsWith('HTML') || k.startsWith('SVG') || k.startsWith('CSS') || _workerPurge.includes(k)) {
try { delete globalThis[k]; } catch (_) {}
}
}
}
if (ops && ops.op_cross_origin_isolated && !ops.op_cross_origin_isolated()) {
internals.push('SharedArrayBuffer');
}
// -- Warm-reuse global-namespace reset ---------------------------
// The last retention source for a pooled `Page`: properties page
// scripts hang straight off the global (`window.__APP_STATE = …`,
// `window.onscroll = …`, framework singletons). `globalThis` is the
// same object for the whole life of the `JsRuntime`, so on the warm
// path every one of those — and everything they transitively
// reference — survives into the next navigation. A real browser gives
// each navigation a fresh global; this is the closest equivalent that
// keeps the expensive bootstrap intact.
//
// `__markGlobalsBaseline()` snapshots the engine-owned key set;
// `__resetPageGlobals()` deletes everything added since. Rust re-marks
// the baseline once more after it installs the post-bootstrap
// instrumentation (`__cookieWrites` / `__scriptErrors` / the fetch +
// XHR wrappers), which is why those names are also allowlisted below —
// construction paths that skip the re-mark must not lose them.
// Note `window === globalThis` here (dom_bootstrap.js), so scrubbing
// the global object covers both.
// Guarded: this file is executed TWICE per page — once from
// `BrowserJsRuntime`'s constructor (before any page script) and again
// from `build_page_with_scripts_*` after the document's scripts have
// run. Only the first execution may seed the baseline; re-running the
// definitions would also reset the closure variable and throw the real
// baseline away.
if (typeof globalThis.__resetPageGlobals !== 'function') {
let _globalsBaseline = null;
let _onHandlerBaseline = null;
const _BASELINE_ALWAYS = [
'_browser_oxide', '__cookieWrites', '__scriptErrors',
'__bo_input_events', '__jsCookies',
];
// `on*` handlers need value-level treatment, not just key-level.
// `onscroll`, `onerror`, … already EXIST as own properties of the
// global at bootstrap (default `null`), so a page that assigns
// `window.onscroll = fn` mutates a baseline key rather than adding
// one — the key-set diff below cannot see it, and the closure (plus
// everything it captures) survives the navigation.
//
// Blanket-nulling them is wrong: the engine itself installs
// `window.onerror` as its script-error instrumentation, once, and
// does NOT re-install it on the warm path. So snapshot the values
// at baseline and RESTORE them, which nulls page assignments while
// preserving the engine's.
const _snapshotOnHandlers = (target) => {
const m = new Map();
if (!target) return m;
let names;
try { names = Object.getOwnPropertyNames(target); } catch (_e) { return m; }
for (const k of names) {
if (!k.startsWith('on')) continue;
try { m.set(k, target[k]); } catch (_e) {}
}
return m;
};
const _restoreOnHandlers = (target, baseline) => {
if (!target || !baseline) return;
let names;
try { names = Object.getOwnPropertyNames(target); } catch (_e) { return; }
for (const k of names) {
if (!k.startsWith('on')) continue;
try {
if (typeof target[k] !== 'function') continue;
const orig = baseline.get(k);
// Already the engine's own handler ⇒ leave it alone.
if (orig === target[k]) continue;
target[k] = (typeof orig === 'function') ? orig : null;
} catch (_e) {}
}
};
Object.defineProperty(globalThis, '__markGlobalsBaseline', {
value: function __markGlobalsBaseline() {
const seen = new Set(_BASELINE_ALWAYS);
for (const k of Object.getOwnPropertyNames(globalThis)) seen.add(k);
for (const s of Object.getOwnPropertySymbols(globalThis)) seen.add(s);
_globalsBaseline = seen;
// `document` is a singleton that survives `replace_dom`, so
// `document.onclick = fn` persists exactly like the window
// case and needs the same treatment.
_onHandlerBaseline = {
global: _snapshotOnHandlers(globalThis),
document: _snapshotOnHandlers(globalThis.document),
};
},
writable: true, configurable: true, enumerable: false,
});
Object.defineProperty(globalThis, '__resetPageGlobals', {
value: function __resetPageGlobals() {
// No baseline ⇒ nothing to compare against; deleting on a
// guess would strip the engine's own globals.
if (!_globalsBaseline) return 0;
let removed = 0;
const keys = Object.getOwnPropertyNames(globalThis)
.concat(Object.getOwnPropertySymbols(globalThis));
for (const k of keys) {
if (_globalsBaseline.has(k)) continue;
// Best-effort: a page can install a non-configurable
// property, and `delete` cannot remove those.
try { if (delete globalThis[k]) removed++; } catch (_e) {}
}
if (_onHandlerBaseline) {
_restoreOnHandlers(globalThis, _onHandlerBaseline.global);
_restoreOnHandlers(globalThis.document, _onHandlerBaseline.document);
}
return removed;
},
writable: true, configurable: true, enumerable: false,
});
// Seed the baseline on this first execution: it runs as the last
// bootstrap, before anything page-authored, so the global namespace
// is exactly the engine's. Rust re-marks once more after installing
// the post-bootstrap instrumentation. The `internals` purge below
// only ever REMOVES keys, so marking before it is safe.
globalThis.__markGlobalsBaseline();
}
for (const name of internals) {
[globalThis, globalThis.window].forEach(obj => {
if (!obj || !(name in obj)) return;
try {
const success = delete obj[name];
if (!success) {
Object.defineProperty(obj, name, { enumerable: false, configurable: true });
}
} catch (e) {
try {
Object.defineProperty(obj, name, { enumerable: false, configurable: true });
} catch (e2) {}
}
});
}
})(globalThis);