@qontinui/ui-bridge-wrapper 0.12.0 → 0.15.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.
Files changed (49) hide show
  1. package/README.md +157 -8
  2. package/dist/capture-specs-cli.cjs +301 -53
  3. package/dist/capture-specs-cli.cjs.map +1 -1
  4. package/dist/capture-specs-cli.d.ts.map +1 -1
  5. package/dist/chunk-IKHDNIU4.js +478 -0
  6. package/dist/chunk-IKHDNIU4.js.map +1 -0
  7. package/dist/chunk-Z32CC665.cjs +488 -0
  8. package/dist/chunk-Z32CC665.cjs.map +1 -0
  9. package/dist/create-transport.d.ts.map +1 -1
  10. package/dist/frame-capture.d.ts +3 -28
  11. package/dist/frame-capture.d.ts.map +1 -1
  12. package/dist/frame-page.d.ts +35 -0
  13. package/dist/frame-page.d.ts.map +1 -0
  14. package/dist/index.cjs +145 -375
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.ts +1 -0
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +90 -351
  19. package/dist/index.js.map +1 -1
  20. package/dist/inject-cli.cjs +407 -134
  21. package/dist/inject-cli.cjs.map +1 -1
  22. package/dist/inject-cli.d.ts +1 -1
  23. package/dist/inject-cli.d.ts.map +1 -1
  24. package/dist/live/index.cjs +40 -0
  25. package/dist/live/index.cjs.map +1 -0
  26. package/dist/live/index.d.ts +32 -0
  27. package/dist/live/index.d.ts.map +1 -0
  28. package/dist/live/index.js +3 -0
  29. package/dist/live/index.js.map +1 -0
  30. package/dist/login-web-cli.cjs +312 -61
  31. package/dist/login-web-cli.cjs.map +1 -1
  32. package/dist/login-web-cli.d.ts.map +1 -1
  33. package/dist/network-throttle.d.ts +5 -0
  34. package/dist/network-throttle.d.ts.map +1 -1
  35. package/dist/screenshot-capture.d.ts +82 -0
  36. package/dist/screenshot-capture.d.ts.map +1 -0
  37. package/dist/timeline-capture.d.ts +74 -10
  38. package/dist/timeline-capture.d.ts.map +1 -1
  39. package/dist/transports/headless.d.ts +46 -1
  40. package/dist/transports/headless.d.ts.map +1 -1
  41. package/dist/transports/injected.d.ts +8 -0
  42. package/dist/transports/injected.d.ts.map +1 -1
  43. package/dist/transports/live.d.ts +27 -1
  44. package/dist/transports/live.d.ts.map +1 -1
  45. package/dist/types.d.ts +3 -1
  46. package/dist/types.d.ts.map +1 -1
  47. package/package.json +11 -8
  48. package/dist/cli-args.d.ts +0 -13
  49. package/dist/cli-args.d.ts.map +0 -1
@@ -5,52 +5,19 @@ var fs = require('fs');
5
5
  var path = require('path');
6
6
  var module$1 = require('module');
7
7
  var crypto = require('crypto');
8
- var ui_bridge_cli_args_star = require('@qontinui/ui-bridge-cli-args');
9
8
 
10
9
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
11
10
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
12
11
 
13
- function _interopNamespace(e) {
14
- if (e && e.__esModule) return e;
15
- var n = Object.create(null);
16
- if (e) {
17
- Object.keys(e).forEach(function (k) {
18
- if (k !== 'default') {
19
- var d = Object.getOwnPropertyDescriptor(e, k);
20
- Object.defineProperty(n, k, d.get ? d : {
21
- enumerable: true,
22
- get: function () { return e[k]; }
23
- });
24
- }
25
- });
26
- }
27
- n.default = e;
28
- return Object.freeze(n);
29
- }
30
-
31
12
  var fs__default = /*#__PURE__*/_interopDefault(fs);
32
13
  var path__default = /*#__PURE__*/_interopDefault(path);
33
- var ui_bridge_cli_args_star__namespace = /*#__PURE__*/_interopNamespace(ui_bridge_cli_args_star);
34
14
 
