@luckylillia-dev/plugin-aiimgdetector 0.0.0-stage → 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.
- package/README.md +2 -2
- package/assets/demo.png +0 -0
- package/assets/icon.svg +15 -0
- package/assets/synthid-login-check.jpg +0 -0
- package/docs/details.md +45 -0
- package/docs/publishing.md +66 -0
- package/docs/synthid.md +80 -0
- package/lib/image.js +90 -0
- package/lib/index.js +207 -0
- package/lib/provenance.js +21 -0
- package/lib/synthid-auth.js +100 -0
- package/lib/synthid-browser.js +451 -0
- package/lib/synthid-http-runtime/chromium-css-property-catalog.mjs +7 -0
- package/lib/synthid-http-runtime/complete-protocol.mjs +88 -0
- package/lib/synthid-http-runtime/entry.d.mts +41 -0
- package/lib/synthid-http-runtime/entry.mjs +6 -0
- package/lib/synthid-http-runtime/event-listener-diagnostics.mjs +141 -0
- package/lib/synthid-http-runtime/independent-request-reference.mjs +49 -0
- package/lib/synthid-http-runtime/jsdom-event-clock-compat.mjs +76 -0
- package/lib/synthid-http-runtime/lifecycle-client.mjs +165 -0
- package/lib/synthid-http-runtime/lifecycle-web-session.mjs +114 -0
- package/lib/synthid-http-runtime/lifecycle-worker.mjs +363 -0
- package/lib/synthid-http-runtime/node-platform-failure-diagnostics.mjs +108 -0
- package/lib/synthid-http-runtime/realm-activation-diagnostic.js +31 -0
- package/lib/synthid-http-runtime/realm-focus-diagnostic.js +9 -0
- package/lib/synthid-http-runtime/realm-init.js +34 -0
- package/lib/synthid-http-runtime/realm-pointer-diagnostic.js +49 -0
- package/lib/synthid-http-runtime/runtime-anchor-href-translate.mjs +242 -0
- package/lib/synthid-http-runtime/runtime-child-web-compat.mjs +103 -0
- package/lib/synthid-http-runtime/runtime-chrome-csi.mjs +216 -0
- package/lib/synthid-http-runtime/runtime-clock-precision-control.mjs +51 -0
- package/lib/synthid-http-runtime/runtime-css-properties-compat.mjs +165 -0
- package/lib/synthid-http-runtime/runtime-detached-frame-compat.mjs +214 -0
- package/lib/synthid-http-runtime/runtime-javascript-bindings.mjs +69 -0
- package/lib/synthid-http-runtime/runtime-navigator-compat.mjs +99 -0
- package/lib/synthid-http-runtime/runtime-permissions-binding.mjs +64 -0
- package/lib/synthid-http-runtime/runtime-permissions-control.mjs +143 -0
- package/lib/synthid-http-runtime/runtime-web-compat.mjs +639 -0
- package/lib/synthid-http-runtime/runtime-webidl-callable-control.mjs +151 -0
- package/lib/synthid-http-runtime/runtime-webidl-realm-compat.mjs +132 -0
- package/lib/synthid-http-runtime/runtime-window-state-compat.mjs +128 -0
- package/lib/synthid-http-runtime/scripting-parser.mjs +13 -0
- package/lib/synthid-http-runtime/web-session.mjs +64 -0
- package/lib/synthid-http-runtime/webidl-brand-errors-preload.mjs +49 -0
- package/lib/synthid-http-runtime/webidl-callable-source-catalog.mjs +4491 -0
- package/lib/synthid-http-runtime/webidl-realm-catalog.mjs +124 -0
- package/lib/synthid-http.js +314 -0
- package/lib/synthid-manual.js +365 -0
- package/lib/synthid-page.js +101 -0
- package/lib/synthid-result.js +189 -0
- package/lib/synthid.js +540 -0
- package/lib/vision.js +41 -0
- package/package.json +84 -4
- package/src/image.ts +74 -0
- package/src/index.ts +203 -0
- package/src/provenance.ts +40 -0
- package/src/synthid-auth.ts +83 -0
- package/src/synthid-browser.ts +426 -0
- package/src/synthid-http-runtime/chromium-css-property-catalog.mjs +7 -0
- package/src/synthid-http-runtime/complete-protocol.mjs +88 -0
- package/src/synthid-http-runtime/entry.d.mts +41 -0
- package/src/synthid-http-runtime/entry.mjs +6 -0
- package/src/synthid-http-runtime/event-listener-diagnostics.mjs +141 -0
- package/src/synthid-http-runtime/independent-request-reference.mjs +49 -0
- package/src/synthid-http-runtime/jsdom-event-clock-compat.mjs +76 -0
- package/src/synthid-http-runtime/lifecycle-client.mjs +165 -0
- package/src/synthid-http-runtime/lifecycle-web-session.mjs +114 -0
- package/src/synthid-http-runtime/lifecycle-worker.mjs +363 -0
- package/src/synthid-http-runtime/node-platform-failure-diagnostics.mjs +108 -0
- package/src/synthid-http-runtime/realm-activation-diagnostic.js +31 -0
- package/src/synthid-http-runtime/realm-focus-diagnostic.js +9 -0
- package/src/synthid-http-runtime/realm-init.js +34 -0
- package/src/synthid-http-runtime/realm-pointer-diagnostic.js +49 -0
- package/src/synthid-http-runtime/runtime-anchor-href-translate.mjs +242 -0
- package/src/synthid-http-runtime/runtime-child-web-compat.mjs +103 -0
- package/src/synthid-http-runtime/runtime-chrome-csi.mjs +216 -0
- package/src/synthid-http-runtime/runtime-clock-precision-control.mjs +51 -0
- package/src/synthid-http-runtime/runtime-css-properties-compat.mjs +165 -0
- package/src/synthid-http-runtime/runtime-detached-frame-compat.mjs +214 -0
- package/src/synthid-http-runtime/runtime-javascript-bindings.mjs +69 -0
- package/src/synthid-http-runtime/runtime-navigator-compat.mjs +99 -0
- package/src/synthid-http-runtime/runtime-permissions-binding.mjs +64 -0
- package/src/synthid-http-runtime/runtime-permissions-control.mjs +143 -0
- package/src/synthid-http-runtime/runtime-web-compat.mjs +639 -0
- package/src/synthid-http-runtime/runtime-webidl-callable-control.mjs +151 -0
- package/src/synthid-http-runtime/runtime-webidl-realm-compat.mjs +132 -0
- package/src/synthid-http-runtime/runtime-window-state-compat.mjs +128 -0
- package/src/synthid-http-runtime/scripting-parser.mjs +13 -0
- package/src/synthid-http-runtime/web-session.mjs +64 -0
- package/src/synthid-http-runtime/webidl-brand-errors-preload.mjs +49 -0
- package/src/synthid-http-runtime/webidl-callable-source-catalog.mjs +4491 -0
- package/src/synthid-http-runtime/webidl-realm-catalog.mjs +124 -0
- package/src/synthid-http.ts +290 -0
- package/src/synthid-manual.ts +388 -0
- package/src/synthid-page.ts +103 -0
- package/src/synthid-result.ts +177 -0
- package/src/synthid.ts +514 -0
- package/src/vision.ts +57 -0
- package/webui/index.js +279 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Typed production runtime surface.
|
|
2
|
+
export interface RuntimeInitialization { success: boolean; [key: string]: unknown }
|
|
3
|
+
export interface RuntimeSnapshot { success: boolean; bgToken?: string; [key: string]: unknown }
|
|
4
|
+
export interface LifecycleClient {
|
|
5
|
+
initialize(input: Record<string, unknown>): Promise<RuntimeInitialization>
|
|
6
|
+
dispatchPointerDiagnostics(): Promise<{ success: boolean; [key: string]: unknown }>
|
|
7
|
+
snapshot(blobref: string, options?: { signal?: AbortSignal }): Promise<RuntimeSnapshot>
|
|
8
|
+
dispose(): Promise<{ success: boolean; [key: string]: unknown }>
|
|
9
|
+
readonly telemetry: Record<string, unknown>
|
|
10
|
+
}
|
|
11
|
+
export interface LifecycleClientOptions {
|
|
12
|
+
timeouts?: { init?: number; snapshot?: number; [key: string]: number | undefined }
|
|
13
|
+
maxLifetimeMs?: number
|
|
14
|
+
signal?: AbortSignal
|
|
15
|
+
webidlBrandErrors?: boolean
|
|
16
|
+
}
|
|
17
|
+
export interface WebSession {
|
|
18
|
+
config: Record<string, string>
|
|
19
|
+
environment(): Promise<Record<string, unknown>>
|
|
20
|
+
request(url: string, init?: Record<string, unknown>): Promise<Response>
|
|
21
|
+
nextRequestId(): string
|
|
22
|
+
readonly summary: Record<string, unknown>
|
|
23
|
+
}
|
|
24
|
+
export interface RequestReference {
|
|
25
|
+
userAgent: string
|
|
26
|
+
stages: Record<string, { headers: Record<string, string> }>
|
|
27
|
+
}
|
|
28
|
+
export interface OfficialChallenge {
|
|
29
|
+
program: string
|
|
30
|
+
globalName: string
|
|
31
|
+
clientExperimentsStateBlob?: string
|
|
32
|
+
interpreterUrl?: { privateDoNotAccessOrElseTrustedResourceUrlWrappedValue?: string }
|
|
33
|
+
interpreterJavascript?: { privateDoNotAccessOrElseSafeScriptWrappedValue?: string }
|
|
34
|
+
[key: string]: unknown
|
|
35
|
+
}
|
|
36
|
+
export declare function createLifecycleClient(options?: LifecycleClientOptions): LifecycleClient
|
|
37
|
+
export declare function createLifecycleWebSession(options: { fetch: (url: string, init?: Record<string, unknown>) => Promise<Response> }, userAgent: string, settings?: { networkMeasurements?: boolean; collapseConnectionTiming?: boolean }): Promise<WebSession>
|
|
38
|
+
export declare function attachWebXsrf(body: unknown, config: Record<string, string>): URLSearchParams
|
|
39
|
+
export declare function createIndependentRequestReference(options: { userAgent: string; clientHints?: Record<string, string> }): RequestReference
|
|
40
|
+
export declare function parseOfficialChallenge(raw: unknown): OfficialChallenge
|
|
41
|
+
export declare function normalizeOfficialExperimentState(blob: string | undefined): string
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Browser-free JavaScript production runtime.
|
|
2
|
+
export { createLifecycleClient } from './lifecycle-client.mjs'
|
|
3
|
+
export { createLifecycleWebSession } from './lifecycle-web-session.mjs'
|
|
4
|
+
export { attachWebXsrf } from './web-session.mjs'
|
|
5
|
+
export { createIndependentRequestReference } from './independent-request-reference.mjs'
|
|
6
|
+
export { parseOfficialChallenge, normalizeOfficialExperimentState } from './complete-protocol.mjs'
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import generatedUtils from 'jsdom/lib/jsdom/living/generated/utils.js';
|
|
2
|
+
import DocumentModule from 'jsdom/lib/jsdom/living/nodes/Document-impl.js';
|
|
3
|
+
|
|
4
|
+
// Passive, version-sensitive JSDOM 26 diagnostic. No event listener is installed
|
|
5
|
+
// or wrapped, and callbacks/options getters are never read. These are current
|
|
6
|
+
// registration counts, not proof that a particular callback was invoked.
|
|
7
|
+
const TYPES = Object.freeze(['mousemove', 'pointermove', 'click']);
|
|
8
|
+
const LIMIT = 1000000;
|
|
9
|
+
const MAX_REALMS = 32;
|
|
10
|
+
const MAX_NODES = 4096;
|
|
11
|
+
const bodyGetter = Object.getOwnPropertyDescriptor(DocumentModule.implementation.prototype, 'body').get;
|
|
12
|
+
const own = (object, key) => {
|
|
13
|
+
if (!object || (typeof object !== 'object' && typeof object !== 'function')) return undefined;
|
|
14
|
+
const descriptor = Object.getOwnPropertyDescriptor(object, key);
|
|
15
|
+
return descriptor && Object.hasOwn(descriptor, 'value') ? descriptor.value : undefined;
|
|
16
|
+
};
|
|
17
|
+
const impl = wrapper => {
|
|
18
|
+
if (!wrapper || !own(wrapper, generatedUtils.implSymbol)) return undefined;
|
|
19
|
+
return generatedUtils.implForWrapper(wrapper);
|
|
20
|
+
};
|
|
21
|
+
const bounded = number => Math.min(LIMIT, Math.max(0, number));
|
|
22
|
+
|
|
23
|
+
export function countEventTargetListeners(targetImpl) {
|
|
24
|
+
const table = own(targetImpl, '_eventListeners');
|
|
25
|
+
const events = Object.fromEntries(TYPES.map(type => [type, { total: 0, capture: 0, bubble: 0, invalid: 0 }]));
|
|
26
|
+
if (!table || typeof table !== 'object') return { available: false, events };
|
|
27
|
+
for (const type of TYPES) {
|
|
28
|
+
const list = own(table, type);
|
|
29
|
+
if (list === undefined) continue;
|
|
30
|
+
if (!Array.isArray(list)) { events[type].invalid = 1; continue; }
|
|
31
|
+
const length = own(list, 'length');
|
|
32
|
+
if (!Number.isSafeInteger(length) || length < 0) { events[type].invalid = 1; continue; }
|
|
33
|
+
events[type].total = bounded(length);
|
|
34
|
+
for (let index = 0; index < Math.min(length, LIMIT); index++) {
|
|
35
|
+
const options = own(own(list, String(index)), 'options');
|
|
36
|
+
const capture = own(options, 'capture');
|
|
37
|
+
if (capture === true) events[type].capture++;
|
|
38
|
+
else if (capture === false) events[type].bubble++;
|
|
39
|
+
else events[type].invalid++;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return { available: true, events };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function createEventListenerDiagnostics(topWindow) {
|
|
46
|
+
const records = [];
|
|
47
|
+
const windows = new WeakMap();
|
|
48
|
+
const observers = [];
|
|
49
|
+
let disposed = false, inspectionFailures = 0, truncated = false;
|
|
50
|
+
const fail = () => { inspectionFailures = bounded(inspectionFailures + 1); };
|
|
51
|
+
function captureBody(record) {
|
|
52
|
+
try {
|
|
53
|
+
const body = Reflect.apply(bodyGetter, record.documentImpl, []);
|
|
54
|
+
if (body) record.bodyImpl = body;
|
|
55
|
+
return body;
|
|
56
|
+
} catch { fail(); return undefined; }
|
|
57
|
+
}
|
|
58
|
+
function noteFrame(frame) {
|
|
59
|
+
if (disposed) return;
|
|
60
|
+
try {
|
|
61
|
+
const frameImpl = impl(frame);
|
|
62
|
+
const documentImpl = own(frameImpl, '_contentDocument');
|
|
63
|
+
const window = own(documentImpl, '_defaultView');
|
|
64
|
+
if (window && documentImpl) observeWindow(window, documentImpl, frameImpl);
|
|
65
|
+
} catch { fail(); }
|
|
66
|
+
}
|
|
67
|
+
function visit(node, owner, budget) {
|
|
68
|
+
if (!node || budget.left-- <= 0) { truncated = true; return; }
|
|
69
|
+
const nodeImpl = impl(node);
|
|
70
|
+
const name = own(nodeImpl, '_localName');
|
|
71
|
+
if ((name === 'body' || name === 'frameset') && own(nodeImpl, '_ownerDocument') === owner.documentImpl) owner.bodyImpl = nodeImpl;
|
|
72
|
+
if (name === 'iframe' || name === 'frame') noteFrame(node);
|
|
73
|
+
// Use original DOM access only to traverse nodes; no text, attribute, URL,
|
|
74
|
+
// listener callback, coordinates or realm property values enter a report.
|
|
75
|
+
for (const child of node.childNodes || []) visit(child, owner, budget);
|
|
76
|
+
}
|
|
77
|
+
function observeWindow(window, documentImpl, frameImpl) {
|
|
78
|
+
if (windows.has(window)) { captureBody(windows.get(window)); return; }
|
|
79
|
+
if (records.length >= MAX_REALMS) { truncated = true; return; }
|
|
80
|
+
const document = generatedUtils.wrapperForImpl(documentImpl);
|
|
81
|
+
const record = { window, windowImpl: impl(window), documentImpl, frameImpl, bodyImpl: undefined };
|
|
82
|
+
windows.set(window, record); records.push(record);
|
|
83
|
+
captureBody(record);
|
|
84
|
+
const Observer = own(window, 'MutationObserver');
|
|
85
|
+
if (typeof Observer === 'function' && document) {
|
|
86
|
+
const observer = new Observer(mutations => {
|
|
87
|
+
if (disposed) return;
|
|
88
|
+
try {
|
|
89
|
+
const budget = { left: MAX_NODES };
|
|
90
|
+
for (const mutation of mutations) {
|
|
91
|
+
for (const node of mutation.addedNodes) visit(node, record, budget);
|
|
92
|
+
for (const node of mutation.removedNodes) visit(node, record, budget);
|
|
93
|
+
}
|
|
94
|
+
captureBody(record);
|
|
95
|
+
} catch { fail(); }
|
|
96
|
+
});
|
|
97
|
+
observer.observe(document, { childList: true, subtree: true });
|
|
98
|
+
observers.push(observer);
|
|
99
|
+
}
|
|
100
|
+
if (document) visit(document, record, { left: MAX_NODES });
|
|
101
|
+
}
|
|
102
|
+
const document = own(topWindow, '_document');
|
|
103
|
+
const documentImpl = impl(document);
|
|
104
|
+
if (documentImpl) observeWindow(topWindow, documentImpl);
|
|
105
|
+
else fail();
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
noteFrame,
|
|
109
|
+
snapshot() {
|
|
110
|
+
if (disposed) return { disposed: true, inspectionFailures, truncated, top: undefined, frames: [] };
|
|
111
|
+
// A synchronous scan sees newly attached frames even before the observer
|
|
112
|
+
// microtask. Retained records continue to expose closed/detached realms.
|
|
113
|
+
for (const record of [...records]) {
|
|
114
|
+
try {
|
|
115
|
+
const current = own(record.window, '_document');
|
|
116
|
+
if (current) visit(current, record, { left: MAX_NODES });
|
|
117
|
+
} catch { fail(); }
|
|
118
|
+
}
|
|
119
|
+
const realms = records.map(record => {
|
|
120
|
+
const currentBody = captureBody(record);
|
|
121
|
+
const closed = own(record.window, '_document') === undefined;
|
|
122
|
+
return {
|
|
123
|
+
closed,
|
|
124
|
+
attached: record.frameImpl ? own(record.frameImpl, '_attached') === true : true,
|
|
125
|
+
bodyPresent: Boolean(currentBody && !closed),
|
|
126
|
+
bodyRetained: Boolean(record.bodyImpl && (!currentBody || closed)),
|
|
127
|
+
window: countEventTargetListeners(record.windowImpl),
|
|
128
|
+
document: countEventTargetListeners(record.documentImpl),
|
|
129
|
+
body: countEventTargetListeners(record.bodyImpl),
|
|
130
|
+
};
|
|
131
|
+
});
|
|
132
|
+
return { disposed: false, inspectionFailures, truncated, top: realms[0], frames: realms.slice(1) };
|
|
133
|
+
},
|
|
134
|
+
dispose() {
|
|
135
|
+
if (disposed) return;
|
|
136
|
+
disposed = true;
|
|
137
|
+
for (const observer of observers) observer.disconnect();
|
|
138
|
+
observers.length = 0; records.length = 0;
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Research-only reference for parameter-parity.mjs. No captured state or I/O.
|
|
2
|
+
const ORIGIN = 'https://synthid.com';
|
|
3
|
+
const STAGES = ['start', 'upload, finalize', 'detect', 'challenge'];
|
|
4
|
+
const CLIENT_HINT_HEADERS = new Set([
|
|
5
|
+
'sec-ch-ua', 'sec-ch-ua-arch', 'sec-ch-ua-bitness', 'sec-ch-ua-form-factors',
|
|
6
|
+
'sec-ch-ua-full-version', 'sec-ch-ua-full-version-list', 'sec-ch-ua-mobile',
|
|
7
|
+
'sec-ch-ua-model', 'sec-ch-ua-platform', 'sec-ch-ua-platform-version', 'sec-ch-ua-wow64',
|
|
8
|
+
]);
|
|
9
|
+
|
|
10
|
+
function invalidInput() {
|
|
11
|
+
return new TypeError('Invalid independent request reference input');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function publicHeaderValue(value, limit) {
|
|
15
|
+
if (typeof value !== 'string' || !value.length || value.length > limit
|
|
16
|
+
|| value.trim() !== value || /[^\x20-\x7e]/.test(value)) throw invalidInput();
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Accept an explicitly chosen userAgent and optional public clientHints.
|
|
22
|
+
* clientHints maps sec-ch-ua* header names to their serialized HTTP values;
|
|
23
|
+
* preserve quoting, brand order, and ?0/?1 booleans supplied by the caller.
|
|
24
|
+
* No browser/version defaults or hints inferred from the user agent.
|
|
25
|
+
*
|
|
26
|
+
* Body/content-type, upload metadata, auth, cookies, query fields and XSRF
|
|
27
|
+
* remain owned by the current request/session builders. This reference is
|
|
28
|
+
* a header policy, not a record of an observed request or transport protocol.
|
|
29
|
+
*/
|
|
30
|
+
export function createIndependentRequestReference({ userAgent, clientHints = {} } = {}) {
|
|
31
|
+
const identity = publicHeaderValue(userAgent, 1024);
|
|
32
|
+
if (!clientHints || typeof clientHints !== 'object' || Array.isArray(clientHints)) throw invalidInput();
|
|
33
|
+
const hints = {};
|
|
34
|
+
for (const [rawName, value] of Object.entries(clientHints)) {
|
|
35
|
+
const name = rawName.toLowerCase();
|
|
36
|
+
if (!CLIENT_HINT_HEADERS.has(name) || Object.hasOwn(hints, name)) throw invalidInput();
|
|
37
|
+
hints[name] = publicHeaderValue(value, 4096);
|
|
38
|
+
if (['sec-ch-ua-mobile', 'sec-ch-ua-wow64'].includes(name) && !['?0', '?1'].includes(value)) throw invalidInput();
|
|
39
|
+
}
|
|
40
|
+
const common = {
|
|
41
|
+
origin: ORIGIN, referer: ORIGIN + '/', 'user-agent': identity,
|
|
42
|
+
'accept-language': 'en-US,en;q=0.9', ...hints,
|
|
43
|
+
};
|
|
44
|
+
const stages = Object.fromEntries(STAGES.map(stage => [stage, { headers: { ...common } }]));
|
|
45
|
+
Object.assign(stages.detect.headers, {
|
|
46
|
+
accept: '*/*', 'sec-fetch-site': 'same-origin', 'sec-fetch-mode': 'cors', 'sec-fetch-dest': 'empty',
|
|
47
|
+
});
|
|
48
|
+
return { stages, userAgent: identity };
|
|
49
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import EventModule from 'jsdom/lib/jsdom/living/events/Event-impl.js';
|
|
2
|
+
import PerformanceModule from 'jsdom/lib/jsdom/living/hr-time/Performance-impl.js';
|
|
3
|
+
import generatedUtils from 'jsdom/lib/jsdom/living/generated/utils.js';
|
|
4
|
+
import jsdomPackage from 'jsdom/package.json' with { type: 'json' };
|
|
5
|
+
import {uncoarsenedPerformanceNow,quantizeCompletedClock100us} from './runtime-clock-precision-control.mjs';
|
|
6
|
+
|
|
7
|
+
const EventImpl = EventModule.implementation;
|
|
8
|
+
const PerformanceImpl = PerformanceModule.implementation;
|
|
9
|
+
const performanceNow = uncoarsenedPerformanceNow;
|
|
10
|
+
const ownData = (object, key) => {
|
|
11
|
+
if (!object || (typeof object !== 'object' && typeof object !== 'function')) return undefined;
|
|
12
|
+
const descriptor = Object.getOwnPropertyDescriptor(object, key);
|
|
13
|
+
return descriptor && Object.hasOwn(descriptor, 'value') ? descriptor.value : undefined;
|
|
14
|
+
};
|
|
15
|
+
const unsupported = () => { throw Error('EVENT_CLOCK_UNSUPPORTED_JSDOM'); };
|
|
16
|
+
|
|
17
|
+
/** Experimental standards correction, for a dedicated isolated JSDOM worker.
|
|
18
|
+
* JSDOM26 stamps events with Date.now(); DOM timestamps use the creation realm's
|
|
19
|
+
* relative high-resolution clock. No browser identity/trust value is changed.
|
|
20
|
+
* This mutates one internal prototype process-wide, and must be disposed. */
|
|
21
|
+
export function installEventClockCompatibility(options = {}) {
|
|
22
|
+
if(!options||typeof options!=='object')throw Error('EVENT_CLOCK_INVALID_OPTIONS');
|
|
23
|
+
const precisionDescriptor=Object.getOwnPropertyDescriptor(options,'clockPrecision100us');
|
|
24
|
+
if(precisionDescriptor&&!Object.hasOwn(precisionDescriptor,'value'))throw Error('EVENT_CLOCK_INVALID_OPTIONS');
|
|
25
|
+
const suppliedPrecision=precisionDescriptor?.value;
|
|
26
|
+
const clockPrecision100us=suppliedPrecision===undefined?false:suppliedPrecision;
|
|
27
|
+
if(typeof clockPrecision100us!=='boolean')throw Error('EVENT_CLOCK_INVALID_OPTIONS');
|
|
28
|
+
const prototype = EventImpl.prototype;
|
|
29
|
+
const source = Function.prototype.toString.call(EventImpl);
|
|
30
|
+
if (jsdomPackage.version !== '26.1.0' || typeof performanceNow !== 'function' ||
|
|
31
|
+
Object.getOwnPropertyDescriptor(prototype, 'constructor')?.value !== EventImpl ||
|
|
32
|
+
!Object.isExtensible(prototype) || Object.hasOwn(prototype, 'timeStamp') ||
|
|
33
|
+
!source.includes('this._globalObject = globalObject;') ||
|
|
34
|
+
!source.includes('this.timeStamp = Date.now();') ||
|
|
35
|
+
source.indexOf('this._globalObject = globalObject;') > source.indexOf('this.timeStamp = Date.now();')) unsupported();
|
|
36
|
+
const clocks = new WeakMap();
|
|
37
|
+
let disposed = false;
|
|
38
|
+
function stampAtCreation(epochAssignment) {
|
|
39
|
+
if (disposed || !EventImpl.prototype.isPrototypeOf(this) ||
|
|
40
|
+
Object.hasOwn(this, 'timeStamp') || !Number.isFinite(epochAssignment)) unsupported();
|
|
41
|
+
const realm = ownData(this, '_globalObject');
|
|
42
|
+
if (!realm || (typeof realm !== 'object' && typeof realm !== 'function')) unsupported();
|
|
43
|
+
let clock = clocks.get(realm);
|
|
44
|
+
if (!clock) {
|
|
45
|
+
// The Window getter returns its own original Performance wrapper. Capture
|
|
46
|
+
// the implementation once, never use a page-replaced performance.now().
|
|
47
|
+
const descriptor = Object.getOwnPropertyDescriptor(realm, 'performance');
|
|
48
|
+
if (!descriptor || typeof descriptor.get !== 'function' || descriptor.set !== undefined) unsupported();
|
|
49
|
+
const wrapper = Reflect.apply(descriptor.get, realm, []);
|
|
50
|
+
if (!ownData(wrapper, generatedUtils.implSymbol)) unsupported();
|
|
51
|
+
clock = generatedUtils.implForWrapper(wrapper);
|
|
52
|
+
if (!PerformanceImpl.prototype.isPrototypeOf(clock) ||
|
|
53
|
+
ownData(clock, '_globalObject') !== realm ||
|
|
54
|
+
!Number.isFinite(ownData(clock, '_nowAtTimeOrigin')) ||
|
|
55
|
+
!Number.isFinite(ownData(clock, 'timeOrigin'))) unsupported();
|
|
56
|
+
clocks.set(realm, clock);
|
|
57
|
+
}
|
|
58
|
+
const completed = Reflect.apply(performanceNow, clock, []);
|
|
59
|
+
const value = clockPrecision100us ? quantizeCompletedClock100us(completed) : completed;
|
|
60
|
+
if (!Number.isFinite(value) || value < 0) unsupported();
|
|
61
|
+
// Match the exact property flags produced by EventImpl's normal assignment.
|
|
62
|
+
// Every subsequent access uses this stable own value, not the setter/clock.
|
|
63
|
+
Object.defineProperty(this, 'timeStamp', { value, writable: true, enumerable: true, configurable: true });
|
|
64
|
+
}
|
|
65
|
+
Object.defineProperty(prototype, 'timeStamp', { set: stampAtCreation, configurable: true, enumerable: false });
|
|
66
|
+
return {
|
|
67
|
+
dispose() {
|
|
68
|
+
if (disposed) return;
|
|
69
|
+
const current = Object.getOwnPropertyDescriptor(prototype, 'timeStamp');
|
|
70
|
+
if (!current || current.set !== stampAtCreation || current.get !== undefined ||
|
|
71
|
+
current.configurable !== true || current.enumerable !== false) throw Error('EVENT_CLOCK_RESTORE_CONFLICT');
|
|
72
|
+
delete prototype.timeStamp;
|
|
73
|
+
disposed = true;
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
4
|
+
import { dirname, resolve } from 'node:path';
|
|
5
|
+
|
|
6
|
+
const DIRECTORY = dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
const VERSION = 1;
|
|
8
|
+
const MAX_INPUT_BYTES = 16 * 1024 * 1024;
|
|
9
|
+
const MAX_RESPONSE_BYTES = 1024 * 1024;
|
|
10
|
+
const TIMEOUTS = { init: 20000, snapshot: 15000, pointerDiagnostics: 5000, inspect: 2000, dispose: 2000 };
|
|
11
|
+
const boundedTimeout = (value, operation) => Number.isInteger(value) && value >= 10 && value <= (operation === 'init' ? 240000 : 120000);
|
|
12
|
+
|
|
13
|
+
export class LifecycleError extends Error {
|
|
14
|
+
constructor(code, phase, errorType) {
|
|
15
|
+
super('SynthID interpreter lifecycle failed: ' + code);
|
|
16
|
+
this.name = 'LifecycleError'; this.code = code; this.phase = phase; this.errorType = errorType;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** All supplied programs, cookies and per-image tokens remain on private pipes. */
|
|
21
|
+
export class SynthIdLifecycleClient {
|
|
22
|
+
#child; #pending = new Map(); #buffer = ''; #nextId = 1; #closed = false;
|
|
23
|
+
#closing = false; #queue = Promise.resolve(); #timeouts; #lifetimeTimer;
|
|
24
|
+
#closePromise; #resolveClose; #disposePromise; #signal; #abortListener;
|
|
25
|
+
#telemetry = { spawned: false, responses: 0, stderrBytes: 0, timedOut: false, disposed: false, exited: false };
|
|
26
|
+
|
|
27
|
+
constructor({ timeouts = {}, maxLifetimeMs = 5 * 60 * 1000, signal, webidlBrandErrors = false } = {}) {
|
|
28
|
+
if (typeof webidlBrandErrors !== 'boolean') throw new LifecycleError('INVALID_OPTIONS');
|
|
29
|
+
this.#timeouts = { ...TIMEOUTS, ...timeouts };
|
|
30
|
+
if (Object.entries(this.#timeouts).some(([operation, value]) => !boundedTimeout(value, operation)) || !Number.isInteger(maxLifetimeMs) || maxLifetimeMs < 100 || maxLifetimeMs > 13 * 60 * 60 * 1000) throw new LifecycleError('INVALID_OPTIONS');
|
|
31
|
+
if (signal?.aborted) throw new LifecycleError('ABORTED');
|
|
32
|
+
this.#closePromise = new Promise(resolve => { this.#resolveClose = resolve; });
|
|
33
|
+
const allowedPaths = [DIRECTORY, resolve(DIRECTORY, '../../node_modules'),
|
|
34
|
+
resolve(dirname(createRequire(import.meta.url).resolve('jsdom/package.json')), '..')];
|
|
35
|
+
this.#telemetry.nativeAddonPermission = false;
|
|
36
|
+
this.#child = spawn(process.execPath, [
|
|
37
|
+
'--permission', '--no-addons', '--no-global-search-paths', '--max-old-space-size=256',
|
|
38
|
+
...(webidlBrandErrors ? ['--import', pathToFileURL(resolve(DIRECTORY, 'webidl-brand-errors-preload.mjs')).href] : []),
|
|
39
|
+
...allowedPaths.map(path => '--allow-fs-read=' + path),
|
|
40
|
+
resolve(DIRECTORY, 'lifecycle-worker.mjs'),
|
|
41
|
+
], {
|
|
42
|
+
cwd: DIRECTORY, windowsHide: true, stdio: ['pipe', 'pipe', 'pipe'],
|
|
43
|
+
env: { SystemRoot: process.env.SystemRoot, WINDIR: process.env.WINDIR },
|
|
44
|
+
});
|
|
45
|
+
this.#child.once('spawn', () => { this.#telemetry.spawned = true; });
|
|
46
|
+
this.#child.stdout.setEncoding('utf8');
|
|
47
|
+
this.#child.stdout.on('data', chunk => this.#read(chunk));
|
|
48
|
+
this.#child.stderr.on('data', chunk => { this.#telemetry.stderrBytes += chunk.length; });
|
|
49
|
+
this.#child.stdin.on('error', () => this.#fail(new LifecycleError('PIPE_FAILURE')));
|
|
50
|
+
this.#child.once('error', () => this.#fail(new LifecycleError('SPAWN_FAILURE')));
|
|
51
|
+
this.#child.once('close', (exitCode, signalName) => {
|
|
52
|
+
this.#closed = true; clearTimeout(this.#lifetimeTimer);
|
|
53
|
+
this.#telemetry.exited = true; this.#telemetry.exitCode = exitCode;
|
|
54
|
+
this.#telemetry.signal = signalName;
|
|
55
|
+
if (this.#signal && this.#abortListener) this.#signal.removeEventListener('abort', this.#abortListener);
|
|
56
|
+
this.#rejectPending(new LifecycleError('WORKER_EXITED'));
|
|
57
|
+
this.#resolveClose();
|
|
58
|
+
});
|
|
59
|
+
this.#lifetimeTimer = setTimeout(() => {
|
|
60
|
+
this.#telemetry.timedOut = true;
|
|
61
|
+
this.#fail(new LifecycleError('LIFETIME_TIMEOUT'));
|
|
62
|
+
}, maxLifetimeMs);
|
|
63
|
+
this.#signal = signal;
|
|
64
|
+
if (signal) {
|
|
65
|
+
this.#abortListener = () => this.#fail(new LifecycleError('ABORTED'));
|
|
66
|
+
signal.addEventListener('abort', this.#abortListener, { once: true });
|
|
67
|
+
if (signal.aborted) this.#abortListener();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
get telemetry() { return { ...this.#telemetry }; }
|
|
72
|
+
#rejectPending(error) {
|
|
73
|
+
for (const { reject, timer } of this.#pending.values()) { clearTimeout(timer); reject(error); }
|
|
74
|
+
this.#pending.clear();
|
|
75
|
+
}
|
|
76
|
+
#fail(error) {
|
|
77
|
+
this.#closing = true;
|
|
78
|
+
this.#rejectPending(error);
|
|
79
|
+
if (!this.#closed) this.#child.kill();
|
|
80
|
+
}
|
|
81
|
+
#read(chunk) {
|
|
82
|
+
this.#buffer += chunk;
|
|
83
|
+
if (Buffer.byteLength(this.#buffer) > MAX_RESPONSE_BYTES) return this.#fail(new LifecycleError('OVERSIZE_RESPONSE'));
|
|
84
|
+
let end;
|
|
85
|
+
while ((end = this.#buffer.indexOf('\n')) !== -1) {
|
|
86
|
+
const line = this.#buffer.slice(0, end); this.#buffer = this.#buffer.slice(end + 1);
|
|
87
|
+
let response;
|
|
88
|
+
try { response = JSON.parse(line); } catch { return this.#fail(new LifecycleError('INVALID_RESPONSE')); }
|
|
89
|
+
const pending = this.#pending.get(response?.id);
|
|
90
|
+
if (response?.version !== VERSION || !pending || typeof response.ok !== 'boolean') return this.#fail(new LifecycleError('INVALID_RESPONSE'));
|
|
91
|
+
clearTimeout(pending.timer); this.#pending.delete(response.id); this.#telemetry.responses++;
|
|
92
|
+
if (response.ok) {
|
|
93
|
+
pending.resolve(response.result);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
const code = /^[A-Z_]{1,50}$/.test(response.error?.code || '') ? response.error.code : 'WORKER_ERROR';
|
|
97
|
+
const phase = ['empty', 'environment', 'interpreter', 'initialize', 'ready', 'snapshot', 'pointerDiagnostics', 'disposed'].includes(response.error?.phase) ? response.error.phase : undefined;
|
|
98
|
+
const errorType = ['Error', 'TypeError', 'RangeError', 'SyntaxError', 'unknown'].includes(response.error?.errorType) ? response.error.errorType : undefined;
|
|
99
|
+
if (code === 'OPERATION_TIMEOUT') this.#telemetry.timedOut = true;
|
|
100
|
+
pending.reject(new LifecycleError(code, phase, errorType));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
#request(op, values = {}) {
|
|
105
|
+
if (this.#signal?.aborted && op !== 'dispose') return Promise.reject(new LifecycleError('ABORTED'));
|
|
106
|
+
if (this.#closed || (this.#closing && op !== 'dispose')) return Promise.reject(new LifecycleError('CLOSED'));
|
|
107
|
+
const id = this.#nextId++;
|
|
108
|
+
const timeoutMs = this.#timeouts[op];
|
|
109
|
+
let line;
|
|
110
|
+
try {
|
|
111
|
+
line = JSON.stringify({ version: VERSION, id, op, timeoutMs, ...values }) + '\n';
|
|
112
|
+
}
|
|
113
|
+
catch { return Promise.reject(new LifecycleError('INVALID_INPUT')); }
|
|
114
|
+
if (Buffer.byteLength(line) > MAX_INPUT_BYTES) return Promise.reject(new LifecycleError('OVERSIZE_INPUT'));
|
|
115
|
+
return new Promise((resolve, reject) => {
|
|
116
|
+
// The VM's synchronous execution is independently bounded at 5 seconds.
|
|
117
|
+
// Add that allowance so asynchronous deadlines retain their real meaning.
|
|
118
|
+
const timer = setTimeout(() => {
|
|
119
|
+
this.#telemetry.timedOut = true;
|
|
120
|
+
this.#fail(new LifecycleError('WORKER_TIMEOUT', op));
|
|
121
|
+
}, timeoutMs + 6500);
|
|
122
|
+
this.#pending.set(id, { resolve, reject, timer });
|
|
123
|
+
this.#child.stdin.write(line, error => { if (error) this.#fail(new LifecycleError('PIPE_FAILURE')); });
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
#serial(op, values) {
|
|
127
|
+
const operation = this.#queue.then(() => this.#request(op, values));
|
|
128
|
+
this.#queue = operation.catch(() => {});
|
|
129
|
+
return operation;
|
|
130
|
+
}
|
|
131
|
+
initialize(input) { return this.#serial('init', { input }); }
|
|
132
|
+
snapshot(blobref) { return this.#serial('snapshot', { blobref }); }
|
|
133
|
+
dispatchPointerDiagnostics() { return this.#serial('pointerDiagnostics'); }
|
|
134
|
+
inspect() { return this.#serial('inspect'); }
|
|
135
|
+
async dispose() {
|
|
136
|
+
if (this.#disposePromise) return this.#disposePromise;
|
|
137
|
+
this.#disposePromise = (async () => {
|
|
138
|
+
let result = { success: true, phase: 'disposed', shutdownInvoked: false, shutdownCompleted: false };
|
|
139
|
+
if (!this.#closed && !this.#closing) {
|
|
140
|
+
this.#closing = true;
|
|
141
|
+
try { result = await this.#request('dispose'); } catch {}
|
|
142
|
+
}
|
|
143
|
+
this.#telemetry.disposed = true;
|
|
144
|
+
if (!this.#closed) {
|
|
145
|
+
this.#child.stdin.end();
|
|
146
|
+
let timer;
|
|
147
|
+
await Promise.race([this.#closePromise, new Promise(resolve => {
|
|
148
|
+
timer = setTimeout(() => { this.#child.kill(); resolve(); }, 1000);
|
|
149
|
+
})]);
|
|
150
|
+
clearTimeout(timer);
|
|
151
|
+
}
|
|
152
|
+
// kill() is asynchronous; bound final cleanup without leaving host timers.
|
|
153
|
+
if (!this.#closed) {
|
|
154
|
+
let timer;
|
|
155
|
+
await Promise.race([this.#closePromise, new Promise(resolve => { timer = setTimeout(resolve, 1000); })]);
|
|
156
|
+
clearTimeout(timer);
|
|
157
|
+
}
|
|
158
|
+
clearTimeout(this.#lifetimeTimer);
|
|
159
|
+
return result;
|
|
160
|
+
})();
|
|
161
|
+
return this.#disposePromise;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export const createLifecycleClient = options => new SynthIdLifecycleClient(options);
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { CookieJar } from 'tough-cookie';
|
|
2
|
+
import { readWebConfig } from './web-session.mjs';
|
|
3
|
+
|
|
4
|
+
const ORIGIN = 'https://synthid.com';
|
|
5
|
+
|
|
6
|
+
// Projection for this producer's explicitly unavailable connection details.
|
|
7
|
+
// Matches Fetch/Undici's absent-connection-info fallback at defaultStartTime;
|
|
8
|
+
// this is not a DNS/TCP measurement and says nothing about connection reuse.
|
|
9
|
+
export function collapseUnavailableConnectionTiming(entry) {
|
|
10
|
+
if (!Number.isFinite(entry?.fetchStart) || entry.fetchStart < 0) throw Error('Invalid connection timing origin');
|
|
11
|
+
const projected = { ...entry }, fields = [];
|
|
12
|
+
for (const name of ['domainLookupStart', 'domainLookupEnd', 'connectStart', 'connectEnd']) {
|
|
13
|
+
if (projected[name] === undefined) { projected[name] = entry.fetchStart; fields.push(name); }
|
|
14
|
+
else if (!Number.isFinite(projected[name]) || projected[name] < 0) throw Error('Invalid supplied connection timing');
|
|
15
|
+
}
|
|
16
|
+
return { entry: projected, summary: { policy: 'unmeasured-collapsed-at-fetch-start', measured: false, projectedFields: fields } };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Mirrors h4's per-page base plus Sba counter in retained official source. */
|
|
20
|
+
export function createRequestIds(clock = () => new Date()) {
|
|
21
|
+
let base = 0;
|
|
22
|
+
let sequence = 0;
|
|
23
|
+
return () => {
|
|
24
|
+
if (!base) {
|
|
25
|
+
const now = clock();
|
|
26
|
+
base = now.getHours() * 3600 + now.getMinutes() * 60 + now.getSeconds();
|
|
27
|
+
}
|
|
28
|
+
return String(1 + base + sequence++ * 100000);
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Public page globals stay in memory; no page script is evaluated here. */
|
|
33
|
+
export function readPageGlobals(html) {
|
|
34
|
+
const assignment = /(?:window\.)?WIZ_global_data\s*=\s*\{/.exec(html);
|
|
35
|
+
if (!assignment) throw new Error('Missing web config');
|
|
36
|
+
const start = assignment.index + assignment[0].length - 1;
|
|
37
|
+
let quoted = false, escaped = false, depth = 0;
|
|
38
|
+
for (let index = start; index < html.length; index++) {
|
|
39
|
+
const character = html[index];
|
|
40
|
+
if (quoted) {
|
|
41
|
+
if (escaped) escaped = false;
|
|
42
|
+
else if (character === '\\') escaped = true;
|
|
43
|
+
else if (character === '"') quoted = false;
|
|
44
|
+
} else if (character === '"') quoted = true;
|
|
45
|
+
else if (character === '{') depth++;
|
|
46
|
+
else if (character === '}' && --depth === 0) {
|
|
47
|
+
const data = JSON.parse(html.slice(start, index + 1));
|
|
48
|
+
if (!data || Array.isArray(data) || typeof data !== 'object') throw new Error('Invalid page config');
|
|
49
|
+
return { WIZ_global_data: data };
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
throw new Error('Incomplete web config');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export async function createLifecycleWebSession(http, userAgent, options = {}) {
|
|
56
|
+
if (options.collapseConnectionTiming !== undefined && typeof options.collapseConnectionTiming !== 'boolean') throw Error('Invalid connection timing option');
|
|
57
|
+
const cookies = new CookieJar();
|
|
58
|
+
const request = async (url, init = {}) => {
|
|
59
|
+
if (new URL(url).origin !== ORIGIN) throw new Error('Unexpected web session origin');
|
|
60
|
+
const headers = new Headers(init.headers);
|
|
61
|
+
headers.set('user-agent', userAgent);
|
|
62
|
+
const cookie = await cookies.getCookieString(url);
|
|
63
|
+
if (cookie) headers.set('cookie', cookie);
|
|
64
|
+
else headers.delete('cookie');
|
|
65
|
+
const response = await http.fetch(url, { ...init, headers, redirect: 'error' });
|
|
66
|
+
for (const value of response.headers.getSetCookie()) await cookies.setCookie(value, url);
|
|
67
|
+
return response;
|
|
68
|
+
};
|
|
69
|
+
const performanceTimeOriginEpochMs = Date.now();
|
|
70
|
+
const navigationStarted = performance.now();
|
|
71
|
+
const response = await request(ORIGIN + '/image-detection', { signal: AbortSignal.timeout(30000),
|
|
72
|
+
...(options.networkMeasurements === true ? { headers: { 'accept-encoding': 'identity' } } : {}),
|
|
73
|
+
});
|
|
74
|
+
const responseStart = performance.now() - navigationStarted;
|
|
75
|
+
if (!response.ok) { await response.body?.cancel(); throw new Error('Page fetch failed'); }
|
|
76
|
+
const pageBytes = Buffer.from(await response.arrayBuffer());
|
|
77
|
+
const pageHTML = pageBytes.toString('utf8');
|
|
78
|
+
const responseEnd = performance.now() - navigationStarted;
|
|
79
|
+
if (pageHTML.length > 4 * 1024 * 1024) throw new Error('Oversize page');
|
|
80
|
+
const config = readWebConfig(pageHTML);
|
|
81
|
+
const pageGlobals = readPageGlobals(pageHTML);
|
|
82
|
+
// These timings describe this Node HTTP document load, not a captured
|
|
83
|
+
// browser navigation. URLs and timing entries remain private worker input.
|
|
84
|
+
const performanceEntries = [{ name: ORIGIN + '/image-detection', entryType: 'navigation',
|
|
85
|
+
startTime: 0, duration: responseEnd, fetchStart: 0, requestStart: 0,
|
|
86
|
+
responseStart, responseEnd, decodedBodySize: pageBytes.length,
|
|
87
|
+
}];
|
|
88
|
+
let connectionTiming;
|
|
89
|
+
if (options.collapseConnectionTiming === true) {
|
|
90
|
+
const projection = collapseUnavailableConnectionTiming(performanceEntries[0]);
|
|
91
|
+
performanceEntries[0] = projection.entry;
|
|
92
|
+
connectionTiming = projection.summary;
|
|
93
|
+
}
|
|
94
|
+
const contentLength = response.headers.get('content-length');
|
|
95
|
+
if (typeof contentLength === 'string' && /^\d{1,10}$/.test(contentLength) && Number(contentLength) > 0) {
|
|
96
|
+
performanceEntries[0].encodedBodySize = Number(contentLength);
|
|
97
|
+
} else if (!response.headers.has('content-encoding') || response.headers.get('content-encoding') === 'identity') {
|
|
98
|
+
performanceEntries[0].encodedBodySize = pageBytes.length;
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
config, request, nextRequestId: createRequestIds(),
|
|
102
|
+
environment: async () => ({ pageHTML, pageGlobals, cookieJar: await cookies.serialize(), performanceTimeOriginEpochMs, performanceEntries }),
|
|
103
|
+
summary: {
|
|
104
|
+
httpStatus: response.status,
|
|
105
|
+
htmlBytes: Buffer.byteLength(pageHTML),
|
|
106
|
+
cookieNames: (await cookies.getCookies(ORIGIN)).map(cookie => cookie.key),
|
|
107
|
+
cookieSource: 'HTTP-only',
|
|
108
|
+
fieldTypes: Object.fromEntries(Object.entries(config).map(([key, value]) => [key, typeof value])),
|
|
109
|
+
sharedPageAndCookieState: true,
|
|
110
|
+
identityEncodingRequested: options.networkMeasurements === true,
|
|
111
|
+
connectionTiming,
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
}
|