@luckylillia-dev/plugin-aiimgdetector 0.0.0-stage → 1.0.5

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.
Files changed (99) hide show
  1. package/README.md +2 -2
  2. package/assets/demo.png +0 -0
  3. package/assets/icon.svg +15 -0
  4. package/assets/synthid-login-check.jpg +0 -0
  5. package/docs/details.md +45 -0
  6. package/docs/publishing.md +66 -0
  7. package/docs/synthid.md +80 -0
  8. package/lib/image.js +90 -0
  9. package/lib/index.js +207 -0
  10. package/lib/provenance.js +21 -0
  11. package/lib/synthid-auth.js +100 -0
  12. package/lib/synthid-browser.js +451 -0
  13. package/lib/synthid-http-runtime/chromium-css-property-catalog.mjs +7 -0
  14. package/lib/synthid-http-runtime/complete-protocol.mjs +88 -0
  15. package/lib/synthid-http-runtime/entry.d.mts +41 -0
  16. package/lib/synthid-http-runtime/entry.mjs +6 -0
  17. package/lib/synthid-http-runtime/event-listener-diagnostics.mjs +141 -0
  18. package/lib/synthid-http-runtime/independent-request-reference.mjs +49 -0
  19. package/lib/synthid-http-runtime/jsdom-event-clock-compat.mjs +76 -0
  20. package/lib/synthid-http-runtime/lifecycle-client.mjs +165 -0
  21. package/lib/synthid-http-runtime/lifecycle-web-session.mjs +114 -0
  22. package/lib/synthid-http-runtime/lifecycle-worker.mjs +363 -0
  23. package/lib/synthid-http-runtime/node-platform-failure-diagnostics.mjs +108 -0
  24. package/lib/synthid-http-runtime/realm-activation-diagnostic.js +31 -0
  25. package/lib/synthid-http-runtime/realm-focus-diagnostic.js +9 -0
  26. package/lib/synthid-http-runtime/realm-init.js +34 -0
  27. package/lib/synthid-http-runtime/realm-pointer-diagnostic.js +49 -0
  28. package/lib/synthid-http-runtime/runtime-anchor-href-translate.mjs +242 -0
  29. package/lib/synthid-http-runtime/runtime-child-web-compat.mjs +103 -0
  30. package/lib/synthid-http-runtime/runtime-chrome-csi.mjs +216 -0
  31. package/lib/synthid-http-runtime/runtime-clock-precision-control.mjs +51 -0
  32. package/lib/synthid-http-runtime/runtime-css-properties-compat.mjs +165 -0
  33. package/lib/synthid-http-runtime/runtime-detached-frame-compat.mjs +214 -0
  34. package/lib/synthid-http-runtime/runtime-javascript-bindings.mjs +69 -0
  35. package/lib/synthid-http-runtime/runtime-navigator-compat.mjs +99 -0
  36. package/lib/synthid-http-runtime/runtime-permissions-binding.mjs +64 -0
  37. package/lib/synthid-http-runtime/runtime-permissions-control.mjs +143 -0
  38. package/lib/synthid-http-runtime/runtime-web-compat.mjs +639 -0
  39. package/lib/synthid-http-runtime/runtime-webidl-callable-control.mjs +151 -0
  40. package/lib/synthid-http-runtime/runtime-webidl-realm-compat.mjs +132 -0
  41. package/lib/synthid-http-runtime/runtime-window-state-compat.mjs +128 -0
  42. package/lib/synthid-http-runtime/scripting-parser.mjs +13 -0
  43. package/lib/synthid-http-runtime/web-session.mjs +64 -0
  44. package/lib/synthid-http-runtime/webidl-brand-errors-preload.mjs +49 -0
  45. package/lib/synthid-http-runtime/webidl-callable-source-catalog.mjs +4491 -0
  46. package/lib/synthid-http-runtime/webidl-realm-catalog.mjs +124 -0
  47. package/lib/synthid-http.js +314 -0
  48. package/lib/synthid-manual.js +365 -0
  49. package/lib/synthid-page.js +101 -0
  50. package/lib/synthid-result.js +189 -0
  51. package/lib/synthid.js +540 -0
  52. package/lib/vision.js +41 -0
  53. package/package.json +84 -4
  54. package/src/image.ts +74 -0
  55. package/src/index.ts +203 -0
  56. package/src/provenance.ts +40 -0
  57. package/src/synthid-auth.ts +83 -0
  58. package/src/synthid-browser.ts +426 -0
  59. package/src/synthid-http-runtime/chromium-css-property-catalog.mjs +7 -0
  60. package/src/synthid-http-runtime/complete-protocol.mjs +88 -0
  61. package/src/synthid-http-runtime/entry.d.mts +41 -0
  62. package/src/synthid-http-runtime/entry.mjs +6 -0
  63. package/src/synthid-http-runtime/event-listener-diagnostics.mjs +141 -0
  64. package/src/synthid-http-runtime/independent-request-reference.mjs +49 -0
  65. package/src/synthid-http-runtime/jsdom-event-clock-compat.mjs +76 -0
  66. package/src/synthid-http-runtime/lifecycle-client.mjs +165 -0
  67. package/src/synthid-http-runtime/lifecycle-web-session.mjs +114 -0
  68. package/src/synthid-http-runtime/lifecycle-worker.mjs +363 -0
  69. package/src/synthid-http-runtime/node-platform-failure-diagnostics.mjs +108 -0
  70. package/src/synthid-http-runtime/realm-activation-diagnostic.js +31 -0
  71. package/src/synthid-http-runtime/realm-focus-diagnostic.js +9 -0
  72. package/src/synthid-http-runtime/realm-init.js +34 -0
  73. package/src/synthid-http-runtime/realm-pointer-diagnostic.js +49 -0
  74. package/src/synthid-http-runtime/runtime-anchor-href-translate.mjs +242 -0
  75. package/src/synthid-http-runtime/runtime-child-web-compat.mjs +103 -0
  76. package/src/synthid-http-runtime/runtime-chrome-csi.mjs +216 -0
  77. package/src/synthid-http-runtime/runtime-clock-precision-control.mjs +51 -0
  78. package/src/synthid-http-runtime/runtime-css-properties-compat.mjs +165 -0
  79. package/src/synthid-http-runtime/runtime-detached-frame-compat.mjs +214 -0
  80. package/src/synthid-http-runtime/runtime-javascript-bindings.mjs +69 -0
  81. package/src/synthid-http-runtime/runtime-navigator-compat.mjs +99 -0
  82. package/src/synthid-http-runtime/runtime-permissions-binding.mjs +64 -0
  83. package/src/synthid-http-runtime/runtime-permissions-control.mjs +143 -0
  84. package/src/synthid-http-runtime/runtime-web-compat.mjs +639 -0
  85. package/src/synthid-http-runtime/runtime-webidl-callable-control.mjs +151 -0
  86. package/src/synthid-http-runtime/runtime-webidl-realm-compat.mjs +132 -0
  87. package/src/synthid-http-runtime/runtime-window-state-compat.mjs +128 -0
  88. package/src/synthid-http-runtime/scripting-parser.mjs +13 -0
  89. package/src/synthid-http-runtime/web-session.mjs +64 -0
  90. package/src/synthid-http-runtime/webidl-brand-errors-preload.mjs +49 -0
  91. package/src/synthid-http-runtime/webidl-callable-source-catalog.mjs +4491 -0
  92. package/src/synthid-http-runtime/webidl-realm-catalog.mjs +124 -0
  93. package/src/synthid-http.ts +290 -0
  94. package/src/synthid-manual.ts +388 -0
  95. package/src/synthid-page.ts +103 -0
  96. package/src/synthid-result.ts +177 -0
  97. package/src/synthid.ts +514 -0
  98. package/src/vision.ts +57 -0
  99. package/webui/index.js +279 -0