35
- var __defProp = Object.defineProperty;
36
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
37
- var __getOwnPropNames = Object.getOwnPropertyNames;
38
- var __hasOwnProp = Object.prototype.hasOwnProperty;
39
15
  var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
40
16
  get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
41
17
  }) : x)(function(x) {
42
18
  if (typeof require !== "undefined") return require.apply(this, arguments);
43
19
  throw Error('Dynamic require of "' + x + '" is not supported');
44
20
  });
45
- var __copyProps = (to, from, except, desc) => {
46
- if (from && typeof from === "object" || typeof from === "function") {
47
- for (let key of __getOwnPropNames(from))
48
- if (!__hasOwnProp.call(to, key) && key !== except)
49
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
50
- }
51
- return to;
52
- };
53
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget);
54
21
 
55
22
  // src/types.ts
56
23
  var WrapperTransportError = class extends Error {
@@ -284,9 +251,60 @@ var HeadlessTransport = class extends BaseTransport {
284
251
  userAgent: typeof raw["userAgent"] === "string" ? raw["userAgent"] : void 0,
285
252
  forwardConsole: typeof raw["forwardConsole"] === "boolean" ? raw["forwardConsole"] : void 0,
286
253
  launchArgs: Array.isArray(raw["launchArgs"]) && raw["launchArgs"].every((a) => typeof a === "string") ? raw["launchArgs"] : void 0,
287
- storageStatePath: typeof raw["storageStatePath"] === "string" ? raw["storageStatePath"] : void 0
254
+ storageStatePath: typeof raw["storageStatePath"] === "string" ? raw["storageStatePath"] : void 0,
255
+ ...this.parseContextOptions(raw)
288
256
  };
289
257
  }
258
+ /**
259
+ * `recordHar`, `recordVideo`, `serviceWorkers` and `initRouter`. Unlike the display
260
+ * options above, a malformed value is REFUSED rather than dropped: dropping
261
+ * `recordHar` would leave a caller waiting for an archive that is never
262
+ * written, and dropping `initRouter` would let requests it meant to answer
263
+ * reach the network.
264
+ */
265
+ parseContextOptions(raw) {
266
+ const out = {};
267
+ const invalid = (what) => new WrapperTransportError("INVALID_CONFIG", `Transport kind '${this.kind}': ${what}`);
268
+ const har = raw["recordHar"];
269
+ if (har !== void 0) {
270
+ if (typeof har !== "object" || har === null || typeof har.path !== "string" || har.path.length === 0) {
271
+ throw invalid("options.recordHar must be an object with a non-empty string `path`");
272
+ }
273
+ out.recordHar = har;
274
+ }
275
+ const video = raw["recordVideo"];
276
+ if (video !== void 0) {
277
+ if (typeof video !== "object" || video === null || typeof video.dir !== "string" || video.dir.length === 0) {
278
+ throw invalid("options.recordVideo must be an object with a non-empty string `dir`");
279
+ }
280
+ const size = video.size;
281
+ if (size !== void 0) {
282
+ const positiveInt = (n) => typeof n === "number" && Number.isInteger(n) && n > 0;
283
+ const s = size;
284
+ if (typeof size !== "object" || s === null || !positiveInt(s.width) || !positiveInt(s.height)) {
285
+ throw invalid(
286
+ "options.recordVideo.size must be { width, height } with positive integer sides"
287
+ );
288
+ }
289
+ }
290
+ out.recordVideo = video;
291
+ }
292
+ const sw = raw["serviceWorkers"];
293
+ if (sw !== void 0) {
294
+ if (sw !== "allow" && sw !== "block") {
295
+ throw invalid(`options.serviceWorkers must be 'allow' or 'block' (got ${String(sw)})`);
296
+ }
297
+ out.serviceWorkers = sw;
298
+ }
299
+ const router = raw["initRouter"];
300
+ if (router !== void 0) {
301
+ if (typeof router !== "function") {
302
+ throw invalid("options.initRouter must be a function (context) => void | Promise<void>");
303
+ }
304
+ out.initRouter = router;
305
+ }
306
+ return out;
307
+ }
290
308
  async onReady() {
291
309
  let launchHeadlessTab;
292
310
  const headlessSpecifier = "@qontinui/ui-bridge-headless";
@@ -314,6 +332,13 @@ Underlying import error: ${cause}`
314
332
  const initScripts = await this.buildInitScripts();
315
333
  const relayAuth = this.relayAuth();
316
334
  const pinnedTabId = this.pinnedTabId();
335
+ const { recordHar, recordVideo, serviceWorkers, initRouter: callerRouter } = this.options;
336
+ const contextOptionsRequested = recordHar !== void 0 || recordVideo !== void 0 || serviceWorkers === "block" || callerRouter !== void 0;
337
+ let routerCalled = false;
338
+ const initRouter = contextOptionsRequested || serviceWorkers !== void 0 ? async (context) => {
339
+ routerCalled = true;
340
+ if (callerRouter) await callerRouter(context);
341
+ } : void 0;
317
342
  let tab;
318
343
  try {
319
344
  tab = await launchHeadlessTab({
@@ -332,7 +357,11 @@ Underlying import error: ${cause}`
332
357
  storageStatePath: this.options.storageStatePath,
333
358
  ...relayAuth.authToken ? { authToken: relayAuth.authToken } : {},
334
359
  ...relayAuth.callerUserId ? { callerUserId: relayAuth.callerUserId } : {},
335
- ...pinnedTabId ? { pinnedTabId } : {}
360
+ ...pinnedTabId ? { pinnedTabId } : {},
361
+ ...recordHar !== void 0 ? { recordHar } : {},
362
+ ...recordVideo !== void 0 ? { recordVideo } : {},
363
+ ...serviceWorkers !== void 0 ? { serviceWorkers } : {},
364
+ ...initRouter ? { initRouter } : {}
336
365
  });
