@qontinui/ui-bridge-wrapper 0.11.0 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +129 -8
- package/dist/capture-specs-cli.cjs +171 -50
- package/dist/capture-specs-cli.cjs.map +1 -1
- package/dist/capture-specs-cli.d.ts.map +1 -1
- package/dist/index.cjs +88 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +88 -4
- package/dist/index.js.map +1 -1
- package/dist/inject-cli.cjs +283 -115
- package/dist/inject-cli.cjs.map +1 -1
- package/dist/inject-cli.d.ts +1 -1
- package/dist/inject-cli.d.ts.map +1 -1
- package/dist/login-web-cli.cjs +178 -54
- package/dist/login-web-cli.cjs.map +1 -1
- package/dist/login-web-cli.d.ts.map +1 -1
- package/dist/network-throttle.d.ts +5 -0
- package/dist/network-throttle.d.ts.map +1 -1
- package/dist/timeline-capture.d.ts +75 -9
- package/dist/timeline-capture.d.ts.map +1 -1
- package/dist/transports/headless.d.ts +46 -1
- package/dist/transports/headless.d.ts.map +1 -1
- package/dist/transports/injected.d.ts +10 -2
- package/dist/transports/injected.d.ts.map +1 -1
- package/dist/types.d.ts +3 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -6
- package/dist/cli-args.d.ts +0 -13
- package/dist/cli-args.d.ts.map +0 -1
package/dist/index.js
CHANGED
|
@@ -234,9 +234,60 @@ var HeadlessTransport = class extends BaseTransport {
|
|
|
234
234
|
userAgent: typeof raw["userAgent"] === "string" ? raw["userAgent"] : void 0,
|
|
235
235
|
forwardConsole: typeof raw["forwardConsole"] === "boolean" ? raw["forwardConsole"] : void 0,
|
|
236
236
|
launchArgs: Array.isArray(raw["launchArgs"]) && raw["launchArgs"].every((a) => typeof a === "string") ? raw["launchArgs"] : void 0,
|
|
237
|
-
storageStatePath: typeof raw["storageStatePath"] === "string" ? raw["storageStatePath"] : void 0
|
|
237
|
+
storageStatePath: typeof raw["storageStatePath"] === "string" ? raw["storageStatePath"] : void 0,
|
|
238
|
+
...this.parseContextOptions(raw)
|
|
238
239
|
};
|
|
239
240
|
}
|
|
241
|
+
/**
|
|
242
|
+
* `recordHar`, `recordVideo`, `serviceWorkers` and `initRouter`. Unlike the display
|
|
243
|
+
* options above, a malformed value is REFUSED rather than dropped: dropping
|
|
244
|
+
* `recordHar` would leave a caller waiting for an archive that is never
|
|
245
|
+
* written, and dropping `initRouter` would let requests it meant to answer
|
|
246
|
+
* reach the network.
|
|
247
|
+
*/
|
|
248
|
+
parseContextOptions(raw) {
|
|
249
|
+
const out = {};
|
|
250
|
+
const invalid = (what) => new WrapperTransportError("INVALID_CONFIG", `Transport kind '${this.kind}': ${what}`);
|
|
251
|
+
const har = raw["recordHar"];
|
|
252
|
+
if (har !== void 0) {
|
|
253
|
+
if (typeof har !== "object" || har === null || typeof har.path !== "string" || har.path.length === 0) {
|
|
254
|
+
throw invalid("options.recordHar must be an object with a non-empty string `path`");
|
|
255
|
+
}
|
|
256
|
+
out.recordHar = har;
|
|
257
|
+
}
|
|
258
|
+
const video = raw["recordVideo"];
|
|
259
|
+
if (video !== void 0) {
|
|
260
|
+
if (typeof video !== "object" || video === null || typeof video.dir !== "string" || video.dir.length === 0) {
|
|
261
|
+
throw invalid("options.recordVideo must be an object with a non-empty string `dir`");
|
|
262
|
+
}
|
|
263
|
+
const size = video.size;
|
|
264
|
+
if (size !== void 0) {
|
|
265
|
+
const positiveInt = (n) => typeof n === "number" && Number.isInteger(n) && n > 0;
|
|
266
|
+
const s = size;
|
|
267
|
+
if (typeof size !== "object" || s === null || !positiveInt(s.width) || !positiveInt(s.height)) {
|
|
268
|
+
throw invalid(
|
|
269
|
+
"options.recordVideo.size must be { width, height } with positive integer sides"
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
out.recordVideo = video;
|
|
274
|
+
}
|
|
275
|
+
const sw = raw["serviceWorkers"];
|
|
276
|
+
if (sw !== void 0) {
|
|
277
|
+
if (sw !== "allow" && sw !== "block") {
|
|
278
|
+
throw invalid(`options.serviceWorkers must be 'allow' or 'block' (got ${String(sw)})`);
|
|
279
|
+
}
|
|
280
|
+
out.serviceWorkers = sw;
|
|
281
|
+
}
|
|
282
|
+
const router = raw["initRouter"];
|
|
283
|
+
if (router !== void 0) {
|
|
284
|
+
if (typeof router !== "function") {
|
|
285
|
+
throw invalid("options.initRouter must be a function (context) => void | Promise<void>");
|
|
286
|
+
}
|
|
287
|
+
out.initRouter = router;
|
|
288
|
+
}
|
|
289
|
+
return out;
|
|
290
|
+
}
|
|
240
291
|
async onReady() {
|
|
241
292
|
let launchHeadlessTab;
|
|
242
293
|
const headlessSpecifier = "@qontinui/ui-bridge-headless";
|
|
@@ -264,6 +315,13 @@ Underlying import error: ${cause}`
|
|
|
264
315
|
const initScripts = await this.buildInitScripts();
|
|
265
316
|
const relayAuth = this.relayAuth();
|
|
266
317
|
const pinnedTabId = this.pinnedTabId();
|
|
318
|
+
const { recordHar, recordVideo, serviceWorkers, initRouter: callerRouter } = this.options;
|
|
319
|
+
const contextOptionsRequested = recordHar !== void 0 || recordVideo !== void 0 || serviceWorkers === "block" || callerRouter !== void 0;
|
|
320
|
+
let routerCalled = false;
|
|
321
|
+
const initRouter = contextOptionsRequested || serviceWorkers !== void 0 ? async (context) => {
|
|
322
|
+
routerCalled = true;
|
|
323
|
+
if (callerRouter) await callerRouter(context);
|
|
324
|
+
} : void 0;
|
|
267
325
|
let tab;
|
|
268
326
|
try {
|
|
269
327
|
tab = await launchHeadlessTab({
|
|
@@ -282,7 +340,11 @@ Underlying import error: ${cause}`
|
|
|
282
340
|
storageStatePath: this.options.storageStatePath,
|
|
283
341
|
...relayAuth.authToken ? { authToken: relayAuth.authToken } : {},
|
|
284
342
|
...relayAuth.callerUserId ? { callerUserId: relayAuth.callerUserId } : {},
|
|
285
|
-
...pinnedTabId ? { pinnedTabId } : {}
|
|
343
|
+
...pinnedTabId ? { pinnedTabId } : {},
|
|
344
|
+
...recordHar !== void 0 ? { recordHar } : {},
|
|
345
|
+
...recordVideo !== void 0 ? { recordVideo } : {},
|
|
346
|
+
...serviceWorkers !== void 0 ? { serviceWorkers } : {},
|
|
347
|
+
...initRouter ? { initRouter } : {}
|
|
286
348
|
});
|
|
287
349
|
} catch (err) {
|
|
288
350
|
const cause = err instanceof Error ? err.message : String(err);
|
|
@@ -304,6 +366,24 @@ Underlying launch error: ${cause}`
|
|
|
304
366
|
tabId: tab.tabId,
|
|
305
367
|
close: tab.close
|
|
306
368
|
};
|
|
369
|
+
if (contextOptionsRequested && !routerCalled) {
|
|
370
|
+
await this.onClose().catch(() => {
|
|
371
|
+
});
|
|
372
|
+
throw new WrapperTransportError(
|
|
373
|
+
"CONTEXT_OPTIONS_NOT_APPLIED",
|
|
374
|
+
`The installed '@qontinui/ui-bridge-headless' peer launched the tab without calling initRouter, so it predates the recordHar / recordVideo / serviceWorkers / initRouter passthrough (0.8.0, ui-bridge#381) and ignored them: no HAR or video would be written and no route installed. Upgrade it to 0.8.0 or later.`,
|
|
375
|
+
{
|
|
376
|
+
details: {
|
|
377
|
+
requested: {
|
|
378
|
+
recordHar: recordHar !== void 0,
|
|
379
|
+
recordVideo: recordVideo !== void 0,
|
|
380
|
+
serviceWorkers: serviceWorkers ?? null,
|
|
381
|
+
initRouter: callerRouter !== void 0
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
);
|
|
386
|
+
}
|
|
307
387
|
await this.verifyEmulation(tab.page);
|
|
308
388
|
await this.afterLaunch(tab.page);
|
|
309
389
|
}
|
|
@@ -561,7 +641,7 @@ var InjectedTransport = class extends HeadlessTransport {
|
|
|
561
641
|
}
|
|
562
642
|
/**
|
|
563
643
|
* Best-effort digest of the first {@link DIGEST_MAX_ELEMENTS} registered
|
|
564
|
-
* interactive elements, read through the in-page dispatcher's
|
|
644
|
+
* interactive and media elements, read through the in-page dispatcher's
|
|
565
645
|
* `getControlSnapshot` action (the snapshot's per-element projection is
|
|
566
646
|
* already redaction-safe — we never read raw DOM labels here). Returns
|
|
567
647
|
* `null` on ANY failure or timeout: this feeds error diagnostics only, and a
|
|
@@ -583,7 +663,10 @@ var InjectedTransport = class extends HeadlessTransport {
|
|
|
583
663
|
const elements = snapshot.elements;
|
|
584
664
|
if (!Array.isArray(elements)) return null;
|
|
585
665
|
const digest = [];
|
|
586
|
-
|
|
666
|
+
const counted = elements.filter(
|
|
667
|
+
(el) => el?.category !== "content"
|
|
668
|
+
);
|
|
669
|
+
for (const el of counted.slice(0, DIGEST_MAX_ELEMENTS)) {
|
|
587
670
|
if (!el || typeof el !== "object") continue;
|
|
588
671
|
const e = el;
|
|
589
672
|
if (typeof e.id !== "string") continue;
|
|
@@ -647,6 +730,7 @@ var InjectedTransport = class extends HeadlessTransport {
|
|
|
647
730
|
execute,
|
|
648
731
|
find: (criteria) => execute("find", criteria ?? {}),
|
|
649
732
|
act: (id, request) => execute("executeElementAction", { id, request }),
|
|
733
|
+
element: (id) => execute("getElement", { id }),
|
|
650
734
|
snapshot: (options) => execute("getControlSnapshot", options ?? {}),
|
|
651
735
|
assert: (spec) => execute("aiAssert", spec)
|
|
652
736
|
};
|