@@ -0,0 +1,165 @@
1
+ // Missing CSS named-property reads on unchanged cssstyle declaration backends.
2
+ // Parser/serialization/rendering behavior is deliberately not replaced.
3
+ import { types as nodeTypes } from 'node:util';
4
+ import WindowModule from 'jsdom/lib/jsdom/browser/Window.js';
5
+ import cssstyle from 'cssstyle';
6
+ import cssstylePackage from 'cssstyle/package.json' with { type: 'json' };
7
+ import jsdomPackage from 'jsdom/package.json' with { type: 'json' };
8
+ import utils from 'jsdom/lib/jsdom/living/generated/utils.js';
9
+ import { chromiumCssPropertyCatalog } from './chromium-css-property-catalog.mjs';
10
+
11
+ const get = Object.getOwnPropertyDescriptor, define = Object.defineProperty, apply = Reflect.apply, remove = Reflect.deleteProperty;
12
+ const own = Object.hasOwn, proxy = nodeTypes.isProxy, object = value => value !== null && (typeof value === 'object' || typeof value === 'function');
13
+ const data = (value, key) => { if (!object(value) || proxy(value)) return undefined; const d = get(value, key); return d && own(d, 'value') ? d.value : undefined; };
14
+ const same = (left, right) => !!left && !!right && ['value', 'get', 'set', 'writable', 'enumerable', 'configurable'].every(
15
+ key => own(left, key) === own(right, key) && Object.is(left[key], right[key]));
16
+ const cssPrototype = cssstyle.CSSStyleDeclaration.prototype;
17
+ const originalRead = data(cssPrototype, 'getPropertyValue'), originalWrite = data(cssPrototype, 'setProperty');
18
+ const mapHas = Map.prototype.has, isPrototype = Object.prototype.isPrototypeOf;
19
+ const MAX_REALMS = 32, MAX_STYLES = 1024, LIMIT = 1000000, activeRealms = new WeakSet(); let activeChildHook = false;
20
+ const errors = new Set(['INVALID_OPTIONS', 'UNSUPPORTED_JSDOM', 'UNSUPPORTED_REALM', 'ALREADY_INSTALLED', 'CHILD_HOOK_ALREADY_INSTALLED', 'INSTALL_FAILED']);
21
+ export class RuntimeCssPropertiesCompatError extends Error {
22
+ constructor(code) { const safe = errors.has(code) ? code : 'INSTALL_FAILED'; super('Runtime CSS properties failed: ' + safe); this.name = 'RuntimeCssPropertiesCompatError'; this.code = safe; }
23
+ }
24
+ function hasProperty(value, key) {
25
+ for (let current = value, depth = 0; current && depth < 64; current = Object.getPrototypeOf(current), depth++) {
26
+ if (proxy(current)) return true;
27
+ if (get(current, key)) return true;
28
+ }
29
+ return false;
30
+ }
31
+ function isStyle(value) {
32
+ if (!object(value) || proxy(value) || !apply(isPrototype, cssPrototype, [value])) return false;
33
+ const values = data(value, '_values');
34
+ if (!object(values) || proxy(values)) return false;
35
+ try { apply(mapHas, values, ['']); return true; } catch { return false; }
36
+ }
37
+
38
+ function createRealmHelpers(read, write, brand, decorateInline, decorateComputed, entries) {
39
+ 'use strict';
40
+ const RealmTypeError = TypeError, apply = Reflect.apply, get = Object.getOwnPropertyDescriptor;
41
+ const descriptors = entries.map(([name, cssName]) => {
42
+ const holder = {
43
+ get [name]() { if (!brand(this)) throw new RealmTypeError('Illegal invocation'); return read(this, cssName); },
44
+ set [name](value) { if (!brand(this)) throw new RealmTypeError('Illegal invocation'); write(this, cssName, value); },
45
+ };
46
+ return { name, descriptor: get(holder, name) };
47
+ });
48
+ return {
49
+ realm: globalThis, descriptors,
50
+ styleGetter(original) { return get({ get style() { return decorateInline(apply(original, this, arguments), this); } }, 'style').get; },
51
+ computedStyle(original) { return function getComputedStyle(element) { return decorateComputed(apply(original, this, arguments)); }; },
52
+ };
53
+ }
54
+
55
+ /** Install before page code, after earlier compatibility hooks. Existing styles
56
+ * are decorated lazily on acquisition; dispose before earlier child hooks. */
57
+ export function installRuntimeCssPropertiesCompat(window, options = {}) {
58
+ if (!object(window) || proxy(window) || !object(options) || proxy(options) || Array.isArray(options)) throw new RuntimeCssPropertiesCompatError('INVALID_OPTIONS');
59
+ const option = get(options, 'children');
60
+ if (option && !own(option, 'value')) throw new RuntimeCssPropertiesCompatError('INVALID_OPTIONS');
61
+ const children = option?.value === undefined ? false : option.value;
62
+ if (typeof children !== 'boolean') throw new RuntimeCssPropertiesCompatError('INVALID_OPTIONS');
63
+ if (jsdomPackage.version !== '26.1.0' || cssstylePackage.version !== '4.6.0' || typeof originalRead !== 'function' || typeof originalWrite !== 'function') throw new RuntimeCssPropertiesCompatError('UNSUPPORTED_JSDOM');
64
+ if (activeRealms.has(window)) throw new RuntimeCssPropertiesCompatError('ALREADY_INSTALLED');
65
+ if (children && activeChildHook) throw new RuntimeCssPropertiesCompatError('CHILD_HOOK_ALREADY_INSTALLED');
66
+ const previousFactory = children ? get(WindowModule, 'createWindow') : undefined;
67
+ if (children && (!previousFactory?.writable || typeof previousFactory.value !== 'function')) throw new RuntimeCssPropertiesCompatError('UNSUPPORTED_JSDOM');
68
+ const missing = chromiumCssPropertyCatalog.filter(([name]) => !hasProperty(cssPrototype, name));
69
+ const realms = [], saved = []; let stylesSeen = new WeakSet(), realmByBacking = new WeakMap(), disposed = false, installedFactory;
70
+ const stats = { installedRealms: 0, missingCatalogProperties: missing.length, decoratedStyles: 0, addedProperties: 0, preservedProperties: 0,
71
+ inlineGetterWrappers: 0, computedStyleWrappers: 0, unsupportedAcquisitions: 0, unsupportedStyleObjects: 0,
72
+ reads: 0, writes: 0, observedChildren: 0, skippedFactories: 0, unsupportedChildren: 0, childFailures: 0,
73
+ realmLimitReached: false, styleLimitReached: false, mutationFailures: 0, removedProperties: 0, restoredAcquisitionWrappers: 0,
74
+ cleanupConflicts: 0, cleanupFailures: 0, childFactoryRestored: false, childFactoryRestoreConflict: false };
75
+ const increment = key => { stats[key] = Math.min(LIMIT, stats[key] + 1); };
76
+ const snapshot = () => ({ schemaVersion: 1, diagnosticOnly: true, runtimeCssPropertiesCompat: true,
77
+ childrenEnabled: children, maximumRealms: MAX_REALMS, maximumStyles: MAX_STYLES, catalogProperties: chromiumCssPropertyCatalog.length,
78
+ getterSource: 'unchanged-cssstyle-getPropertyValue', setterSource: 'unchanged-cssstyle-setProperty', staticDefaultValues: false,
79
+ fullChromeCssGrammar: false, parserModified: false, renderingModeled: false, sharedCssPrototypeModified: false,
80
+ originalCssMethodsModified: false, styleObjectIdentityChanged: false, sourceRenderingModified: false,
81
+ standaloneConstructorInstancesModeled: false, stylesheetRuleObjectsModeled: false, ...stats, disposed });
82
+ function decorate(style, record) {
83
+ if (disposed || !record) return style;
84
+ if (!isStyle(style)) { increment('unsupportedStyleObjects'); return style; }
85
+ if (stylesSeen.has(style)) return style;
86
+ if (stats.decoratedStyles >= MAX_STYLES) { stats.styleLimitReached = true; return style; }
87
+ stylesSeen.add(style); increment('decoratedStyles');
88
+ for (const { name, descriptor } of record.helpers.descriptors) {
89
+ if (hasProperty(style, name)) { increment('preservedProperties'); continue; }
90
+ const next = { ...descriptor, enumerable: true, configurable: true };
91
+ try { define(style, name, next); saved.push({ target: style, key: name, previous: undefined, next, property: true }); increment('addedProperties'); }
92
+ catch { increment('mutationFailures'); }
93
+ }
94
+ return style;
95
+ }
96
+ function wrap(target, key, previous, next, counter) {
97
+ if (!previous || (!previous.configurable && (!own(previous, 'value') || !previous.writable))) { increment('unsupportedAcquisitions'); return; }
98
+ define(target, key, next); saved.push({ target, key, previous, next, property: false }); increment(counter);
99
+ }
100
+ function installRealm(realm) {
101
+ if (realms.length >= MAX_REALMS) { stats.realmLimitReached = true; return; }
102
+ if (!object(realm) || proxy(realm) || activeRealms.has(realm)) throw new RuntimeCssPropertiesCompatError('UNSUPPORTED_REALM');
103
+ const realmFunction = data(realm, 'Function'), backing = data(realm, '_globalObject'), registry = data(realm, utils.ctorRegistrySymbol);
104
+ if (typeof realmFunction !== 'function' || realmFunction === Function || !backing || data(backing, '_globalProxy') !== realm || !registry) throw new RuntimeCssPropertiesCompatError('UNSUPPORTED_REALM');
105
+ const record = { realm, backing, helpers: undefined }; realms.push(record); realmByBacking.set(backing, record); activeRealms.add(realm); increment('installedRealms');
106
+ const read = (receiver, cssName) => { if (!disposed) increment('reads'); return apply(originalRead, receiver, [cssName]); };
107
+ const write = (receiver, cssName, value) => { if (!disposed) increment('writes'); return apply(originalWrite, receiver, [cssName, value]); };
108
+ const decorateInline = (style, receiver) => {
109
+ const impl = data(receiver, utils.implSymbol), owner = data(impl, '_globalObject');
110
+ return decorate(style, realmByBacking?.get(owner));
111
+ };
112
+ const decorateComputed = style => decorate(style, record);
113
+ const factory = realmFunction('read', 'write', 'brand', 'decorateInline', 'decorateComputed', 'entries',
114
+ 'return (' + createRealmHelpers.toString() + ')(read,write,brand,decorateInline,decorateComputed,entries)');
115
+ // Names are fixed public catalog data. They are never derived from a page.
116
+ const entries = apply(realmFunction('return ' + JSON.stringify(missing)), undefined, []);
117
+ const helpers = apply(factory, undefined, [read, write, isStyle, decorateInline, decorateComputed, entries]);
118
+ if (helpers.realm !== realm) throw new RuntimeCssPropertiesCompatError('UNSUPPORTED_REALM'); record.helpers = helpers;
119
+ for (const name of ['HTMLElement', 'SVGElement']) {
120
+ const constructor = data(registry, name), prototype = data(constructor, 'prototype'), previous = prototype && get(prototype, 'style');
121
+ if (!previous || typeof previous.get !== 'function') { increment('unsupportedAcquisitions'); continue; }
122
+ wrap(prototype, 'style', previous, { ...previous, get: helpers.styleGetter(previous.get) }, 'inlineGetterWrappers');
123
+ }
124
+ const computed = get(realm, 'getComputedStyle');
125
+ if (computed && own(computed, 'value') && typeof computed.value === 'function')
126
+ wrap(realm, 'getComputedStyle', computed, { ...computed, value: helpers.computedStyle(computed.value) }, 'computedStyleWrappers');
127
+ else increment('unsupportedAcquisitions');
128
+ }
129
+ function dispose() {
130
+ if (disposed) return snapshot(); disposed = true;
131
+ if (installedFactory) {
132
+ try {
133
+ if (same(get(WindowModule, 'createWindow'), installedFactory)) { define(WindowModule, 'createWindow', previousFactory); stats.childFactoryRestored = true; }
134
+ else stats.childFactoryRestoreConflict = true;
135
+ } catch { stats.childFactoryRestoreConflict = true; }
136
+ activeChildHook = false;
137
+ }
138
+ for (let index = saved.length - 1; index >= 0; index--) {
139
+ const { target, key, previous, next, property } = saved[index];
140
+ try {
141
+ if (!same(get(target, key), next)) { increment('cleanupConflicts'); continue; }
142
+ if (previous) define(target, key, previous); else if (!remove(target, key)) throw Error('RESTORE_FAILED');
143
+ increment(property ? 'removedProperties' : 'restoredAcquisitionWrappers');
144
+ } catch { increment('cleanupFailures'); }
145
+ }
146
+ saved.length = 0; for (const record of realms) activeRealms.delete(record.realm); realms.length = 0;
147
+ stylesSeen = undefined; realmByBacking = undefined; return snapshot();
148
+ }
149
+ try {
150
+ installRealm(window);
151
+ if (children) {
152
+ const original = previousFactory.value;
153
+ const wrapper = function createWindowWithCssProperties(factoryOptions) {
154
+ const child = apply(original, this, arguments); if (disposed) return child;
155
+ if (!object(factoryOptions) || proxy(factoryOptions) || !get(factoryOptions, 'parentOrigin')) { increment('skippedFactories'); return child; }
156
+ increment('observedChildren');
157
+ if (data(factoryOptions, 'runScripts') !== 'outside-only') { increment('unsupportedChildren'); return child; }
158
+ try { const realm = data(child, '_globalProxy'); if (!realm) increment('unsupportedChildren'); else installRealm(realm); } catch { increment('childFailures'); }
159
+ return child;
160
+ };
161
+ installedFactory = { ...previousFactory, value: wrapper }; define(WindowModule, 'createWindow', installedFactory); activeChildHook = true;
162
+ }
163
+ return Object.freeze({ snapshot, dispose });
164
+ } catch (error) { dispose(); throw error instanceof RuntimeCssPropertiesCompatError ? error : new RuntimeCssPropertiesCompatError('INSTALL_FAILED'); }
165
+ }
@@ -0,0 +1,214 @@
1
+ // Scoped JSDOM 26 correction for retained, detached sourceless leaf iframes.
2
+ // Install before child web compatibility; dispose after it, before root close.
3
+ import WindowModule from 'jsdom/lib/jsdom/browser/Window.js';
4
+ import FrameModule from 'jsdom/lib/jsdom/living/nodes/HTMLFrameElement-impl.js';
5
+ import NodeModule from 'jsdom/lib/jsdom/living/nodes/Node-impl.js';
6
+ import EventTargetModule from 'jsdom/lib/jsdom/living/events/EventTarget-impl.js';
7
+ import utils from 'jsdom/lib/jsdom/living/generated/utils.js';
8
+ import jsdomPackage from 'jsdom/package.json' with { type: 'json' };
9
+
10
+ let active = false;
11
+ const object = value => value !== null && (typeof value === 'object' || typeof value === 'function');
12
+ const data = (value, key) => {
13
+ if (!object(value)) return;
14
+ const d = Object.getOwnPropertyDescriptor(value, key);
15
+ return d && Object.hasOwn(d, 'value') ? d.value : undefined;
16
+ };
17
+ const sameDescriptor = (a, b) => !!a && !!b && ['value', 'get', 'set', 'writable', 'enumerable', 'configurable']
18
+ .every(key => Object.hasOwn(a, key) === Object.hasOwn(b, key) && Object.is(a[key], b[key]));
19
+
20
+ export function installRuntimeDetachedFrameCompat(window, options = {}) {
21
+ const root = data(window, '_globalObject');
22
+ const limitOption = object(options) ? Object.getOwnPropertyDescriptor(options, 'maximumFrames') : undefined;
23
+ const maximumFrames = limitOption?.value ?? 32;
24
+ if (!object(window) || !object(root) || data(root, '_globalProxy') !== window
25
+ || data(root, '_runScripts') !== 'outside-only' || window.Function === Function
26
+ || !object(options) || limitOption && !Object.hasOwn(limitOption, 'value')
27
+ || !Number.isInteger(maximumFrames) || maximumFrames < 1 || maximumFrames > 32) throw Error('DETACHED_FRAME_INVALID_OPTIONS');
28
+ if (active) throw Error('DETACHED_FRAME_ALREADY_INSTALLED');
29
+ if (jsdomPackage.version !== '26.1.0') throw Error('DETACHED_FRAME_UNSUPPORTED_JSDOM');
30
+ const framePrototype = FrameModule.implementation.prototype;
31
+ const eventPrototype = EventTargetModule.implementation.prototype;
32
+ const hooks = [], records = [], frameRecords = new WeakMap();
33
+ const detachedDocuments = new WeakSet(), detachedWindows = new WeakSet();
34
+ const stats = { diagnosticOnly: true, detachedFrameCompatibility: true, nativeParityProven: false,
35
+ sourcelessLeafFramesOnly: true, maximumFrames, trackedFrames: 0, retainedFrames: 0,
36
+ observedAttachments: 0, skippedUnownedFrames: 0, skippedSourcedFrames: 0,
37
+ skippedUntrackedFrames: 0, skippedChangedFrames: 0, skippedNestedFrames: 0,
38
+ frameLimitReached: false, timerCallsSuppressed: 0, closeCallsSuppressed: 0,
39
+ nodeEventsSuppressed: 0, windowEventsSuppressed: 0, preparationFailures: 0,
40
+ detachFailures: 0, disposed: false, disposedRetainedFrames: 0,
41
+ restoredProperties: 0, restoreConflicts: 0, restoreFailures: 0,
42
+ restoredHooks: 0, hookRestoreConflicts: 0, cleanupFailures: 0, forcedTimerCleanups: 0, hostTimersCreated: 0 };
43
+ const count = key => { stats[key] = Math.min(1000000, stats[key] + 1); };
44
+ let pendingFrame;
45
+ const belongs = doc => {
46
+ let current = data(doc, '_defaultView');
47
+ for (let depth = 0; object(current) && depth < 32; depth++) {
48
+ if (current === window || current === root) return true;
49
+ const next = data(current, '_parent');
50
+ if (next === current) return false;
51
+ current = next;
52
+ }
53
+ return false;
54
+ };
55
+ const eligibleAttributes = frame => data(frame, '_localName') === 'iframe'
56
+ && !frame.hasAttributeNS(null, 'src') && !frame.hasAttributeNS(null, 'srcdoc')
57
+ && !frame.hasAttributeNS(null, 'sandbox');
58
+ const restoreProperties = record => {
59
+ for (let index = record.properties.length - 1; index >= 0; index--) {
60
+ const { target, key, previous, next } = record.properties[index];
61
+ try {
62
+ if (!sameDescriptor(Object.getOwnPropertyDescriptor(target, key), next)) { count('restoreConflicts'); continue; }
63
+ if (previous) Object.defineProperty(target, key, previous); else delete target[key];
64
+ count('restoredProperties');
65
+ } catch { count('restoreFailures'); }
66
+ }
67
+ record.properties.length = 0;
68
+ };
69
+ function prepare(frame, backing) {
70
+ if (records.length >= maximumFrames) { stats.frameLimitReached = true; return; }
71
+ const realm = data(backing, '_globalProxy'), document = data(backing, '_document');
72
+ const doc = object(document) ? utils.implForWrapper(document) : undefined;
73
+ const realmFunction = data(realm, 'Function');
74
+ if (!object(realm) || typeof realmFunction !== 'function' || realmFunction === Function || !object(doc)
75
+ || data(backing, '_runScripts') !== 'outside-only' || doc.URL !== 'about:blank') { count('preparationFailures'); return; }
76
+ const record = { frame, realm, backing, document, doc, windowImpl: utils.implForWrapper(realm),
77
+ detached: false, properties: [], originalClose: data(realm, 'close') };
78
+ const add = (key, next) => {
79
+ const previous = Object.getOwnPropertyDescriptor(realm, key);
80
+ Object.defineProperty(realm, key, next);
81
+ record.properties.push({ target: realm, key, previous, next: Object.getOwnPropertyDescriptor(realm, key) });
82
+ };
83
+ try {
84
+ if (typeof record.originalClose !== 'function' || Reflect.has(realm, 'closed')) throw Error('UNSUPPORTED_FRAME');
85
+ for (const key of ['setTimeout', 'setInterval', 'requestAnimationFrame', 'close']) {
86
+ const previous = Object.getOwnPropertyDescriptor(realm, key);
87
+ if (!previous && key === 'requestAnimationFrame') continue;
88
+ if (!previous || !Object.hasOwn(previous, 'value') || typeof previous.value !== 'function'
89
+ || !previous.configurable) throw Error('UNSUPPORTED_FRAME');
90
+ const invoke = (receiver, args) => {
91
+ if (record.detached) {
92
+ count(key === 'close' ? 'closeCallsSuppressed' : 'timerCallsSuppressed');
93
+ return key === 'close' ? undefined : 0;
94
+ }
95
+ return Reflect.apply(previous.value, receiver, args);
96
+ };
97
+ const wrapper = realmFunction('invoke', 'return function ' + key + '(){ return invoke(this, arguments); };')(invoke);
98
+ Object.defineProperty(wrapper, 'length', { value: previous.value.length, configurable: true });
99
+ add(key, { ...previous, value: wrapper });
100
+ }
101
+ const closed = realmFunction('read', 'return Object.getOwnPropertyDescriptor({get closed(){return read();}}, "closed").get')(() => record.detached);
102
+ add('closed', { get: closed, enumerable: true, configurable: true });
103
+ records.push(record); frameRecords.set(frame, record); count('trackedFrames');
104
+ } catch { restoreProperties(record); count('preparationFailures'); }
105
+ }
106
+ function finishDetached(record) {
107
+ try { Reflect.apply(record.originalClose, record.realm, []); }
108
+ catch {
109
+ count('cleanupFailures');
110
+ // A failing request abort or DOM cleanup must not skip the private timer
111
+ // shutdown later in JSDOM close. Re-enter without the owned document.
112
+ const descriptor = Object.getOwnPropertyDescriptor(record.backing, '_document');
113
+ if (descriptor?.configurable && descriptor.value === record.document) {
114
+ try {
115
+ delete record.backing._document;
116
+ Reflect.apply(record.originalClose, record.realm, []);
117
+ count('forcedTimerCleanups');
118
+ } catch { count('cleanupFailures'); }
119
+ }
120
+ }
121
+ if (!data(record.backing, '_document') && !record.cleaned) { record.cleaned = true; count('disposedRetainedFrames'); }
122
+ detachedDocuments.delete(record.doc); detachedWindows.delete(record.windowImpl);
123
+ }
124
+ const retire = record => { restoreProperties(record); record.retired = true; };
125
+ function dispose() {
126
+ if (stats.disposed) return snapshot();
127
+ stats.disposed = true;
128
+ for (let index = records.length - 1; index >= 0; index--) {
129
+ const record = records[index];
130
+ if (record.detached) finishDetached(record);
131
+ restoreProperties(record);
132
+ }
133
+ records.length = 0; pendingFrame = undefined;
134
+ for (let index = hooks.length - 1; index >= 0; index--) {
135
+ const { target, key, previous, next } = hooks[index];
136
+ try {
137
+ if (sameDescriptor(Object.getOwnPropertyDescriptor(target, key), next)) {
138
+ Object.defineProperty(target, key, previous); count('restoredHooks');
139
+ } else count('hookRestoreConflicts');
140
+ } catch { count('restoreFailures'); }
141
+ }
142
+ hooks.length = 0; active = false;
143
+ return snapshot();
144
+ }
145
+ const snapshot = () => ({ ...stats });
146
+ const hook = (target, key, make) => {
147
+ const previous = Object.getOwnPropertyDescriptor(target, key);
148
+ if (!previous?.writable || typeof previous.value !== 'function') throw Error('UNSUPPORTED_HOOK');
149
+ const next = { ...previous, value: make(previous.value) };
150
+ Object.defineProperty(target, key, next); hooks.push({ target, key, previous, next });
151
+ };
152
+ try {
153
+ hook(framePrototype, '_attach', original => function () {
154
+ if (stats.disposed) return Reflect.apply(original, this, arguments);
155
+ count('observedAttachments');
156
+ const previousPending = pendingFrame;
157
+ pendingFrame = undefined;
158
+ if (!belongs(this._ownerDocument)) count('skippedUnownedFrames');
159
+ else if (!eligibleAttributes(this)) count('skippedSourcedFrames');
160
+ else pendingFrame = this;
161
+ try { return Reflect.apply(original, this, arguments); }
162
+ finally { pendingFrame = previousPending; }
163
+ });
164
+ hook(WindowModule, 'createWindow', original => function () {
165
+ const frame = pendingFrame;
166
+ const result = Reflect.apply(original, this, arguments);
167
+ if (!stats.disposed && frame) prepare(frame, result);
168
+ return result;
169
+ });
170
+ hook(framePrototype, '_detach', original => function () {
171
+ if (stats.disposed) return Reflect.apply(original, this, arguments);
172
+ const record = frameRecords.get(this);
173
+ if (!record) { if (belongs(this._ownerDocument)) count('skippedUntrackedFrames'); return Reflect.apply(original, this, arguments); }
174
+ if (record.detached || record.retired) return Reflect.apply(original, this, arguments);
175
+ if (!eligibleAttributes(this) || this._contentDocument !== record.doc
176
+ || data(record.backing, '_document') !== record.document || record.doc.URL !== 'about:blank'
177
+ || !record.properties.every(item => sameDescriptor(Object.getOwnPropertyDescriptor(item.target, item.key), item.next))) {
178
+ count('skippedChangedFrames'); retire(record); return Reflect.apply(original, this, arguments);
179
+ }
180
+ if (data(record.backing, '_length') !== 0) { count('skippedNestedFrames'); retire(record); return Reflect.apply(original, this, arguments); }
181
+ const previousDocument = Object.getOwnPropertyDescriptor(record.backing, '_document');
182
+ if (!previousDocument?.writable || !previousDocument.configurable) { count('detachFailures'); retire(record); return Reflect.apply(original, this, arguments); }
183
+ try {
184
+ record.detached = true;
185
+ detachedDocuments.add(record.doc); detachedWindows.add(record.windowImpl);
186
+ // JSDOM's own close cancels its private timers and sockets. Temporarily
187
+ // omit only the internal document slot so it cannot erase the DOM tree.
188
+ Object.defineProperty(record.backing, '_document', { ...previousDocument, value: undefined });
189
+ try { Reflect.apply(record.originalClose, record.realm, []); }
190
+ finally { Object.defineProperty(record.backing, '_document', previousDocument); }
191
+ record.doc._requestManager?.close();
192
+ record.doc._defaultView = null;
193
+ record.doc._clearBaseURLCache();
194
+ record.backing._parent = null; record.backing._top = null; record.backing._frameElement = null;
195
+ this._contentDocument = null;
196
+ count('retainedFrames');
197
+ } catch {
198
+ count('detachFailures'); finishDetached(record); retire(record);
199
+ }
200
+ return Reflect.apply(original, this, arguments);
201
+ });
202
+ hook(eventPrototype, '_dispatch', original => function () {
203
+ if (!stats.disposed) {
204
+ if (detachedWindows.has(this)) { count('windowEventsSuppressed'); return true; }
205
+ if (NodeModule.implementation.prototype.isPrototypeOf(this) && detachedDocuments.has(this._ownerDocument)) {
206
+ count('nodeEventsSuppressed'); return false;
207
+ }
208
+ }
209
+ return Reflect.apply(original, this, arguments);
210
+ });
211
+ active = true;
212
+ return { snapshot, dispose };
213
+ } catch { dispose(); throw Error('DETACHED_FRAME_INSTALL_FAILED'); }
214
+ }
@@ -0,0 +1,69 @@
1
+ // JavaScript WebIDL receiver checks for the owned JSDOM runtime. Valid calls
2
+ // delegate to JSDOM; invalid calls throw the declaring window's TypeError.
3
+ // Function.prototype.toString and host intrinsics are left unchanged.
4
+ import WindowModule from 'jsdom/lib/jsdom/browser/Window.js';
5
+ import NavigatorModule from 'jsdom/lib/jsdom/living/generated/Navigator.js';
6
+ import MediaModule from 'jsdom/lib/jsdom/living/generated/HTMLMediaElement.js';
7
+ import jsdomPackage from 'jsdom/package.json' with { type: 'json' };
8
+ const own=Object.getOwnPropertyDescriptor,define=Object.defineProperty,apply=Reflect.apply;
9
+ const active=new WeakSet();let childHookActive=false;
10
+ const same=(a,b)=>!!a&&!!b&&['value','get','set','writable','enumerable','configurable'].every(k=>Object.hasOwn(a,k)===Object.hasOwn(b,k)&&a[k]===b[k]);
11
+ export function installJavascriptBindings(window,{children=false}={}) {
12
+ if(jsdomPackage.version!=='26.1.0'||!window||active.has(window)||typeof children!=='boolean'||children&&childHookActive)throw Error('JS_BINDING_OPTIONS_INVALID');
13
+ const previousFactory=children?own(WindowModule,'createWindow'):undefined;
14
+ if(children&&(!previousFactory?.writable||typeof previousFactory.value!=='function'))throw Error('JS_BINDING_FACTORY_UNAVAILABLE');
15
+ const records=[];let disposed=false,installedFactory;
16
+ const stats={realms:0,childRealms:0,installedDescriptors:0,calls:0,rejectedReceivers:0,returned:0,delegatedThrows:0,
17
+ childFailures:0,realmLimitReached:false,restoredDescriptors:0,restoreConflicts:0,restoreFailures:0,childFactoryRestored:false};
18
+ const snapshot=()=>({...stats,javascriptOnly:true,nativeAddonUsed:false,functionToStringOverridden:false,disposed});
19
+ const installRealm=realm=>{
20
+ if(active.has(realm))return;
21
+ if(records.length>=32){stats.realmLimitReached=true;return;}
22
+ if(typeof realm.Function!=='function'||realm.Function===Function)throw Error('JS_BINDING_REALM_INVALID');
23
+ const record={realm,bindings:[]};records.push(record);active.add(realm);stats.realms++;if(realm!==window)stats.childRealms++;
24
+ const RealmError=realm.TypeError,captureStack=realm.Error.captureStackTrace,NavigatorPrototype=realm.Navigator.prototype,MediaPrototype=realm.HTMLMediaElement.prototype;
25
+ const install=(target,key,kind,predicate,fallback)=>{
26
+ const previous=own(target,key),original=fallback??previous?.[kind];
27
+ if(typeof original!=='function'||previous&&!previous.configurable&&!previous.writable)throw Error('JS_BINDING_DESCRIPTOR_INVALID');
28
+ const wrapper=new realm.Proxy(original,{apply:function invokeBinding(fn,receiver,args){
29
+ stats.calls++;
30
+ if(!predicate(receiver)){
31
+ stats.rejectedReceivers++;
32
+ const error=new RealmError('Illegal invocation');
33
+ captureStack(error,invokeBinding);
34
+ throw error;
35
+ }
36
+ try{const result=apply(fn,receiver,args);stats.returned++;return result;}catch(error){stats.delegatedThrows++;throw error;}
37
+ }});
38
+ const installed=previous?{...previous,[kind]:wrapper}:{configurable:true,enumerable:true,get:wrapper,set:undefined};
39
+ define(target,key,installed);record.bindings.push({target,key,previous,installed});stats.installedDescriptors++;
40
+ };
41
+ install(NavigatorPrototype,'plugins','get',NavigatorModule.is);
42
+ install(NavigatorPrototype,'mimeTypes','get',NavigatorModule.is);
43
+ const falseGetter=realm.eval('Object.getOwnPropertyDescriptor({get webdriver(){return false}},"webdriver").get');
44
+ install(NavigatorPrototype,'webdriver','get',NavigatorModule.is,falseGetter);
45
+ install(MediaPrototype,'canPlayType','value',MediaModule.is);
46
+ };
47
+ const dispose=()=>{
48
+ if(disposed)return snapshot();disposed=true;
49
+ if(installedFactory){try{if(same(own(WindowModule,'createWindow'),installedFactory)){define(WindowModule,'createWindow',previousFactory);stats.childFactoryRestored=true;}else stats.restoreConflicts++;}catch{stats.restoreFailures++;}childHookActive=false;}
50
+ for(const record of [...records].reverse()){
51
+ for(const binding of [...record.bindings].reverse())try{
52
+ if(!same(own(binding.target,binding.key),binding.installed)){stats.restoreConflicts++;continue;}
53
+ if(binding.previous)define(binding.target,binding.key,binding.previous);else if(!Reflect.deleteProperty(binding.target,binding.key))throw Error('JS_BINDING_DELETE_FAILED');
54
+ stats.restoredDescriptors++;
55
+ }catch{stats.restoreFailures++;}
56
+ active.delete(record.realm);
57
+ }
58
+ return snapshot();
59
+ };
60
+ try{
61
+ installRealm(window);
62
+ if(children){installedFactory={...previousFactory,value:function createWindowWithJavascriptBindings(options){
63
+ const child=apply(previousFactory.value,this,arguments);
64
+ if(!disposed&&options&&own(options,'parentOrigin')&&options.runScripts==='outside-only')try{installRealm(own(child,'_globalProxy')?.value);}catch{stats.childFailures++;}
65
+ return child;
66
+ }};define(WindowModule,'createWindow',installedFactory);childHookActive=true;}
67
+ return Object.freeze({snapshot,dispose});
68
+ }catch(error){dispose();throw error;}
69
+ }
@@ -0,0 +1,99 @@
1
+ // Optional, source-derived consistency for two EXISTING legacy properties.
2
+ // Uses the pinned per-navigator implementation; public getters stay original.
3
+ import WindowModule from 'jsdom/lib/jsdom/browser/Window.js';
4
+ import NavigatorModule from 'jsdom/lib/jsdom/living/navigator/Navigator-impl.js';
5
+ import utils from 'jsdom/lib/jsdom/living/generated/utils.js';
6
+ import jsdomPackage from 'jsdom/package.json' with { type: 'json' };
7
+
8
+ const MAX_REALMS=32,MAX_UA_LENGTH=8192;
9
+ const activeWindows=new WeakSet();let activeChildHook=false;
10
+ const isObject=value=>value!==null&&(typeof value==='object'||typeof value==='function');
11
+ const ownData=(object,key)=>{const d=Object.getOwnPropertyDescriptor(object,key);return d&&Object.hasOwn(d,'value')?d.value:undefined;};
12
+ const sameDescriptor=(a,b)=>!!a&&!!b&&['value','get','set','writable','enumerable','configurable'].every(key=>Object.hasOwn(a,key)===Object.hasOwn(b,key)&&a[key]===b[key]);
13
+ const ERROR_CODES=new Set(['INVALID_OPTIONS','UNSUPPORTED_JSDOM','UNSUPPORTED_REALM','ALREADY_INSTALLED','CHILD_HOOK_ALREADY_INSTALLED','INSTALL_FAILED']);
14
+ export class RuntimeNavigatorCompatError extends Error{constructor(code){const safe=ERROR_CODES.has(code)?code:'INSTALL_FAILED';super('Navigator compatibility failed: '+safe);this.name='RuntimeNavigatorCompatError';this.code=safe;}}
15
+
16
+ export function installRuntimeNavigatorCompat(window,options={}){
17
+ if(!isObject(window)||!options||typeof options!=='object')throw new RuntimeNavigatorCompatError('INVALID_OPTIONS');
18
+ const option=Object.getOwnPropertyDescriptor(options,'children');
19
+ if(option&&!Object.hasOwn(option,'value'))throw new RuntimeNavigatorCompatError('INVALID_OPTIONS');
20
+ const children=option?.value??false;if(typeof children!=='boolean')throw new RuntimeNavigatorCompatError('INVALID_OPTIONS');
21
+ if(jsdomPackage.version!=='26.1.0')throw new RuntimeNavigatorCompatError('UNSUPPORTED_JSDOM');
22
+ if(activeWindows.has(window))throw new RuntimeNavigatorCompatError('ALREADY_INSTALLED');
23
+ if(children&&activeChildHook)throw new RuntimeNavigatorCompatError('CHILD_HOOK_ALREADY_INSTALLED');
24
+ const factoryDescriptor=children?Object.getOwnPropertyDescriptor(WindowModule,'createWindow'):undefined;
25
+ if(children&&(!factoryDescriptor?.writable||typeof factoryDescriptor.value!=='function'))throw new RuntimeNavigatorCompatError('UNSUPPORTED_JSDOM');
26
+ const saved=[],realms=[];let disposed=false,factoryWrapper;
27
+ const stats={diagnosticOnly:true,legacyNavigatorConsistency:true,sourceDerivedFromSuppliedUserAgent:true,
28
+ publicGetterFunctionsChanged:false,publicDescriptorsChanged:false,nativeSourceForged:false,userAgentModified:false,
29
+ userAgentDataAdded:false,otherNavigatorPropertiesModified:false,maximumRealms:MAX_REALMS,childrenEnabled:children,
30
+ visitedRealms:0,eligibleChromeRealms:0,skippedNonChromeRealms:0,invalidUserAgents:0,wrapperValueConflicts:0,
31
+ correctedRealms:0,appVersionCorrections:0,vendorCorrections:0,alreadyConsistentProperties:0,
32
+ unsupportedProperties:0,mutationFailures:0,observedChildren:0,skippedFactories:0,unsupportedChildren:0,
33
+ childFailures:0,realmLimitReached:false,restoredProperties:0,restoreConflicts:0,restoreFailures:0,
34
+ childFactoryRestored:false,childFactoryRestoreConflict:false,disposed:false};
35
+ const increment=key=>{stats[key]=Math.min(1000000,stats[key]+1);};
36
+
37
+ function installRealm(realm){
38
+ if(realms.length>=MAX_REALMS){stats.realmLimitReached=true;return;}
39
+ if(activeWindows.has(realm))throw new RuntimeNavigatorCompatError('ALREADY_INSTALLED');
40
+ const realmFunction=ownData(realm,'Function');
41
+ if(typeof realmFunction!=='function'||realmFunction===Function)throw new RuntimeNavigatorCompatError('UNSUPPORTED_REALM');
42
+ const navigator=realm.navigator,impl=isObject(navigator)?ownData(navigator,utils.implSymbol):undefined;
43
+ const backing=ownData(realm,'_globalObject');
44
+ if(!isObject(impl)||!Object.prototype.isPrototypeOf.call(NavigatorModule.implementation.prototype,impl)
45
+ ||ownData(impl,'_globalObject')!==backing||ownData(backing,'_globalProxy')!==realm)throw new RuntimeNavigatorCompatError('UNSUPPORTED_REALM');
46
+ realms.push(realm);activeWindows.add(realm);increment('visitedRealms');
47
+ // Navigator-impl receives precisely this own data value from the supplied
48
+ // ResourceLoader. Do not manufacture a user agent or read browser storage.
49
+ const ua=ownData(impl,'userAgent');
50
+ if(typeof ua!=='string'||ua.length>MAX_UA_LENGTH){increment('invalidUserAgents');return;}
51
+ if(navigator.userAgent!==ua){increment('wrapperValueConflicts');return;}
52
+ if(!ua.startsWith('Mozilla/')||!/(?:^|\s)Chrome\/\d+(?:\.\d+){1,3}(?:\s|$)/.test(ua)){increment('skippedNonChromeRealms');return;}
53
+ increment('eligibleChromeRealms');let corrected=0;
54
+ for(const [key,value,counter] of [['appVersion',ua.slice(8),'appVersionCorrections'],['vendor','Google Inc.','vendorCorrections']]){
55
+ const previous=Object.getOwnPropertyDescriptor(impl,key);
56
+ const inherited=Object.getOwnPropertyDescriptor(NavigatorModule.implementation.prototype,key);
57
+ if(previous&&!Object.hasOwn(previous,'value')||!previous&&typeof inherited?.get!=='function'){
58
+ increment('unsupportedProperties');continue;
59
+ }
60
+ const current=previous?previous.value:Reflect.apply(inherited.get,impl,[]);
61
+ if(navigator[key]!==current){increment('wrapperValueConflicts');continue;}
62
+ if(current===value){increment('alreadyConsistentProperties');continue;}
63
+ if(previous&&!previous.configurable&&!previous.writable||!previous&&!Object.isExtensible(impl)){
64
+ increment('unsupportedProperties');continue;
65
+ }
66
+ const next=previous?{...previous,value}:{value,writable:true,enumerable:true,configurable:true};
67
+ try{Object.defineProperty(impl,key,next);saved.push({impl,key,previous,next});increment(counter);corrected++;}
68
+ catch{increment('mutationFailures');}
69
+ }
70
+ if(corrected>0)increment('correctedRealms');
71
+ }
72
+ function dispose(){
73
+ if(disposed)return;disposed=true;stats.disposed=true;
74
+ if(factoryWrapper){const current=Object.getOwnPropertyDescriptor(WindowModule,'createWindow');
75
+ if(current?.value===factoryWrapper){try{Object.defineProperty(WindowModule,'createWindow',factoryDescriptor);stats.childFactoryRestored=true;}catch{stats.childFactoryRestoreConflict=true;}}
76
+ else stats.childFactoryRestoreConflict=true;activeChildHook=false;
77
+ }
78
+ for(let i=saved.length-1;i>=0;i--){const {impl,key,previous,next}=saved[i];
79
+ try{if(!sameDescriptor(Object.getOwnPropertyDescriptor(impl,key),next)){increment('restoreConflicts');continue;}
80
+ if(previous)Object.defineProperty(impl,key,previous);else delete impl[key];increment('restoredProperties');
81
+ }catch{increment('restoreFailures');}}
82
+ saved.length=0;for(const realm of realms)activeWindows.delete(realm);realms.length=0;
83
+ }
84
+ try{
85
+ installRealm(window);
86
+ if(children){const original=factoryDescriptor.value;
87
+ factoryWrapper=function createWindowWithNavigatorConsistency(factoryOptions){
88
+ const child=Reflect.apply(original,this,arguments);if(disposed)return child;
89
+ if(!factoryOptions||!Object.hasOwn(factoryOptions,'parentOrigin')){increment('skippedFactories');return child;}
90
+ increment('observedChildren');if(ownData(factoryOptions,'runScripts')!=='outside-only'){increment('unsupportedChildren');return child;}
91
+ if(realms.length>=MAX_REALMS){stats.realmLimitReached=true;return child;}
92
+ try{const proxy=ownData(child,'_globalProxy');if(!proxy){increment('unsupportedChildren');return child;}installRealm(proxy);}catch{increment('childFailures');}
93
+ return child;
94
+ };
95
+ Object.defineProperty(WindowModule,'createWindow',{...factoryDescriptor,value:factoryWrapper});activeChildHook=true;
96
+ }
97
+ }catch(error){dispose();throw error instanceof RuntimeNavigatorCompatError?error:new RuntimeNavigatorCompatError('INSTALL_FAILED');}
98
+ return{snapshot(){return{...stats};},dispose};
99
+ }
@@ -0,0 +1,64 @@
1
+ // Abstract Permissions interface only. No Permissions instances are issued.
2
+ // Self-contained: root may serialize this installer into another owned realm.
3
+ export function installRuntimePermissionsBinding(window) {
4
+ if (window === null || (typeof window !== 'object' && typeof window !== 'function')) {
5
+ throw new TypeError('Invalid Permissions binding realm');
6
+ }
7
+ const own = Object.getOwnPropertyDescriptor;
8
+ const stats = {
9
+ abstractInterface: true, instancesProvisioned: 0, bindingInstalled: false,
10
+ existingBindingPreserved: false, sourceRenderingModified: false,
11
+ disposed: false, bindingRemoved: false, cleanupConflict: false,
12
+ };
13
+ let Constructor;
14
+ const snapshot = () => ({ ...stats });
15
+ const dispose = () => {
16
+ if (stats.disposed) return snapshot();
17
+ stats.disposed = true;
18
+ if (!stats.bindingInstalled) return snapshot();
19
+ const current = own(window, 'Permissions');
20
+ if (!current) return snapshot();
21
+ if (current.value !== Constructor || current.writable !== true || current.configurable !== true || current.enumerable !== false) {
22
+ stats.cleanupConflict = true;
23
+ return snapshot();
24
+ }
25
+ try { stats.bindingRemoved = Reflect.deleteProperty(window, 'Permissions'); }
26
+ catch { stats.bindingRemoved = false; }
27
+ stats.cleanupConflict = !stats.bindingRemoved;
28
+ return snapshot();
29
+ };
30
+ const api = Object.freeze({ snapshot, dispose });
31
+ // Preserve existing own or inherited bindings, including accessors, without
32
+ // invoking them or claiming ownership of them.
33
+ if ('Permissions' in window) { stats.existingBindingPreserved = true; return api; }
34
+ const RealmFunction = own(window, 'Function')?.value;
35
+ if (typeof RealmFunction !== 'function') throw new TypeError('Invalid Permissions binding realm');
36
+ const create = RealmFunction([
37
+ '"use strict";',
38
+ 'const RealmTypeError = TypeError;',
39
+ 'const RealmPromise = Promise;',
40
+ 'function Permissions() {',
41
+ ' throw new RealmTypeError(new.target ? "Failed to construct \'Permissions\': Illegal constructor" : "Illegal constructor");',
42
+ '}',
43
+ // Every receiver is unbranded because this binding provisions no instances.
44
+ // Reject before reading or converting any argument, including missing ones.
45
+ 'const prototype = { query(descriptor) {',
46
+ ' return new RealmPromise((resolve, reject) => {',
47
+ ' reject(new RealmTypeError("Failed to execute \'query\' on \'Permissions\': Illegal invocation"));',
48
+ ' });',
49
+ '} };',
50
+ 'Object.defineProperty(prototype, "constructor", { value: Permissions, writable: true, enumerable: false, configurable: true });',
51
+ 'Object.defineProperty(prototype, Symbol.toStringTag, { value: "Permissions", writable: false, enumerable: false, configurable: true });',
52
+ 'Object.defineProperty(Permissions, "prototype", { value: prototype, writable: false, enumerable: false, configurable: false });',
53
+ 'return { Constructor: Permissions, realm: globalThis };',
54
+ ].join('\n'));
55
+ const created = create();
56
+ // A JSDOM window without an isolated scripting realm would otherwise create
57
+ // host functions and errors. Do not install that misleading shape.
58
+ if (created.realm !== window || typeof created.Constructor !== 'function') throw new TypeError('Invalid Permissions binding realm');
59
+ if ('Permissions' in window) { stats.existingBindingPreserved = true; return api; }
60
+ Constructor = created.Constructor;
61
+ Object.defineProperty(window, 'Permissions', { value: Constructor, writable: true, enumerable: false, configurable: true });
62
+ stats.bindingInstalled = true;
63
+ return api;
64
+ }