337
366
  } catch (err) {
338
367
  const cause = err instanceof Error ? err.message : String(err);
@@ -354,6 +383,24 @@ Underlying launch error: ${cause}`
354
383
  tabId: tab.tabId,
355
384
  close: tab.close
356
385
  };
386
+ if (contextOptionsRequested && !routerCalled) {
387
+ await this.onClose().catch(() => {
388
+ });
389
+ throw new WrapperTransportError(
390
+ "CONTEXT_OPTIONS_NOT_APPLIED",
391
+ `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.`,
392
+ {
393
+ details: {
394
+ requested: {
395
+ recordHar: recordHar !== void 0,
396
+ recordVideo: recordVideo !== void 0,
397
+ serviceWorkers: serviceWorkers ?? null,
398
+ initRouter: callerRouter !== void 0
399
+ }
400
+ }
401
+ }
402
+ );
403
+ }
357
404
  await this.verifyEmulation(tab.page);
358
405
  await this.afterLaunch(tab.page);
359
406
  }
@@ -700,6 +747,7 @@ var InjectedTransport = class extends HeadlessTransport {
700
747
  execute,
701
748
  find: (criteria) => execute("find", criteria ?? {}),
702
749
  act: (id, request) => execute("executeElementAction", { id, request }),
750
+ element: (id) => execute("getElement", { id }),
703
751
  snapshot: (options) => execute("getControlSnapshot", options ?? {}),
704
752
  assert: (spec) => execute("aiAssert", spec)
705
753
  };
@@ -711,6 +759,113 @@ function isRegistrationMetadata(value) {
711
759
  return typeof v.userId === "string" && typeof v.sessionId === "string";
712
760
  }
713
761
 
762
+ // src/frame-page.ts
763
+ var PNG_SIGNATURE = [137, 80, 78, 71, 13, 10, 26, 10];
764
+ function pngDimensions(buf) {
765
+ if (buf.length < 24 || PNG_SIGNATURE.some((b, i) => buf[i] !== b)) {
766
+ throw new Error("not a PNG (signature mismatch or truncated header)");
767
+ }
768
+ const chunkType = String.fromCharCode(buf[12], buf[13], buf[14], buf[15]);
769
+ if (chunkType !== "IHDR") {
770
+ throw new Error(`PNG does not start with an IHDR chunk (found ${JSON.stringify(chunkType)})`);
771
+ }
772
+ const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
773
+ return { width: view.getUint32(16), height: view.getUint32(20) };
774
+ }
775
+ async function readPageMetrics(page) {
776
+ return page.evaluate(() => ({
777
+ devicePixelRatio: window.devicePixelRatio,
778
+ innerWidth: window.innerWidth,
779
+ innerHeight: window.innerHeight,
780
+ colorScheme: window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"
781
+ }));
782
+ }
783
+
784
+ // src/screenshot-capture.ts
785
+ var SCREENSHOT_CAPABILITY = "screenshot";
786
+ var SCREENSHOT_ACTION = "getScreenshot";
787
+ var SCREENSHOT_TIMEOUT_MS = 1e4;
788
+ var NO_COMPOSITOR_FRAME = /Unable to capture screenshot/;
789
+ var NO_COMPOSITOR_FRAME_RETRY_MS = 16;
790
+ function toBase64(bytes) {
791
+ const CHUNK = 32768;
792
+ let binary = "";
793
+ for (let i = 0; i < bytes.length; i += CHUNK) {
794
+ binary += String.fromCharCode(...bytes.subarray(i, i + CHUNK));
795
+ }
796
+ return btoa(binary);
797
+ }
798
+ function errorText(err) {
799
+ return err instanceof Error ? err.message : String(err);
800
+ }
801
+ async function captureScreenshotReply(page, options = {}) {
802
+ const timeoutMs = options.timeoutMs ?? SCREENSHOT_TIMEOUT_MS;
803
+ const retryMs = options.retryMs ?? NO_COMPOSITOR_FRAME_RETRY_MS;
804
+ const deadline = Date.now() + timeoutMs;
805
+ let timedOut = false;
806
+ let timer;
807
+ const attempt = async () => {
808
+ let metrics;
809
+ try {
810
+ metrics = await readPageMetrics(page);
811
+ } catch (err) {
812
+ throw new WrapperTransportError(
813
+ "SCREENSHOT_FAILED",
814
+ `could not read the page's viewport: ${errorText(err)}`,
815
+ { cause: err }
816
+ );
817
+ }
818
+ for (; ; ) {
819
+ let png;
820
+ try {
821
+ png = await page.screenshot({ type: "png", scale: "device", fullPage: false });
822
+ } catch (err) {
823
+ const text = errorText(err);
824
+ const noFrameYet = NO_COMPOSITOR_FRAME.test(text);
825
+ if (noFrameYet && !timedOut && Date.now() + retryMs < deadline) {
826
+ await new Promise((r) => setTimeout(r, retryMs));
827
+ if (timedOut) throw err;
828
+ continue;
829
+ }
830
+ throw new WrapperTransportError("SCREENSHOT_FAILED", `screenshot failed: ${text}`, {
831
+ retryable: noFrameYet,
832
+ cause: err
833
+ });
834
+ }
835
+ try {
836
+ pngDimensions(png);
837
+ } catch (err) {
838
+ throw new WrapperTransportError(
839
+ "SCREENSHOT_FAILED",
840
+ `the screenshot is unreadable: ${errorText(err)}`,
841
+ { cause: err }
842
+ );
843
+ }
844
+ return { screenshot: toBase64(png), width: metrics.innerWidth, height: metrics.innerHeight };
845
+ }
846
+ };
847
+ const timeout = new Promise((_, reject) => {
848
+ timer = setTimeout(() => {
849
+ timedOut = true;
850
+ reject(
851
+ new WrapperTransportError(
852
+ "SCREENSHOT_TIMEOUT",
853
+ `screenshot did not complete within ${timeoutMs}ms`,
854
+ { retryable: true }
855
+ )
856
+ );
857
+ }, timeoutMs);
858
+ });
859
+ try {
860
+ return await Promise.race([attempt(), timeout]);
861
+ } finally {
862
+ clearTimeout(timer);
863
+ }
864
+ }
865
+ function registerScreenshotCapture(registrar, page, options = {}) {
866
+ registrar.register(SCREENSHOT_ACTION, () => captureScreenshotReply(page, options));
867
+ }
868
+
714
869
  // src/transports/live.ts
