@luckylillia-dev/plugin-aiimgdetector 0.0.0-placeholder → 1.0.4

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 +77 -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,151 @@
1
+ // Optional diagnostic: empty realm-owned Proxy forwarding of existing APIs.
2
+ // Proxy source rendering is NOT proof of a native implementation or browser.
3
+ import WindowModule from 'jsdom/lib/jsdom/browser/Window.js';
4
+ import webIdlUtils from 'jsdom/lib/jsdom/living/generated/utils.js';
5
+ import jsdomPackage from 'jsdom/package.json' with { type: 'json' };
6
+ import { createHash } from 'node:crypto';
7
+ import { webIdlConstructorNames } from './webidl-realm-catalog.mjs';
8
+ import { webIdlCallableSourceHashes } from './webidl-callable-source-catalog.mjs';
9
+
10
+ const MAX_REALMS=32,MAX_CALLABLES=10000,MAX_OWN_KEYS=4096,MAX_SOURCE_LENGTH=1000000;
11
+ const sourceHashes=new Set(webIdlCallableSourceHashes),hostToString=Function.prototype.toString;
12
+ const activeWindows=new WeakSet();let activeChildHook=false;
13
+ const isObject=value=>value!==null&&(typeof value==='object'||typeof value==='function');
14
+ const ownData=(object,key)=>{const d=Object.getOwnPropertyDescriptor(object,key);return d&&Object.hasOwn(d,'value')?d.value:undefined;};
15
+ 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]);
16
+ const ERROR_CODES=new Set(['INVALID_OPTIONS','UNSUPPORTED_JSDOM','UNSUPPORTED_REALM','REALM_COMPAT_REQUIRED','ALREADY_INSTALLED','CHILD_HOOK_ALREADY_INSTALLED','INSTALL_FAILED']);
17
+ export class WebIdlCallableControlError extends Error{constructor(code){const safe=ERROR_CODES.has(code)?code:'INSTALL_FAILED';super('WebIDL callable control failed: '+safe);this.name='WebIdlCallableControlError';this.code=safe;}}
18
+
19
+ /** Install before official/page code, AFTER WebIDL realm compatibility.
20
+ * Dispose in the reverse order: this controller before realm compatibility.
21
+ * Source hashes only reject overwritten or newly added page callbacks. They
22
+ * are not independent proof of function ownership or internal [[Realm]]. */
23
+ export function installWebIdlCallableControl(window,options={}){
24
+ if(!isObject(window)||!options||typeof options!=='object')throw new WebIdlCallableControlError('INVALID_OPTIONS');
25
+ const childrenDescriptor=Object.getOwnPropertyDescriptor(options,'children');
26
+ if(childrenDescriptor&&!Object.hasOwn(childrenDescriptor,'value'))throw new WebIdlCallableControlError('INVALID_OPTIONS');
27
+ const children=childrenDescriptor?.value??false;
28
+ if(typeof children!=='boolean')throw new WebIdlCallableControlError('INVALID_OPTIONS');
29
+ if(jsdomPackage.version!=='26.1.0')throw new WebIdlCallableControlError('UNSUPPORTED_JSDOM');
30
+ if(activeWindows.has(window))throw new WebIdlCallableControlError('ALREADY_INSTALLED');
31
+ if(children&&activeChildHook)throw new WebIdlCallableControlError('CHILD_HOOK_ALREADY_INSTALLED');
32
+ const factoryDescriptor=children?Object.getOwnPropertyDescriptor(WindowModule,'createWindow'):undefined;
33
+ if(children&&(!factoryDescriptor?.writable||typeof factoryDescriptor.value!=='function'))throw new WebIdlCallableControlError('UNSUPPORTED_JSDOM');
34
+ const realms=[],saved=[],callables=new WeakMap();let disposed=false,factoryWrapper;
35
+ const stats={diagnosticOnly:true,proxyCallableSimulation:true,nativeIdentityProven:false,functionInternalRealmChanged:false,
36
+ callableIdentitiesChanged:true,sourceRenderingModified:true,functionToStringOverridden:false,nativeSourceStringsInvented:false,
37
+ officialCodeChanged:false,hostIntrinsicsModified:false,absentApisAdded:0,pageCallbacksWrapped:0,sourceCatalogPinned:true,
38
+ maximumRealms:MAX_REALMS,maximumCallables:MAX_CALLABLES,childrenEnabled:children,installedRealms:0,observedChildren:0,skippedFactories:0,
39
+ unsupportedChildren:0,childFailures:0,realmLimitReached:false,callableLimitReached:false,descriptorLimitReached:false,
40
+ constructorsFound:0,callablesObserved:0,proxiesCreated:0,sourceMismatchesSkipped:0,sourceReadFailures:0,
41
+ sharedCallableConflicts:0,nonRealmFunctionsSkipped:0,descriptorsChanged:0,invariantDescriptorsSkipped:0,
42
+ inheritedConstructorParentsChanged:0,nonExtensibleConstructorsSkipped:0,inspectionFailures:0,mutationFailures:0,
43
+ restoredDescriptors:0,restoredConstructorParents:0,restoreConflicts:0,restoreFailures:0,
44
+ childFactoryRestored:false,childFactoryRestoreConflict:false,disposed:false};
45
+ const increment=key=>{stats[key]=Math.min(1000000,stats[key]+1);};
46
+
47
+ function installRealm(realm){
48
+ if(realms.length>=MAX_REALMS){stats.realmLimitReached=true;return;}
49
+ if(activeWindows.has(realm))throw new WebIdlCallableControlError('ALREADY_INSTALLED');
50
+ const realmFunction=ownData(realm,'Function'),realmFunctionPrototype=isObject(realmFunction)?ownData(realmFunction,'prototype'):undefined;
51
+ const realmProxy=ownData(realm,'Proxy'),registry=ownData(realm,webIdlUtils.ctorRegistrySymbol);
52
+ if(typeof realmFunction!=='function'||realmFunction===Function||typeof realmProxy!=='function'||realmProxy===Proxy||!isObject(registry)||Object.getPrototypeOf(registry)!==null)throw new WebIdlCallableControlError('UNSUPPORTED_REALM');
53
+ const eventTarget=ownData(registry,'EventTarget');
54
+ if(typeof eventTarget!=='function'||Object.getPrototypeOf(eventTarget)!==realmFunctionPrototype)throw new WebIdlCallableControlError('REALM_COMPAT_REQUIRED');
55
+ // Compile only this fixed, public helper in the existing isolated realm.
56
+ // Its handler has no traps or inherited trap properties; nothing is added
57
+ // to the page global and no page callable is invoked during installation.
58
+ const makeProxy=Reflect.apply(realmFunction,undefined,['return function(original){ return new Proxy(original, Object.create(null)); };'])();
59
+ const owner={realm,realmFunctionPrototype,makeProxy};realms.push(owner);activeWindows.add(realm);increment('installedRealms');
60
+ const constructors=new Set();
61
+ for(const name of webIdlConstructorNames){const ctor=ownData(registry,name);if(typeof ctor==='function')constructors.add(ctor);}
62
+ const windowPrototype=Object.getPrototypeOf(realm),windowConstructor=isObject(windowPrototype)?ownData(windowPrototype,'constructor'):undefined;
63
+ if(typeof windowConstructor==='function'&&Object.getPrototypeOf(windowConstructor)===eventTarget&&ownData(windowConstructor,'prototype')===windowPrototype)constructors.add(windowConstructor);
64
+ for(const [alias,target] of [['Image','HTMLImageElement'],['Audio','HTMLAudioElement'],['Option','HTMLOptionElement']]){
65
+ const candidate=ownData(realm,alias),registered=ownData(registry,target);
66
+ if(typeof candidate==='function'&&typeof registered==='function'&&ownData(candidate,'name')===alias&&ownData(candidate,'prototype')===ownData(registered,'prototype'))constructors.add(candidate);
67
+ }
68
+ stats.constructorsFound=Math.min(1000000,stats.constructorsFound+constructors.size);
69
+ function proxyFor(fn){
70
+ if(typeof fn!=='function')return fn;
71
+ const seen=callables.get(fn);
72
+ if(seen){if(seen.owner!==owner){increment('sharedCallableConflicts');return fn;}return seen.proxy;}
73
+ if(stats.callablesObserved>=MAX_CALLABLES){stats.callableLimitReached=true;return fn;}
74
+ increment('callablesObserved');const entry={owner,proxy:fn};callables.set(fn,entry);
75
+ const parent=Object.getPrototypeOf(fn);
76
+ if(parent!==realmFunctionPrototype&&!constructors.has(parent)){increment('nonRealmFunctionsSkipped');return fn;}
77
+ // The trust anchor remains the per-window constructor registry. Public
78
+ // pristine-source fingerprints additionally reject replaced callbacks,
79
+ // compat shims and already proxied functions. Never retain candidate text.
80
+ try{const source=Reflect.apply(hostToString,fn,[]);
81
+ if(source.length>MAX_SOURCE_LENGTH||!sourceHashes.has(createHash('sha256').update(source).digest('hex'))){increment('sourceMismatchesSkipped');return fn;}
82
+ }catch{increment('sourceReadFailures');return fn;}
83
+ entry.proxy=Reflect.apply(makeProxy,undefined,[fn]);increment('proxiesCreated');return entry.proxy;
84
+ }
85
+ function replaceDescriptor(object,key,previous,next){
86
+ if(sameDescriptor(previous,next))return;
87
+ if(!previous.configurable&&(!Object.hasOwn(previous,'value')||!previous.writable)){increment('invariantDescriptorsSkipped');return;}
88
+ try{Object.defineProperty(object,key,next);saved.push({kind:'descriptor',object,key,previous,next});increment('descriptorsChanged');}
89
+ catch{increment('mutationFailures');}
90
+ }
91
+ const inspected=new WeakSet();
92
+ function inspectOwn(object){
93
+ if(!isObject(object)||inspected.has(object))return;inspected.add(object);
94
+ try{const keys=Reflect.ownKeys(object);if(keys.length>MAX_OWN_KEYS){stats.descriptorLimitReached=true;return;}
95
+ for(const key of keys){if(stats.callableLimitReached)return;const previous=Object.getOwnPropertyDescriptor(object,key);if(!previous)continue;
96
+ const next={...previous};for(const field of ['value','get','set'])if(typeof previous[field]==='function')next[field]=proxyFor(previous[field]);
97
+ replaceDescriptor(object,key,previous,next);}
98
+ }catch{increment('inspectionFailures');}
99
+ }
100
+ // Make all constructor proxies before altering inheritance, so every
101
+ // derived constructor still passes the original ownership check.
102
+ for(const ctor of constructors)proxyFor(ctor);
103
+ for(const ctor of constructors){inspectOwn(ctor);inspectOwn(ownData(ctor,'prototype'));}
104
+ // Keep internal construction, aliases and visible constructor identities
105
+ // consistent. Only own descriptors for the trusted standard names qualify.
106
+ for(const name of webIdlConstructorNames)for(const object of [registry,realm]){
107
+ const previous=Object.getOwnPropertyDescriptor(object,name);
108
+ if(!previous||!Object.hasOwn(previous,'value')||!constructors.has(previous.value))continue;
109
+ replaceDescriptor(object,name,previous,{...previous,value:proxyFor(previous.value)});
110
+ }
111
+ for(const ctor of constructors){
112
+ const previous=Object.getPrototypeOf(ctor),next=callables.get(previous)?.proxy;
113
+ if(!constructors.has(previous)||!next||previous===next)continue;
114
+ if(!Object.isExtensible(ctor)){increment('nonExtensibleConstructorsSkipped');continue;}
115
+ try{Object.setPrototypeOf(ctor,next);saved.push({kind:'parent',object:ctor,previous,next});increment('inheritedConstructorParentsChanged');}
116
+ catch{increment('mutationFailures');}
117
+ }
118
+ }
119
+
120
+ function dispose(){
121
+ if(disposed)return;disposed=true;stats.disposed=true;
122
+ if(factoryWrapper){const current=Object.getOwnPropertyDescriptor(WindowModule,'createWindow');
123
+ if(current?.value===factoryWrapper){try{Object.defineProperty(WindowModule,'createWindow',factoryDescriptor);stats.childFactoryRestored=true;}catch{stats.childFactoryRestoreConflict=true;}}
124
+ else stats.childFactoryRestoreConflict=true;activeChildHook=false;
125
+ }
126
+ for(let i=saved.length-1;i>=0;i--){const change=saved[i];
127
+ try{if(change.kind==='parent'){
128
+ if(Object.getPrototypeOf(change.object)!==change.next){increment('restoreConflicts');continue;}
129
+ Object.setPrototypeOf(change.object,change.previous);increment('restoredConstructorParents');
130
+ }else{
131
+ if(!sameDescriptor(Object.getOwnPropertyDescriptor(change.object,change.key),change.next)){increment('restoreConflicts');continue;}
132
+ Object.defineProperty(change.object,change.key,change.previous);increment('restoredDescriptors');
133
+ }}catch{increment('restoreFailures');}}
134
+ saved.length=0;for(const owner of realms)activeWindows.delete(owner.realm);realms.length=0;
135
+ }
136
+ try{
137
+ installRealm(window);
138
+ if(children){const original=factoryDescriptor.value;
139
+ factoryWrapper=function createWindowWithWebIdlCallableControl(factoryOptions){
140
+ const child=Reflect.apply(original,this,arguments);if(disposed)return child;
141
+ if(!factoryOptions||!Object.hasOwn(factoryOptions,'parentOrigin')){increment('skippedFactories');return child;}
142
+ increment('observedChildren');if(ownData(factoryOptions,'runScripts')!=='outside-only'){increment('unsupportedChildren');return child;}
143
+ if(realms.length>=MAX_REALMS){stats.realmLimitReached=true;return child;}
144
+ try{const proxy=ownData(child,'_globalProxy');if(!proxy){increment('unsupportedChildren');return child;}installRealm(proxy);}catch{increment('childFailures');}
145
+ return child;
146
+ };
147
+ Object.defineProperty(WindowModule,'createWindow',{...factoryDescriptor,value:factoryWrapper});activeChildHook=true;
148
+ }
149
+ }catch(error){dispose();throw error instanceof WebIdlCallableControlError?error:new WebIdlCallableControlError('INSTALL_FAILED');}
150
+ return{snapshot(){return{...stats};},dispose};
151
+ }
@@ -0,0 +1,132 @@
1
+ // Correct prototype chains of existing per-window JSDOM WebIDL functions.
2
+ // No callable replacement, proxy, source rendering change or new API surface.
3
+ import WindowModule from 'jsdom/lib/jsdom/browser/Window.js';
4
+ import webIdlUtils from 'jsdom/lib/jsdom/living/generated/utils.js';
5
+ import jsdomPackage from 'jsdom/package.json' with { type: 'json' };
6
+ import { webIdlConstructorNames } from './webidl-realm-catalog.mjs';
7
+
8
+ const HOST_FUNCTION_PROTOTYPE=Function.prototype;
9
+ const MAX_REALMS=32,MAX_CALLABLES=10000,MAX_OWN_KEYS=4096;
10
+ const activeWindows=new WeakSet();let activeChildHook=false;
11
+ const ERROR_CODES=new Set(['INVALID_OPTIONS','UNSUPPORTED_JSDOM','UNSUPPORTED_REALM','ALREADY_INSTALLED','CHILD_HOOK_ALREADY_INSTALLED','INSTALL_FAILED']);
12
+ export class WebIdlRealmCompatError extends Error{constructor(code){const safe=ERROR_CODES.has(code)?code:'INSTALL_FAILED';super('WebIDL realm compatibility failed: '+safe);this.name='WebIdlRealmCompatError';this.code=safe;}}
13
+ const ownData=(object,key)=>{const descriptor=Object.getOwnPropertyDescriptor(object,key);return descriptor&&Object.hasOwn(descriptor,'value')?descriptor.value:undefined;};
14
+ const isObject=value=>value!==null&&(typeof value==='object'||typeof value==='function');
15
+ const JS_INTRINSICS=['Object','Function','Array','Number','String','Boolean','BigInt','Date','RegExp','Promise','Map','Set','WeakMap','WeakSet','Symbol','Reflect','Intl','JSON','Math','Error','TypeError','RangeError','ReferenceError','SyntaxError','EvalError','URIError','AggregateError','ArrayBuffer','SharedArrayBuffer','DataView','Int8Array','Uint8Array','Uint8ClampedArray','Int16Array','Uint16Array','Int32Array','Uint32Array','Float16Array','Float32Array','Float64Array','BigInt64Array','BigUint64Array','Proxy','WeakRef','FinalizationRegistry','Atomics','WebAssembly','eval'];
16
+ const EXCLUDED_NAMES=new Set(JS_INTRINSICS);
17
+ const protectedHostFunctions=new Set([HOST_FUNCTION_PROTOTYPE]);
18
+ for(const name of JS_INTRINSICS){
19
+ const intrinsic=ownData(globalThis,name);if(!isObject(intrinsic))continue;if(typeof intrinsic==='function')protectedHostFunctions.add(intrinsic);
20
+ for(const object of [intrinsic,ownData(intrinsic,'prototype')])if(isObject(object))for(const key of Reflect.ownKeys(object)){
21
+ const descriptor=Object.getOwnPropertyDescriptor(object,key);
22
+ for(const value of [descriptor?.value,descriptor?.get,descriptor?.set])if(typeof value==='function')protectedHostFunctions.add(value);
23
+ }
24
+ }
25
+
26
+ export function installWebIdlRealmCompat(window,options={}){
27
+ if(!isObject(window)||!options||typeof options!=='object')throw new WebIdlRealmCompatError('INVALID_OPTIONS');
28
+ const children=ownData(options,'children')??false;
29
+ if(typeof children!=='boolean'||Object.getOwnPropertyDescriptor(options,'children')&&!Object.hasOwn(Object.getOwnPropertyDescriptor(options,'children'),'value'))throw new WebIdlRealmCompatError('INVALID_OPTIONS');
30
+ if(jsdomPackage.version!=='26.1.0')throw new WebIdlRealmCompatError('UNSUPPORTED_JSDOM');
31
+ if(activeWindows.has(window))throw new WebIdlRealmCompatError('ALREADY_INSTALLED');
32
+ if(children&&activeChildHook)throw new WebIdlRealmCompatError('CHILD_HOOK_ALREADY_INSTALLED');
33
+ const factoryDescriptor=children?Object.getOwnPropertyDescriptor(WindowModule,'createWindow'):undefined;
34
+ if(children&&(!factoryDescriptor?.writable||typeof factoryDescriptor.value!=='function'))throw new WebIdlRealmCompatError('UNSUPPORTED_JSDOM');
35
+ const saved=[],realms=[],seenFunctions=new WeakMap();let disposed=false,factoryWrapper;
36
+ const stats={diagnosticOnly:true,prototypeChainCompatibility:true,functionInternalRealmChanged:false,proxyCallableSimulation:false,nativeIdentityProven:false,
37
+ sourceRenderingModified:false,callableIdentitiesChanged:false,hostIntrinsicsModified:false,absentApisAdded:0,pageCallbacksTraversed:false,
38
+ maximumRealms:MAX_REALMS,maximumCallables:MAX_CALLABLES,childrenEnabled:children,installedRealms:0,observedChildren:0,skippedFactories:0,unsupportedChildren:0,
39
+ childFailures:0,realmLimitReached:false,callableLimitReached:false,descriptorLimitReached:false,constructorsFound:0,unregisteredCatalogFunctions:0,
40
+ callablesObserved:0,functionsCorrected:0,alreadyRealmFunctions:0,inheritedConstructorParentsPreserved:0,protectedIntrinsicsSkipped:0,nonBaselineParentsSkipped:0,
41
+ nonExtensibleFunctions:0,sharedCallableConflicts:0,inspectionFailures:0,mutationFailures:0,restoredFunctions:0,restoreConflicts:0,restoreFailures:0,
42
+ childFactoryRestored:false,childFactoryRestoreConflict:false,disposed:false};
43
+ const increment=key=>{stats[key]=Math.min(1000000,stats[key]+1);};
44
+
45
+ function installRealm(realm){
46
+ if(realms.length>=MAX_REALMS){stats.realmLimitReached=true;return;}
47
+ if(activeWindows.has(realm))throw new WebIdlRealmCompatError('ALREADY_INSTALLED');
48
+ const realmFunction=ownData(realm,'Function'),realmFunctionPrototype=isObject(realmFunction)?ownData(realmFunction,'prototype'):undefined;
49
+ const registry=ownData(realm,webIdlUtils.ctorRegistrySymbol);
50
+ if(typeof realmFunction!=='function'||realmFunction===Function||!isObject(realmFunctionPrototype)||!isObject(registry)||Object.getPrototypeOf(registry)!==null)throw new WebIdlRealmCompatError('UNSUPPORTED_REALM');
51
+ const constructors=new Set();
52
+ for(const name of webIdlConstructorNames){
53
+ if(EXCLUDED_NAMES.has(name))continue;
54
+ // The registry refers to generated per-window interfaces, independently
55
+ // of any later reassignment of a public global to a page callback.
56
+ const registered=ownData(registry,name);
57
+ if(typeof registered==='function')constructors.add(registered);
58
+ else if(typeof ownData(realm,name)==='function')increment('unregisteredCatalogFunctions');
59
+ }
60
+ // Window and these legacy factories are created inside createWindow /
61
+ // installOwnProperties in the pinned JSDOM version. Verify their links to
62
+ // that window's registered interface objects; do not touch shared CSSOM.
63
+ const windowPrototype=Object.getPrototypeOf(realm),windowConstructor=isObject(windowPrototype)?ownData(windowPrototype,'constructor'):undefined;
64
+ const eventTarget=ownData(registry,'EventTarget');
65
+ if(typeof windowConstructor==='function'&&Object.getPrototypeOf(windowConstructor)===eventTarget&&ownData(windowConstructor,'prototype')===windowPrototype)constructors.add(windowConstructor);
66
+ for(const [alias,target] of [['Image','HTMLImageElement'],['Audio','HTMLAudioElement'],['Option','HTMLOptionElement']]){
67
+ const candidate=ownData(realm,alias),registered=ownData(registry,target);
68
+ if(typeof candidate==='function'&&typeof registered==='function'&&ownData(candidate,'name')===alias&&ownData(candidate,'prototype')===ownData(registered,'prototype'))constructors.add(candidate);
69
+ }
70
+ const owner={realm,realmFunctionPrototype};realms.push(owner);activeWindows.add(realm);increment('installedRealms');
71
+ stats.constructorsFound=Math.min(1000000,stats.constructorsFound+constructors.size);
72
+ function correct(fn){
73
+ if(typeof fn!=='function')return;
74
+ if(protectedHostFunctions.has(fn)){increment('protectedIntrinsicsSkipped');return;}
75
+ const previousOwner=seenFunctions.get(fn);
76
+ if(previousOwner){if(previousOwner!==owner)increment('sharedCallableConflicts');return;}
77
+ if(stats.callablesObserved>=MAX_CALLABLES){stats.callableLimitReached=true;return;}
78
+ seenFunctions.set(fn,owner);increment('callablesObserved');
79
+ const previous=Object.getPrototypeOf(fn);
80
+ if(previous===realmFunctionPrototype){increment('alreadyRealmFunctions');return;}
81
+ if(constructors.has(previous)){increment('inheritedConstructorParentsPreserved');return;}
82
+ if(previous!==HOST_FUNCTION_PROTOTYPE){increment('nonBaselineParentsSkipped');return;}
83
+ if(!Object.isExtensible(fn)){increment('nonExtensibleFunctions');return;}
84
+ try{Object.setPrototypeOf(fn,realmFunctionPrototype);saved.push({fn,previous,next:realmFunctionPrototype});increment('functionsCorrected');}
85
+ catch{increment('mutationFailures');}
86
+ }
87
+ const inspected=new WeakSet();
88
+ function inspectOwn(object){
89
+ if(!isObject(object)||inspected.has(object))return;inspected.add(object);
90
+ try{const keys=Reflect.ownKeys(object);if(keys.length>MAX_OWN_KEYS){stats.descriptorLimitReached=true;return;}
91
+ for(const key of keys){if(stats.callableLimitReached)return;const descriptor=Object.getOwnPropertyDescriptor(object,key);
92
+ if(!descriptor)continue;correct(descriptor.value);correct(descriptor.get);correct(descriptor.set);}
93
+ }catch{increment('inspectionFailures');}
94
+ }
95
+ for(const constructor of constructors){
96
+ if(stats.callableLimitReached)break;
97
+ correct(constructor);inspectOwn(constructor);inspectOwn(ownData(constructor,'prototype'));
98
+ }
99
+ }
100
+
101
+ function dispose(){
102
+ if(disposed)return;disposed=true;stats.disposed=true;
103
+ if(factoryWrapper){
104
+ const current=Object.getOwnPropertyDescriptor(WindowModule,'createWindow');
105
+ if(current?.value===factoryWrapper){try{Object.defineProperty(WindowModule,'createWindow',factoryDescriptor);stats.childFactoryRestored=true;}catch{stats.childFactoryRestoreConflict=true;}}
106
+ else stats.childFactoryRestoreConflict=true;
107
+ activeChildHook=false;
108
+ }
109
+ for(let index=saved.length-1;index>=0;index--){const {fn,previous,next}=saved[index];
110
+ try{if(Object.getPrototypeOf(fn)!==next){increment('restoreConflicts');continue;}Object.setPrototypeOf(fn,previous);increment('restoredFunctions');}
111
+ catch{increment('restoreFailures');}}
112
+ saved.length=0;for(const owner of realms)activeWindows.delete(owner.realm);realms.length=0;
113
+ }
114
+ try{
115
+ installRealm(window);
116
+ if(children){
117
+ const original=factoryDescriptor.value;
118
+ factoryWrapper=function createWindowWithWebIdlRealmCompatibility(factoryOptions){
119
+ const child=Reflect.apply(original,this,arguments);if(disposed)return child;
120
+ if(!factoryOptions||!Object.hasOwn(factoryOptions,'parentOrigin')){increment('skippedFactories');return child;}
121
+ increment('observedChildren');
122
+ if(ownData(factoryOptions,'runScripts')!=='outside-only'){increment('unsupportedChildren');return child;}
123
+ if(realms.length>=MAX_REALMS){stats.realmLimitReached=true;return child;}
124
+ try{const proxy=ownData(child,'_globalProxy');if(!proxy){increment('unsupportedChildren');return child;}installRealm(proxy);}
125
+ catch{increment('childFailures');}
126
+ return child;
127
+ };
128
+ Object.defineProperty(WindowModule,'createWindow',{...factoryDescriptor,value:factoryWrapper});activeChildHook=true;
129
+ }
130
+ }catch(error){dispose();throw error instanceof WebIdlRealmCompatError?error:new WebIdlRealmCompatError('INSTALL_FAILED');}
131
+ return{snapshot(){return{...stats};},dispose};
132
+ }
@@ -0,0 +1,128 @@
1
+ // Narrow missing Window/Navigator state for isolated JSDOM 26 realms.
2
+ // Trust derives from the document implementation origin and actual ancestors.
3
+ import WindowModule from 'jsdom/lib/jsdom/browser/Window.js';
4
+ import DocumentModule from 'jsdom/lib/jsdom/living/nodes/Document-impl.js';
5
+ import NavigatorModule from 'jsdom/lib/jsdom/living/navigator/Navigator-impl.js';
6
+ import ElementModule from 'jsdom/lib/jsdom/living/nodes/Element-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
+ const MAX_REALMS=32,activeWindows=new WeakSet();let activeChildHook=false;
11
+ const object=value=>value!==null&&(typeof value==='object'||typeof value==='function');
12
+ const data=(value,key)=>{if(!object(value))return;const d=Object.getOwnPropertyDescriptor(value,key);return d&&Object.hasOwn(d,'value')?d.value:undefined;};
13
+ 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]);
14
+ const implementation=(wrapper,prototype)=>{const impl=data(wrapper,utils.implSymbol);return object(impl)&&Object.prototype.isPrototypeOf.call(prototype,impl)?impl:undefined;};
15
+ function realmState(realm){
16
+ const backing=data(realm,'_globalObject'),proxy=data(backing,'_globalProxy');
17
+ const document=implementation(data(backing,'_document'),DocumentModule.implementation.prototype);
18
+ if(!object(backing)||!object(proxy)||!document||data(document,'_defaultView')!==proxy&&data(document,'_defaultView')!==backing)return;
19
+ return{backing,proxy,document};
20
+ }
21
+ function trustworthyOrigin(origin){
22
+ if(typeof origin!=='string'||origin==='null')return;
23
+ let parsed;try{parsed=new URL(origin);}catch{return;}
24
+ if(parsed.origin!==origin)return;
25
+ if(parsed.protocol==='https:')return true;
26
+ if(parsed.protocol!=='http:')return;
27
+ const host=parsed.hostname.toLowerCase().replace(/\.$/,'');
28
+ return host==='localhost'||host.endsWith('.localhost')||host==='[::1]'||/^127\.\d+\.\d+\.\d+$/.test(host);
29
+ }
30
+ function missing(object,key){
31
+ let current=object;
32
+ for(let depth=0;current&&depth<32;current=Object.getPrototypeOf(current),depth++)if(Object.getOwnPropertyDescriptor(current,key))return false;
33
+ return current===null;
34
+ }
35
+
36
+ export function installRuntimeWindowStateCompat(window,options={}){
37
+ if(!object(window)||!object(options))throw Error('WINDOW_STATE_INVALID_OPTIONS');
38
+ const option=Object.getOwnPropertyDescriptor(options,'children'),children=option?.value??false;
39
+ if(option&&!Object.hasOwn(option,'value')||typeof children!=='boolean')throw Error('WINDOW_STATE_INVALID_OPTIONS');
40
+ if(jsdomPackage.version!=='26.1.0')throw Error('WINDOW_STATE_UNSUPPORTED_JSDOM');
41
+ if(activeWindows.has(window)||children&&activeChildHook)throw Error('WINDOW_STATE_ALREADY_INSTALLED');
42
+ const factoryDescriptor=children?Object.getOwnPropertyDescriptor(WindowModule,'createWindow'):undefined;
43
+ if(children&&(!factoryDescriptor?.writable||typeof factoryDescriptor.value!=='function'))throw Error('WINDOW_STATE_UNSUPPORTED_FACTORY');
44
+ const saved=[],realms=[];let disposed=false,factoryWrapper;
45
+ const stats={diagnosticOnly:true,documentOriginDerived:true,ancestorContextsChecked:true,secureCrossOriginContextsModeled:false,
46
+ sandboxContextsModeled:false,responsePoliciesModeled:false,windowDoNotTrackAdded:false,nativeSourceForged:false,sourceRenderingModified:false,
47
+ doNotTrackPreferenceConfigured:false,maximumRealms:MAX_REALMS,childrenEnabled:children,installedRealms:0,
48
+ secureContextGettersAdded:0,openerPropertiesAdded:0,navigatorDoNotTrackGettersAdded:0,preservedProperties:0,
49
+ secureReads:0,insecureReads:0,unsupportedReads:0,unsupportedSandboxReads:0,unsupportedCrossOriginReads:0,
50
+ unsupportedOriginReads:0,unsupportedAncestryReads:0,observedChildren:0,skippedFactories:0,childFailures:0,
51
+ realmLimitReached:false,mutationFailures:0,restoredProperties:0,restoreConflicts:0,restoreFailures:0,
52
+ childFactoryRestored:false,childFactoryRestoreConflict:false,disposed:false};
53
+ const increment=key=>{stats[key]=Math.min(1000000,stats[key]+1);};
54
+ function unsupported(reason){increment('unsupportedReads');increment(reason);return undefined;}
55
+ function secureContext(realm,pendingChild){
56
+ const seen=new Set();let current=realm,firstOrigin,crossOrigin=false,insecure=false;
57
+ for(let depth=0;depth<MAX_REALMS;depth++){
58
+ const state=realmState(current);if(!state||seen.has(state.backing))return unsupported('unsupportedAncestryReads');
59
+ seen.add(state.backing);
60
+ const url=data(state.document,'_URL'),scheme=data(url,'scheme');
61
+ if(scheme!=='https'&&scheme!=='http'&&!(scheme==='about'&&data(url,'path')==='blank'&&data(url,'query')===null&&data(url,'fragment')===null))return unsupported('unsupportedOriginReads');
62
+ const origin=data(state.document,'_origin'),trusted=trustworthyOrigin(origin);
63
+ if(trusted===undefined)return unsupported('unsupportedOriginReads');
64
+ if(firstOrigin===undefined)firstOrigin=origin;else if(firstOrigin!==origin)crossOrigin=true;
65
+ if(!trusted)insecure=true;
66
+ const parent=realmState(data(state.backing,'_parent')),frame=data(state.backing,'_frameElement');
67
+ if(!parent)return unsupported('unsupportedAncestryReads');
68
+ if(parent.backing===state.backing){
69
+ if(frame!==null||depth===0&&pendingChild)return unsupported('unsupportedAncestryReads');
70
+ if(insecure){increment('insecureReads');return false;}
71
+ if(crossOrigin)return unsupported('unsupportedCrossOriginReads');
72
+ increment('secureReads');return true;
73
+ }
74
+ if(!object(frame)||data(frame,'_ownerDocument')!==parent.document||data(frame,'_contentDocument')!==state.document)return unsupported('unsupportedAncestryReads');
75
+ if(Reflect.apply(ElementModule.implementation.prototype.hasAttributeNS,frame,[null,'sandbox']))return unsupported('unsupportedSandboxReads');
76
+ current=parent.proxy;
77
+ }
78
+ return unsupported('unsupportedAncestryReads');
79
+ }
80
+ function installRealm(realm,pendingChild=false){
81
+ if(realms.length>=MAX_REALMS){stats.realmLimitReached=true;return;}
82
+ if(activeWindows.has(realm))throw Error('WINDOW_STATE_ALREADY_INSTALLED');
83
+ const state=realmState(realm),realmFunction=data(realm,'Function'),realmTypeError=data(realm,'TypeError');
84
+ const navigator=realm.navigator,impl=implementation(navigator,NavigatorModule.implementation.prototype);
85
+ if(!state||state.proxy!==realm||typeof realmFunction!=='function'||realmFunction===Function||typeof realmTypeError!=='function'||!impl||data(impl,'_globalObject')!==state.backing)throw Error('WINDOW_STATE_UNSUPPORTED_REALM');
86
+ realms.push(realm);activeWindows.add(realm);increment('installedRealms');
87
+ function add(target,key,descriptor,counter){
88
+ if(!missing(target,key)){increment('preservedProperties');return;}
89
+ const previous=Object.getOwnPropertyDescriptor(target,key);
90
+ try{Object.defineProperty(target,key,descriptor);saved.push({target,key,previous,next:Object.getOwnPropertyDescriptor(target,key)});increment(counter);}catch{increment('mutationFailures');}
91
+ }
92
+ const secureGetter=realmFunction('resolve','return Object.getOwnPropertyDescriptor({get isSecureContext(){return resolve(this)}} ,"isSecureContext").get')(receiver=>{
93
+ if(receiver!==realm&&receiver!==state.backing)throw new realmTypeError('Illegal invocation');
94
+ try{return secureContext(realm,pendingChild);}catch{return unsupported('unsupportedAncestryReads');}
95
+ });
96
+ add(realm,'isSecureContext',{get:secureGetter,enumerable:true,configurable:true},'secureContextGettersAdded');
97
+ const parent=realmState(data(state.backing,'_parent'));
98
+ if(pendingChild||parent?.backing===state.backing&&data(state.backing,'_frameElement')===null||parent&&object(data(state.backing,'_frameElement')))
99
+ add(realm,'opener',{value:null,writable:true,enumerable:true,configurable:true},'openerPropertiesAdded');
100
+ const navigatorGetter=realmFunction('resolve','return Object.getOwnPropertyDescriptor({get doNotTrack(){return resolve(this)}} ,"doNotTrack").get')(receiver=>{
101
+ if(!implementation(receiver,NavigatorModule.implementation.prototype))throw new realmTypeError('Illegal invocation');return null;
102
+ });
103
+ if(!missing(navigator,'doNotTrack'))increment('preservedProperties');
104
+ else add(Object.getPrototypeOf(navigator),'doNotTrack',{get:navigatorGetter,enumerable:true,configurable:true},'navigatorDoNotTrackGettersAdded');
105
+ }
106
+ function dispose(){
107
+ if(disposed)return;disposed=true;stats.disposed=true;
108
+ if(factoryWrapper){
109
+ if(Object.getOwnPropertyDescriptor(WindowModule,'createWindow')?.value===factoryWrapper){try{Object.defineProperty(WindowModule,'createWindow',factoryDescriptor);stats.childFactoryRestored=true;}catch{stats.childFactoryRestoreConflict=true;}}
110
+ else stats.childFactoryRestoreConflict=true;activeChildHook=false;
111
+ }
112
+ for(let i=saved.length-1;i>=0;i--){const {target,key,previous,next}=saved[i];try{
113
+ if(!sameDescriptor(Object.getOwnPropertyDescriptor(target,key),next)){increment('restoreConflicts');continue;}
114
+ if(previous)Object.defineProperty(target,key,previous);else delete target[key];increment('restoredProperties');
115
+ }catch{increment('restoreFailures');}}
116
+ saved.length=0;for(const realm of realms)activeWindows.delete(realm);realms.length=0;
117
+ }
118
+ try{
119
+ installRealm(window);
120
+ if(children){const original=factoryDescriptor.value;factoryWrapper=function createWindowWithState(factoryOptions){
121
+ const child=Reflect.apply(original,this,arguments);if(disposed)return child;
122
+ if(!factoryOptions||!Object.hasOwn(factoryOptions,'parentOrigin')){increment('skippedFactories');return child;}
123
+ increment('observedChildren');if(data(factoryOptions,'runScripts')!=='outside-only'){increment('childFailures');return child;}
124
+ try{installRealm(data(child,'_globalProxy'),true);}catch{increment('childFailures');}return child;
125
+ };Object.defineProperty(WindowModule,'createWindow',{...factoryDescriptor,value:factoryWrapper});activeChildHook=true;}
126
+ }catch{dispose();throw Error('WINDOW_STATE_INSTALL_FAILED');}
127
+ return{snapshot(){return{...stats};},dispose};
128
+ }
@@ -0,0 +1,13 @@
1
+ import generatedUtils from 'jsdom/lib/jsdom/living/generated/utils.js'
2
+
3
+ // JSDOM 26 public beforeParse hook with one version-sensitive internal parser option.
4
+ // Keep runScripts=outside-only: inline/external page scripts remain inert, while
5
+ // noscript is parsed as on a scripting-enabled page. No DOM/API values are faked.
6
+ export function enableScriptingParsingForOutsideOnly(window) {
7
+ const document = generatedUtils.implForWrapper(window.document)
8
+ if (!document || window._runScripts !== 'outside-only' || document._scriptingDisabled ||
9
+ !document._parseOptions || typeof document._parseOptions !== 'object') {
10
+ throw new Error('unsupported JSDOM scripting parser configuration')
11
+ }
12
+ document._parseOptions.scriptingEnabled = true
13
+ }
@@ -0,0 +1,64 @@
1
+ import { CookieJar } from 'tough-cookie'
2
+
3
+ const ORIGIN = 'https://synthid.com'
4
+ export function attachWebXsrf(body, config) {
5
+ const form = new URLSearchParams(body)
6
+ if (typeof config.SNlM0e === 'string' && config.SNlM0e) form.set('at', config.SNlM0e)
7
+ return form
8
+ }
9
+ export function readWebConfig(html) {
10
+ const assignment = /(?:window\.)?WIZ_global_data\s*=\s*\{/.exec(html)
11
+ if (!assignment) throw new Error('Missing web config')
12
+ const start = assignment.index + assignment[0].length - 1
13
+ let quoted = false, escaped = false, depth = 0
14
+ for (let index = start; index < html.length; index++) {
15
+ const character = html[index]
16
+ if (quoted) {
17
+ if (escaped) escaped = false
18
+ else if (character === '\\') escaped = true
19
+ else if (character === '"') quoted = false
20
+ } else if (character === '"') quoted = true
21
+ else if (character === '{') depth++
22
+ else if (character === '}' && --depth === 0) {
23
+ const data = JSON.parse(html.slice(start, index + 1))
24
+ return Object.fromEntries(['FdrFJe', 'cfb2h', 'SNlM0e', 'eptZe', 'hl', 'QrtxK', 'DpimGf', 'TSDtV'].filter(key => Object.hasOwn(data, key)).map(key => [key, data[key]]))
25
+ }
26
+ }
27
+ throw new Error('Incomplete web config')
28
+ }
29
+
30
+ export async function createWebSession(http, userAgent) {
31
+ const cookies = new CookieJar()
32
+ const request = async (url, init = {}) => {
33
+ if (new URL(url).origin !== ORIGIN) throw new Error('Web session origin mismatch')
34
+ const headers = new Headers(init.headers)
35
+ headers.set('user-agent', userAgent)
36
+ const cookie = await cookies.getCookieString(url)
37
+ if (cookie) headers.set('cookie', cookie)
38
+ const response = await http.fetch(url, { ...init, headers, redirect: 'error' })
39
+ for (const cookie of response.headers.getSetCookie()) await cookies.setCookie(cookie, url)
40
+ return response
41
+ }
42
+ const response = await request(ORIGIN + '/image-detection', { signal: AbortSignal.timeout(30000) })
43
+ if (!response.ok) { await response.body?.cancel(); throw new Error('Page fetch failed') }
44
+ const html = await response.text()
45
+ if (html.length > 4 * 1024 * 1024) throw new Error('Oversize page')
46
+ const config = readWebConfig(html)
47
+ return {
48
+ config, request,
49
+ summary: {
50
+ httpStatus: response.status,
51
+ htmlBytes: Buffer.byteLength(html),
52
+ cachedBuildMarkerPresent: html.includes('Bz_3Tem3Q0o'),
53
+ publicBundlePaths: [...html.matchAll(/<script\b[^>]*\bsrc="([^"]+)"/g)].flatMap(match => {
54
+ try {
55
+ const url = new URL(match[1].replaceAll('&amp;', '&'), ORIGIN)
56
+ return url.origin === 'https://www.gstatic.com' && url.pathname.startsWith('/_/mss/boq-deepmind-visualization/') && !url.search ? [url.pathname] : []
57
+ } catch { return [] }
58
+ }),
59
+ fieldTypes: Object.fromEntries(Object.entries(config).map(([key, value]) => [key, typeof value])),
60
+ fieldNonempty: Object.fromEntries(Object.entries(config).map(([key, value]) => [key, typeof value === 'string' && value.length > 0])),
61
+ cookieNames: (await cookies.getCookies(ORIGIN + '/image-detection')).map(cookie => cookie.key),
62
+ },
63
+ }
64
+ }
@@ -0,0 +1,49 @@
1
+ // Optional JSDOM 26 binding adaptation. Changes only the literal error message
2
+ // in generated receiver-brand guards. Official/page code and error constructors
3
+ // are untouched; dependency files are never rewritten.
4
+ import {registerHooks,createRequire} from 'node:module';
5
+ import {dirname} from 'node:path';
6
+ import {pathToFileURL} from 'node:url';
7
+ import {parse} from 'acorn';
8
+ import jsdomPackage from 'jsdom/package.json' with {type:'json'};
9
+ const brandRequire=createRequire(import.meta.url);
10
+ const prefix=pathToFileURL(dirname(brandRequire.resolve('jsdom/package.json'))+'/lib/jsdom/living/generated/').href;
11
+ if(jsdomPackage.version!=='26.1.0')throw Error('UNSUPPORTED_JSDOM_BRAND_ERRORS');
12
+ const stats={diagnosticOnly:true,jsdomBindingMessagesAdapted:true,officialCodeModified:false,errorConstructorsModified:false,dependencyFilesWritten:false,inspectedModules:0,changedModules:0,changedMessages:0,parseFailures:0,unsupportedSources:0};
13
+ const member=(node,object,property)=>node?.type==='MemberExpression'&&!node.computed&&node.object?.type==='Identifier'&&node.object.name===object&&node.property?.type==='Identifier'&&node.property.name===property;
14
+ export function adaptJsdomBrandErrors(source){
15
+ const ast=parse(source,{ecmaVersion:'latest',sourceType:'script'}),changes=[];
16
+ const stack=[[ast,null,null]];let visited=0;
17
+ while(stack.length){
18
+ if(++visited>250000)throw Error('BRAND_AST_LIMIT');
19
+ const [node,parent,grand]=stack.pop();
20
+ if(node.type==='ThrowStatement'&&parent?.type==='BlockStatement'&&grand?.type==='IfStatement'&&grand.consequent===parent){
21
+ const guard=grand.test,call=guard?.argument,err=node.argument,literal=err?.arguments?.[0];
22
+ if(guard?.type==='UnaryExpression'&&guard.operator==='!'&&call?.type==='CallExpression'&&member(call.callee,'exports','is')&&call.arguments.length===1&&call.arguments[0]?.type==='Identifier'&&call.arguments[0].name==='esValue'&&err?.type==='NewExpression'&&member(err.callee,'globalObject','TypeError')&&err.arguments.length===1&&literal?.type==='Literal'&&typeof literal.value==='string'&&/^'(?:(?:get|set) )?[^']+' called on an object that is not a valid instance of [A-Z][A-Za-z0-9]*.$/.test(literal.value))changes.push([literal.start,literal.end,literal.value]);
23
+ }
24
+ for(const [key,value]of Object.entries(node)){
25
+ if(key==='start'||key==='end')continue;
26
+ if(Array.isArray(value)){for(const child of value)if(child&&typeof child==='object'&&typeof child.type==='string')stack.push([child,node,parent]);}
27
+ else if(value&&typeof value==='object'&&typeof value.type==='string')stack.push([value,node,parent]);
28
+ }
29
+ }
30
+ let output=source;for(const[start,end,literal]of changes.sort((a,b)=>b[0]-a[0])){
31
+
32
+ const asynchronous={"'play' called on an object that is not a valid instance of HTMLMediaElement.":"Failed to execute 'play' on 'HTMLMediaElement': Illegal invocation","'whenDefined' called on an object that is not a valid instance of CustomElementRegistry.":"Failed to execute 'whenDefined' on 'CustomElementRegistry': Illegal invocation"};
33
+ output=output.slice(0,start)+JSON.stringify(asynchronous[literal]||'Illegal invocation')+output.slice(end);
34
+ }
35
+ return {source:output,changedMessages:changes.length};
36
+ }
37
+ registerHooks({load(url,context,nextLoad){
38
+ const result=nextLoad(url,context);
39
+ if(!url.startsWith(prefix)||!/^[-A-Za-z0-9]+.js$/.test(url.slice(prefix.length)))return result;
40
+ if(++stats.inspectedModules>600)throw Error('BRAND_MODULE_LIMIT');
41
+ if(!['commonjs','commonjs-typescript'].includes(result.format)||result.source===undefined||result.source===null){stats.unsupportedSources++;throw Error('BRAND_SOURCE_UNAVAILABLE');}
42
+ const source=typeof result.source==='string'?result.source:Buffer.from(result.source).toString('utf8');
43
+ if(source.length>1048576)throw Error('BRAND_SOURCE_LIMIT');
44
+ let adapted;try{adapted=adaptJsdomBrandErrors(source);}catch{stats.parseFailures++;throw Error('BRAND_SOURCE_PARSE_FAILED');}
45
+ if(!adapted.changedMessages)return result;
46
+ stats.changedModules++;stats.changedMessages+=adapted.changedMessages;
47
+ return {...result,source:adapted.source};
48
+ }});
49
+ export const webidlBrandErrorSnapshot=()=>({...stats});