715
870
  var LiveSessionTransport = class extends BaseTransport {
716
871
  kind = "live";
@@ -730,6 +885,16 @@ var LiveSessionTransport = class extends BaseTransport {
730
885
  this.appId = config.appId;
731
886
  this.appName = config.appName;
732
887
  this.opts = config.options ?? {};
888
+ const page = this.opts.screenshotPage;
889
+ if (page !== void 0) {
890
+ if (page === null || typeof page.screenshot !== "function" || typeof page.evaluate !== "function") {
891
+ throw new WrapperTransportError(
892
+ "INVALID_CONFIG",
893
+ `options.screenshotPage must expose screenshot() and evaluate() (a Playwright Page does)`
894
+ );
895
+ }
896
+ registerScreenshotCapture(this.registry, page);
897
+ }
733
898
  const fromInjection = injected?.webSocketCtor;
734
899
  const fromGlobal = typeof globalThis.WebSocket === "function" ? globalThis.WebSocket : void 0;
735
900
  const resolved = fromInjection ?? fromGlobal;
@@ -759,7 +924,8 @@ var LiveSessionTransport = class extends BaseTransport {
759
924
  };
760
925
  if (this.opts.framework !== void 0) frame.framework = this.opts.framework;
761
926
  if (this.opts.version !== void 0) frame.version = this.opts.version;
762
- if (this.opts.capabilities !== void 0) frame.capabilities = this.opts.capabilities;
927
+ const capabilities = this.advertisedCapabilities();
928
+ if (capabilities !== void 0) frame.capabilities = capabilities;
763
929
  if (this.opts.origin !== void 0) frame.origin = this.opts.origin;
764
930
  if (this.opts.pageUrl !== void 0) frame.pageUrl = this.opts.pageUrl;
765
931
  ws.send(JSON.stringify(frame));
@@ -799,6 +965,18 @@ var LiveSessionTransport = class extends BaseTransport {
799
965
  }
800
966
  }
801
967
  }
968
+ /**
969
+ * The register frame's `capabilities`: the caller's list, plus
970
+ * `"screenshot"` exactly when this transport registered the handler for it.
971
+ * `undefined` (field omitted) when there is nothing to advertise.
972
+ */
973
+ advertisedCapabilities() {
974
+ const declared = this.opts.capabilities;
975
+ if (this.opts.screenshotPage === void 0) return declared;
976
+ const list = [...declared ?? []];
977
+ if (!list.includes(SCREENSHOT_CAPABILITY)) list.push(SCREENSHOT_CAPABILITY);
978
+ return list;
979
+ }
802
980
  async buildContext() {
803
981
  return { kind: "live", commandId: null };
804
982
  }
@@ -920,9 +1098,80 @@ function createTransport(config) {
920
1098
  }
921
1099
  }
922
1100
 
923
- // src/cli-args.ts
924
- var cli_args_exports = {};
925
- __reExport(cli_args_exports, ui_bridge_cli_args_star__namespace);
1101
+ // ../ui-bridge-cli-args/dist/index.js
1102
+ var COMMON_FLAGS = /* @__PURE__ */ new Set(["--help", "-h", "--quiet"]);
1103
+ function isFlagShaped(value) {
1104
+ return value.startsWith("--");
1105
+ }
1106
+ function consumeValue(flag, raw, error) {
1107
+ if (raw === void 0) return null;
1108
+ if (isFlagShaped(raw)) {
1109
+ throw error(
1110
+ `${flag} expects a value but got the flag '${raw}' \u2014 did you omit ${flag}'s argument?`
1111
+ );
1112
+ }
1113
+ return raw;
1114
+ }
1115
+ function parsePositiveInt(flag, raw, error) {
1116
+ const n = raw !== null && /^\d+$/.test(raw) ? Number(raw) : NaN;
1117
+ if (!Number.isSafeInteger(n) || n <= 0) {
1118
+ throw error(`${flag} expects a positive integer (got ${raw ?? "<missing>"})`);
1119
+ }
1120
+ return n;
1121
+ }
1122
+ var ArgReader = class {
1123
+ argv;
1124
+ error;
1125
+ valueFlags;
1126
+ /**
1127
+ * @param argv Already sliced past `node script`.
1128
+ * @param known All flags the bin recognizes (union the bin's set with {@link COMMON_FLAGS}).
1129
+ * @param error Factory producing the bin's domain error type.
1130
+ * @param valueFlags The flags that take a value. The token after one is that
1131
+ * flag's value, never a flag of its own, so `--success -h`
1132
+ * does not also ask for help. Without it, {@link has} cannot
1133
+ * tell a value from a flag.
1134
+ */
1135
+ constructor(argv, known, error, valueFlags = /* @__PURE__ */ new Set()) {
1136
+ this.argv = argv;
1137
+ this.error = error;
1138
+ this.valueFlags = valueFlags;
1139
+ for (const arg of argv) {
1140
+ if (isFlagShaped(arg) && !known.has(arg)) {
1141
+ throw error(`Unknown flag: ${arg}`);
1142
+ }
1143
+ }
1144
+ }
1145
+ /** True if `name` appears as a bare boolean flag, not as a value-flag's value. */
1146
+ has(name) {
1147
+ for (let i = 0; i < this.argv.length; i++) {
1148
+ if (this.valueFlags.has(this.argv[i])) {
1149
+ i++;
1150
+ continue;
1151
+ }
1152
+ if (this.argv[i] === name) return true;
1153
+ }
1154
+ return false;
1155
+ }
1156
+ /**
1157
+ * Value following the value-flag `name`, or `null` when the flag is absent OR
1158
+ * has no following token (the caller defaults it). Throws when the following
1159
+ * token is flag-shaped — the swallow this kit exists to kill. Delegates to
1160
+ * {@link consumeValue} so the guard (and its message) live in exactly one
1161
+ * place for both the indexOf-style and switch-style parsers.
1162
+ */
1163
+ value(name) {
1164
+ const i = this.argv.indexOf(name);
1165
+ if (i < 0 || i + 1 >= this.argv.length) return null;
1166
+ return consumeValue(name, this.argv[i + 1], this.error);
1167
+ }
1168
+ };
1169
+ function makeLogger(prefix, quiet) {
1170
+ if (quiet) return () => {
1171
+ };
1172
+ return (m) => process.stderr.write(`${prefix} ${m}
1173
+ `) ;
1174
+ }
926
1175
 
927
1176
  // src/login-drive.ts
928
1177
  var isCognito = (u) => /auth\.qontinui\.io|amazoncognito\.com|\/oauth2\//i.test(u);
@@ -1029,10 +1278,10 @@ async function loginDrive(page, { email, password, timeoutMs, log = () => {
1029
1278
  { timeout: timeoutMs }
1030
1279
  );
1031
1280
  } catch {
1032
- const errorText2 = await scrapeErrorCard(page);
1281
+ const errorText3 = await scrapeErrorCard(page);
1033
1282
  const finalUrl2 = page.url();
1034
1283
  log(`stalled ${finalUrl2}`);
1035
- return { ok: false, finalUrl: finalUrl2, landingPath: pathOf(finalUrl2), errorText: errorText2 };
1284
+ return { ok: false, finalUrl: finalUrl2, landingPath: pathOf(finalUrl2), errorText: errorText3 };
1036
1285
  }
1037
1286
  }
1038
1287
  await page.waitForLoadState("networkidle").catch(() => {
@@ -1046,8 +1295,8 @@ async function loginDrive(page, { email, password, timeoutMs, log = () => {
1046
1295
  const landingPath = await page.evaluate(() => location.pathname).catch(() => pathOf(finalUrl));
1047
1296
  const ok = !isAppLoginPath(finalUrl) && !isCognito(finalUrl) && !/\/auth\/callback/.test(pathOf(finalUrl));
1048
1297
  log(ok ? `authed ${finalUrl}` : `stalled ${finalUrl}`);
1049
- const errorText = ok ? null : await scrapeErrorCard(page);
1050
- return { ok, finalUrl, landingPath, errorText };
1298
+ const errorText2 = ok ? null : await scrapeErrorCard(page);
1299
+ return { ok, finalUrl, landingPath, errorText: errorText2 };
1051
1300
  }
1052
1301
 
1053
1302
  // src/action-outcome.ts
@@ -1142,17 +1391,14 @@ function computeLoginUrl(targets, origin) {
1142
1391
  }
1143
1392
  function parseArgs(argv) {
1144
1393
  const mkError = (m) => new CaptureCliArgError(m);
1145
- const reader = new cli_args_exports.ArgReader(argv, KNOWN_FLAGS, mkError);
1394
+ const reader = new ArgReader(argv, KNOWN_FLAGS, mkError, VALUE_FLAGS);
1146
1395
  const valueOf = (name) => reader.value(name);
1147
1396
  const has = (name) => reader.has(name);
1148
1397
  const help = has("--help") || has("-h");
1149
1398
  const origin = valueOf("--origin") ?? DEFAULT_ORIGIN;
1150
1399
  const device = valueOf("--device") ?? DEFAULT_DEVICE;
1151
1400
  const timeoutRaw = valueOf("--timeout");
1152
- const timeoutMs = timeoutRaw === null ? 7e4 : Number.parseInt(timeoutRaw, 10);
1153
- if (!help && (!Number.isFinite(timeoutMs) || timeoutMs <= 0)) {
1154
- throw new CaptureCliArgError(`--timeout expects a positive integer (got ${timeoutRaw})`);
1155
- }
1401
+ const timeoutMs = timeoutRaw === null || help ? 7e4 : parsePositiveInt("--timeout", timeoutRaw, mkError);
1156
1402
  const pagesSpec = valueOf("--pages");
1157
1403
  let pages = null;
1158
1404
  if (pagesSpec !== null) {
@@ -1177,16 +1423,16 @@ function parseArgs(argv) {
1177
1423
  validateArgs(args);
1178
1424
  return args;
1179
1425
  }
1180
- var KNOWN_FLAGS = /* @__PURE__ */ new Set([
1426
+ var VALUE_FLAGS = /* @__PURE__ */ new Set([
1181
1427
  "--email",
1182
1428
  "--password",
1183
1429
  "--out",
1184
1430
  "--origin",
1185
1431
  "--pages",
1186
1432
  "--device",
1187
- "--timeout",
1188
- ...cli_args_exports.COMMON_FLAGS
1433
+ "--timeout"
1189
1434
  ]);
1435
+ var KNOWN_FLAGS = /* @__PURE__ */ new Set([...VALUE_FLAGS, ...COMMON_FLAGS]);
1190
1436
  function validateArgs(args) {
1191
1437
  if (args.help) return;
1192
1438
  if (!args.email || !args.password) {
@@ -1211,7 +1457,7 @@ ${USAGE}`);
1211
1457
  process.exit(0);
1212
1458
  }
1213
1459
  const { email, password, out, origin, device, timeoutMs } = args;
1214
- const log = (0, cli_args_exports.makeLogger)("[capture]", args.quiet);
1460
+ const log = makeLogger("[capture]", args.quiet);
1215
1461
  const targets = args.pages ?? defaultTargets(origin, device);
1216
1462
  const { loginUrl } = computeLoginUrl(targets, origin);
1217
1463
  const transport = createTransport({
@@ -1260,7 +1506,9 @@ ${USAGE}`);
1260
1506
  totalRegistered: snap?.registration?.totalRegistered ?? null,
1261
1507
  snapshot: snap
1262
1508
  });
1263
- log(` -> route=${snap?.route} registered=${snap?.registration?.totalRegistered} onLogin=${onLogin}`);
1509
+ log(
1510
+ ` -> route=${snap?.route} registered=${snap?.registration?.totalRegistered} onLogin=${onLogin}`
1511
+ );
1264
1512
  }
1265
1513
  return out2;
1266
1514
  });