@qontinui/ui-bridge-wrapper 0.4.2 → 0.6.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 +4 -4
- package/dist/capture-specs-cli.cjs +34 -4
- package/dist/capture-specs-cli.cjs.map +1 -1
- package/dist/index.cjs +34 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +34 -4
- package/dist/index.js.map +1 -1
- package/dist/inject-cli.cjs +123 -4
- package/dist/inject-cli.cjs.map +1 -1
- package/dist/inject-cli.d.ts +29 -1
- package/dist/inject-cli.d.ts.map +1 -1
- package/dist/login-web-cli.cjs +150 -10
- package/dist/login-web-cli.cjs.map +1 -1
- package/dist/login-web-cli.d.ts +5 -1
- package/dist/login-web-cli.d.ts.map +1 -1
- package/dist/session-storage-capture.d.ts +78 -0
- package/dist/session-storage-capture.d.ts.map +1 -0
- package/dist/transports/headless.d.ts +26 -0
- package/dist/transports/headless.d.ts.map +1 -1
- package/dist/transports/injected.d.ts +10 -0
- package/dist/transports/injected.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/inject-cli.d.ts
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* pure functions so they can be unit-tested without spawning a browser or
|
|
22
22
|
* calling `main()`.
|
|
23
23
|
*/
|
|
24
|
-
export declare const USAGE = "ui-bridge-inject \u2014 drive UI Bridge's injected transport against a UI-Bridge-free page\n\nRequired:\n --url <pageUrl> Page to open. Must start with http:// or https://\n (maps to the transport's options.targetUrl)\n\nRelay (Variant B \u2014 the default mode; --relay is REQUIRED in this mode):\n --relay <uiBridgeBase> UI Bridge relay base; the injected runtime registers\n as a relay tab. Example: http://localhost:3001/api/ui-bridge\n --auth-token <T> Bearer token for an auth-gated relay\n --registration-metadata <json>\n JSON {\"userId\":\"...\",\"sessionId\":\"...\"} for per-user\n tab-scoping on relay heartbeats\n --app-id <id> App id reported to the relay registry\n --app-name <name> Display name reported to the relay registry\n --tab-id <id> Stable per-tab id override\n\nExec (Variant A \u2014 one-shot; presence of any --exec/--exec-stdin selects this mode):\n --exec '<action> <json>' Run one action (repeatable). The value is an action\n id, a space, then a JSON payload (payload optional \u2192\n defaults {}). Example: --exec 'find {\"text\":\"Sign in\"}'\n --exec-stdin Read NDJSON lines from stdin; each line is\n {\"action\":\"...\",\"payload\":{...}}\n\nOptional:\n --headed Launch with a visible window (default: headless)\n --ready-timeout <ms> Max wait for the injected runtime ready/settle gate (default 30000)\n --no-settle Gate ready on the runtime being live only, NOT on the DOM\n settling. By default the launcher waits for the page to paint\n + go quiet (so a client-rendered SPA is drivable immediately),\n which is almost always what you want.\n --settle-quiet <ms> Quiet window with no DOM re-seed before settled (default 500)\n --settle-timeout <ms> Hard cap before settling regardless of mutations (default 10000)\n --expect-selector <css> Don't settle until an element matching this CSS selector\n exists \u2014 use when the target control (e.g. a login form)\n mounts lazily after unrelated chrome. If it never appears\n before --settle-timeout, ready() fails with a BLOCKED error\n instead of returning a control-less page.\n --viewport <WxH> Viewport size, e.g. 1280x720\n --quiet Suppress human-readable logs (JSON results still print)\n --help, -h Print this help and exit\n\nExamples:\n # Variant B: register an injected tab against a relay and stay alive\n ui-bridge-inject --url https://example.com/login \\\n --relay http://localhost:3001/api/ui-bridge --app-name \"example login\"\n\n # Variant A: snapshot the controls on a page, then exit\n ui-bridge-inject --url https://example.com/login \\\n --exec 'getControlSnapshot {}'\n\n # Variant A: find a control and act on it\n ui-bridge-inject --url https://example.com/login \\\n --exec 'find {\"text\":\"Sign in\"}'\n";
|
|
24
|
+
export declare const USAGE = "ui-bridge-inject \u2014 drive UI Bridge's injected transport against a UI-Bridge-free page\n\nRequired:\n --url <pageUrl> Page to open. Must start with http:// or https://\n (maps to the transport's options.targetUrl)\n\nRelay (Variant B \u2014 the default mode; --relay is REQUIRED in this mode):\n --relay <uiBridgeBase> UI Bridge relay base; the injected runtime registers\n as a relay tab. Example: http://localhost:3001/api/ui-bridge\n --auth-token <T> Bearer token for an auth-gated relay\n --registration-metadata <json>\n JSON {\"userId\":\"...\",\"sessionId\":\"...\"} for per-user\n tab-scoping on relay heartbeats\n --app-id <id> App id reported to the relay registry\n --app-name <name> Display name reported to the relay registry\n --tab-id <id> Stable per-tab id override\n\nExec (Variant A \u2014 one-shot; presence of any --exec/--exec-stdin selects this mode):\n --exec '<action> <json>' Run one action (repeatable). The value is an action\n id, a space, then a JSON payload (payload optional \u2192\n defaults {}). Example: --exec 'find {\"text\":\"Sign in\"}'\n --exec-stdin Read NDJSON lines from stdin; each line is\n {\"action\":\"...\",\"payload\":{...}}\n\nOptional:\n --storage-state <path> Seed the browser context from a Playwright storageState\n JSON file (cookies + localStorage) produced by\n 'ui-bridge-login-web --storage-state-out <path>'. This\n carries a saved authenticated session past a login wall,\n so you can drive a login-walled page (e.g. an /admin\n wizard) WITHOUT re-driving the hosted-UI login each run.\n --headed Launch with a visible window (default: headless)\n --ready-timeout <ms> Max wait for the injected runtime ready/settle gate (default 30000)\n --no-settle Gate ready on the runtime being live only, NOT on the DOM\n settling. By default the launcher waits for the page to paint\n + go quiet (so a client-rendered SPA is drivable immediately),\n which is almost always what you want.\n --settle-quiet <ms> Quiet window with no DOM re-seed before settled (default 500)\n --settle-timeout <ms> Hard cap before settling regardless of mutations (default 10000)\n --expect-selector <css> Don't settle until an element matching this CSS selector\n exists \u2014 use when the target control (e.g. a login form)\n mounts lazily after unrelated chrome. If it never appears\n before --settle-timeout, ready() fails with a BLOCKED error\n instead of returning a control-less page.\n --viewport <WxH> Viewport size, e.g. 1280x720\n --launch-arg <arg> Extra Chromium command-line argument (repeatable),\n passed through to chromium.launch({ args }).\n NOTE: when --url is https and --relay resolves to a\n loopback host, the LNA-disable flags\n (--disable-features=LocalNetworkAccessChecks,...) are\n auto-appended \u2014 Chromium otherwise blocks the\n https-page \u2192 loopback-relay fetch (Local Network Access).\n --quiet Suppress human-readable logs (JSON results still print)\n --help, -h Print this help and exit\n\nExamples:\n # Variant B: register an injected tab against a relay and stay alive\n ui-bridge-inject --url https://example.com/login \\\n --relay http://localhost:3001/api/ui-bridge --app-name \"example login\"\n\n # Variant A: snapshot the controls on a page, then exit\n ui-bridge-inject --url https://example.com/login \\\n --exec 'getControlSnapshot {}'\n\n # Variant A: find a control and act on it\n ui-bridge-inject --url https://example.com/login \\\n --exec 'find {\"text\":\"Sign in\"}'\n\n # Reuse a saved login: drive a login-walled page with a captured auth artifact\n ui-bridge-login-web --url \"https://qontinui.io/login?next=%2Fadmin\" \\\n --success /admin --storage-state-out auth.json\n ui-bridge-inject --url https://qontinui.io/admin \\\n --storage-state auth.json --exec 'getControlSnapshot {}'\n";
|
|
25
25
|
/** A single Variant-A action to execute. */
|
|
26
26
|
export interface ExecAction {
|
|
27
27
|
action: string;
|
|
@@ -48,6 +48,10 @@ export interface InjectCliArgs {
|
|
|
48
48
|
tabId: string | null;
|
|
49
49
|
viewportWidth: number | null;
|
|
50
50
|
viewportHeight: number | null;
|
|
51
|
+
/** Path to a Playwright storageState JSON file to seed the context (from --storage-state). */
|
|
52
|
+
storageState: string | null;
|
|
53
|
+
/** Extra Chromium launch args collected from --launch-arg flags (in order). */
|
|
54
|
+
launchArgs: string[];
|
|
51
55
|
/** Variant-A actions collected from --exec flags (in order). */
|
|
52
56
|
execActions: ExecAction[];
|
|
53
57
|
/** True if --exec-stdin was given (read NDJSON from stdin in Variant A). */
|
|
@@ -77,6 +81,30 @@ export declare function validateArgs(args: InjectCliArgs): void;
|
|
|
77
81
|
* otherwise relay registration (Variant B, the default).
|
|
78
82
|
*/
|
|
79
83
|
export declare function selectMode(args: InjectCliArgs): 'exec' | 'relay';
|
|
84
|
+
/**
|
|
85
|
+
* Chromium feature flags that must be DISABLED for an https page to fetch a
|
|
86
|
+
* loopback (local-network) relay. Chromium's Local Network Access checks
|
|
87
|
+
* otherwise block `https://example.com` → `http://127.0.0.1:<port>` with
|
|
88
|
+
* "Permission was denied for this request to access the 'loopback' address
|
|
89
|
+
* space" (plan 2026-06-12 item 2).
|
|
90
|
+
*/
|
|
91
|
+
export declare const LNA_DISABLE_FEATURES: readonly ["LocalNetworkAccessChecks", "PrivateNetworkAccessSendPreflights", "PrivateNetworkAccessRespectPreflightResults"];
|
|
92
|
+
/** True when a URL hostname is a loopback address (localhost / 127/8 / ::1). */
|
|
93
|
+
export declare function isLoopbackHost(hostname: string): boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Compute the effective Chromium launch args: the user's `--launch-arg`
|
|
96
|
+
* values, plus the LNA-disable features auto-appended when the target page
|
|
97
|
+
* is https AND the relay resolves to a loopback host (the combination
|
|
98
|
+
* Chromium's Local Network Access checks block). If the user already passed
|
|
99
|
+
* a `--disable-features=` arg, the missing LNA features are merged into it
|
|
100
|
+
* (Chromium does not union repeated `--disable-features` flags).
|
|
101
|
+
*
|
|
102
|
+
* Pure — exported for unit tests.
|
|
103
|
+
*/
|
|
104
|
+
export declare function buildLaunchArgs(args: Pick<InjectCliArgs, 'url' | 'relay' | 'launchArgs'>): {
|
|
105
|
+
launchArgs: string[];
|
|
106
|
+
lnaAutoAppended: boolean;
|
|
107
|
+
};
|
|
80
108
|
/**
|
|
81
109
|
* Build the `options` object for `createTransport({ kind: 'injected', options })`.
|
|
82
110
|
* Only includes keys the user provided; `targetUrl` is always present.
|
package/dist/inject-cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inject-cli.d.ts","sourceRoot":"","sources":["../src/inject-cli.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAOH,eAAO,MAAM,KAAK,
|
|
1
|
+
{"version":3,"file":"inject-cli.d.ts","sourceRoot":"","sources":["../src/inject-cli.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAOH,eAAO,MAAM,KAAK,2sJAyEjB,CAAC;AAEF,4CAA4C;AAC5C,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,uCAAuC;AACvC,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,oBAAoB,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IACnE,MAAM,EAAE,OAAO,CAAC;IAChB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,iFAAiF;IACjF,aAAa,EAAE,OAAO,CAAC;IACvB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,8FAA8F;IAC9F,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,+EAA+E;IAC/E,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,gEAAgE;IAChE,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,4EAA4E;IAC5E,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,OAAO,CAAC;IACf,IAAI,EAAE,OAAO,CAAC;CACf;AAED;;;GAGG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;gBAC9B,OAAO,EAAE,MAAM;CAI5B;AA2BD;;;GAGG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,aAAa,CA8LvD;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,aAAa,GAAG,IAAI,CActD;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,aAAa,GAAG,MAAM,GAAG,OAAO,CAEhE;AAED;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,4HAIvB,CAAC;AAEX,gFAAgF;AAChF,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CASxD;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,IAAI,CAAC,aAAa,EAAE,KAAK,GAAG,OAAO,GAAG,YAAY,CAAC,GACxD;IAAE,UAAU,EAAE,MAAM,EAAE,CAAC;IAAC,eAAe,EAAE,OAAO,CAAA;CAAE,CA8BpD;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAoBlF"}
|
package/dist/login-web-cli.cjs
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
var url = require('url');
|
|
5
|
-
var module$1 = require('module');
|
|
6
5
|
var fs = require('fs');
|
|
6
|
+
var module$1 = require('module');
|
|
7
7
|
|
|
8
8
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
9
9
|
// src/types.ts
|
|
@@ -224,13 +224,17 @@ var HeadlessTransport = class extends BaseTransport {
|
|
|
224
224
|
uiBridgeBase: typeof raw["uiBridgeBase"] === "string" ? raw["uiBridgeBase"] : void 0,
|
|
225
225
|
waitForUiBridgeMs: typeof raw["waitForUiBridgeMs"] === "number" ? raw["waitForUiBridgeMs"] : void 0,
|
|
226
226
|
userAgent: typeof raw["userAgent"] === "string" ? raw["userAgent"] : void 0,
|
|
227
|
-
forwardConsole: typeof raw["forwardConsole"] === "boolean" ? raw["forwardConsole"] : void 0
|
|
227
|
+
forwardConsole: typeof raw["forwardConsole"] === "boolean" ? raw["forwardConsole"] : void 0,
|
|
228
|
+
launchArgs: Array.isArray(raw["launchArgs"]) && raw["launchArgs"].every((a) => typeof a === "string") ? raw["launchArgs"] : void 0,
|
|
229
|
+
storageStatePath: typeof raw["storageStatePath"] === "string" ? raw["storageStatePath"] : void 0
|
|
228
230
|
};
|
|
229
231
|
}
|
|
230
232
|
async onReady() {
|
|
231
233
|
let launchHeadlessTab;
|
|
234
|
+
const headlessSpecifier = "@qontinui/ui-bridge-headless";
|
|
232
235
|
try {
|
|
233
|
-
|
|
236
|
+
const mod = await import(headlessSpecifier);
|
|
237
|
+
({ launchHeadlessTab } = mod);
|
|
234
238
|
} catch (err) {
|
|
235
239
|
const cause = err instanceof Error ? err.message : String(err);
|
|
236
240
|
const code = err?.code;
|
|
@@ -250,6 +254,7 @@ Underlying import error: ${cause}`
|
|
|
250
254
|
);
|
|
251
255
|
}
|
|
252
256
|
const initScripts = await this.buildInitScripts();
|
|
257
|
+
const relayAuth = this.relayAuth();
|
|
253
258
|
let tab;
|
|
254
259
|
try {
|
|
255
260
|
tab = await launchHeadlessTab({
|
|
@@ -261,7 +266,11 @@ Underlying import error: ${cause}`
|
|
|
261
266
|
viewportHeight: this.options.viewportHeight,
|
|
262
267
|
userAgent: this.options.userAgent,
|
|
263
268
|
forwardConsole: this.options.forwardConsole,
|
|
264
|
-
initScripts: initScripts.length > 0 ? initScripts : void 0
|
|
269
|
+
initScripts: initScripts.length > 0 ? initScripts : void 0,
|
|
270
|
+
launchArgs: this.options.launchArgs && this.options.launchArgs.length > 0 ? this.options.launchArgs : void 0,
|
|
271
|
+
storageStatePath: this.options.storageStatePath,
|
|
272
|
+
...relayAuth.authToken ? { authToken: relayAuth.authToken } : {},
|
|
273
|
+
...relayAuth.callerUserId ? { callerUserId: relayAuth.callerUserId } : {}
|
|
265
274
|
});
|
|
266
275
|
} catch (err) {
|
|
267
276
|
const cause = err instanceof Error ? err.message : String(err);
|
|
@@ -293,6 +302,15 @@ Underlying launch error: ${cause}`
|
|
|
293
302
|
async buildInitScripts() {
|
|
294
303
|
return [];
|
|
295
304
|
}
|
|
305
|
+
/**
|
|
306
|
+
* Subclass hook: credentials for the launcher's Node-side relay registration
|
|
307
|
+
* poll (`<uiBridgeBase>/tabs`). Default: none (anonymous poll — correct for an
|
|
308
|
+
* ungated relay). Injected mode overrides this with the `--auth-token` bearer
|
|
309
|
+
* and the `--registration-metadata` userId.
|
|
310
|
+
*/
|
|
311
|
+
relayAuth() {
|
|
312
|
+
return {};
|
|
313
|
+
}
|
|
296
314
|
/**
|
|
297
315
|
* Subclass hook: run after launch + navigation, before `ready()` resolves.
|
|
298
316
|
* Default: no-op. Injected mode overrides it to await the in-page runtime.
|
|
@@ -386,8 +404,8 @@ var InjectedTransport = class extends HeadlessTransport {
|
|
|
386
404
|
cfg.registrationMetadata = this.injected.registrationMetadata;
|
|
387
405
|
if (this.injected.appId) cfg.appId = this.injected.appId;
|
|
388
406
|
if (this.injected.appName) cfg.appName = this.injected.appName;
|
|
389
|
-
if (this.injected.tabId) cfg.tabId = this.injected.tabId;
|
|
390
407
|
}
|
|
408
|
+
if (this.injected.tabId) cfg.tabId = this.injected.tabId;
|
|
391
409
|
if (this.injected.settleQuietMs !== void 0)
|
|
392
410
|
cfg.settleQuietMs = this.injected.settleQuietMs;
|
|
393
411
|
if (this.injected.settleTimeoutMs !== void 0)
|
|
@@ -396,6 +414,18 @@ var InjectedTransport = class extends HeadlessTransport {
|
|
|
396
414
|
cfg.expectSelector = this.injected.expectSelector;
|
|
397
415
|
return Object.keys(cfg).length > 0 ? cfg : null;
|
|
398
416
|
}
|
|
417
|
+
/**
|
|
418
|
+
* The relay credentials the Node-side registration poll needs. Same bearer the
|
|
419
|
+
* page-side client gets via `__uiBridgeInjectedConfig.authToken`; without it
|
|
420
|
+
* the poll against a gated relay 401s and the CLI reports `tabId: null` on a
|
|
421
|
+
* launch that actually registered.
|
|
422
|
+
*/
|
|
423
|
+
relayAuth() {
|
|
424
|
+
return {
|
|
425
|
+
...this.injected.authToken ? { authToken: this.injected.authToken } : {},
|
|
426
|
+
...this.injected.registrationMetadata?.userId ? { callerUserId: this.injected.registrationMetadata.userId } : {}
|
|
427
|
+
};
|
|
428
|
+
}
|
|
399
429
|
async buildInitScripts() {
|
|
400
430
|
const scripts = [];
|
|
401
431
|
const cfg = this.injectedConfig();
|
|
@@ -720,6 +750,38 @@ function createTransport(config) {
|
|
|
720
750
|
}
|
|
721
751
|
}
|
|
722
752
|
|
|
753
|
+
// src/session-storage-capture.ts
|
|
754
|
+
function isCapturableOrigin(origin) {
|
|
755
|
+
return typeof origin === "string" && origin.length > 0 && origin !== "null";
|
|
756
|
+
}
|
|
757
|
+
function frameOrigin(frameUrl) {
|
|
758
|
+
try {
|
|
759
|
+
const origin = new URL(frameUrl).origin;
|
|
760
|
+
return isCapturableOrigin(origin) ? origin : null;
|
|
761
|
+
} catch {
|
|
762
|
+
return null;
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
function buildMultiOriginSessionStorageMap(frames) {
|
|
766
|
+
const out = {};
|
|
767
|
+
for (const frame of frames) {
|
|
768
|
+
if (frame.kv === null) continue;
|
|
769
|
+
const origin = frameOrigin(frame.url);
|
|
770
|
+
if (origin === null) continue;
|
|
771
|
+
out[origin] = { ...out[origin] ?? {}, ...frame.kv };
|
|
772
|
+
}
|
|
773
|
+
return out;
|
|
774
|
+
}
|
|
775
|
+
function mergeMultiOriginSessionStorageIntoArtifact(artifact, map) {
|
|
776
|
+
const existing = artifact.__sessionStorage && typeof artifact.__sessionStorage === "object" ? artifact.__sessionStorage : {};
|
|
777
|
+
const merged = { ...existing };
|
|
778
|
+
for (const origin of Object.keys(map)) {
|
|
779
|
+
merged[origin] = { ...map[origin] };
|
|
780
|
+
}
|
|
781
|
+
artifact.__sessionStorage = merged;
|
|
782
|
+
return artifact;
|
|
783
|
+
}
|
|
784
|
+
|
|
723
785
|
// src/cli-args.ts
|
|
724
786
|
var COMMON_FLAGS = /* @__PURE__ */ new Set(["--help", "-h", "--quiet"]);
|
|
725
787
|
function isFlagShaped(value) {
|
|
@@ -936,6 +998,14 @@ Options:
|
|
|
936
998
|
--screenshot <path> Write a full-page PNG of the authed landing to
|
|
937
999
|
<path> (captured BEFORE the --expect-text check, so
|
|
938
1000
|
a failing assertion still leaves a diagnostic image).
|
|
1001
|
+
--storage-state-out <path> On a confirmed-authed landing, write a Playwright
|
|
1002
|
+
storageState JSON (cookies + localStorage) to <path>,
|
|
1003
|
+
PLUS a custom __sessionStorage key (origin \u2192 kv) so
|
|
1004
|
+
cold replays land authed on apps that keep their
|
|
1005
|
+
token in sessionStorage (e.g. qontinui-web).
|
|
1006
|
+
Feed it to 'ui-bridge-inject --storage-state <path>'
|
|
1007
|
+
to drive a login-walled page MANY times without
|
|
1008
|
+
re-driving the hosted-UI login each run.
|
|
939
1009
|
--keep-open On success, park the authed session until SIGINT/
|
|
940
1010
|
SIGTERM instead of closing the browser.
|
|
941
1011
|
--quiet Suppress human-readable stderr logs (the JSON
|
|
@@ -955,6 +1025,11 @@ Examples:
|
|
|
955
1025
|
ui-bridge-login-web --url "https://qontinui.io/login?next=%2Foperations" \\
|
|
956
1026
|
--success /operations --expect-text "option2-actions-outage-drill,metric_threshold" \\
|
|
957
1027
|
--screenshot out.png
|
|
1028
|
+
# Capture a reusable auth artifact, then drive a login-walled page with it:
|
|
1029
|
+
ui-bridge-login-web --url "https://qontinui.io/login?next=%2Fadmin%2Fcoord%2Fonboarding" \\
|
|
1030
|
+
--success /admin/coord/onboarding --storage-state-out auth.json
|
|
1031
|
+
ui-bridge-inject --url https://qontinui.io/admin/coord/onboarding \\
|
|
1032
|
+
--storage-state auth.json --exec 'getControlSnapshot {}'
|
|
958
1033
|
`;
|
|
959
1034
|
var LoginCliArgError = class extends Error {
|
|
960
1035
|
constructor(message) {
|
|
@@ -986,6 +1061,7 @@ function parseArgs(argv) {
|
|
|
986
1061
|
expectText: (valueOf("--expect-text") ?? "").split(",").map((s) => s.trim()).filter((s) => s.length > 0),
|
|
987
1062
|
scrollToText: valueOf("--scroll-to"),
|
|
988
1063
|
screenshotPath: valueOf("--screenshot"),
|
|
1064
|
+
storageStateOut: valueOf("--storage-state-out"),
|
|
989
1065
|
keepOpen: has("--keep-open"),
|
|
990
1066
|
quiet: has("--quiet"),
|
|
991
1067
|
help
|
|
@@ -1004,6 +1080,7 @@ var KNOWN_FLAGS = /* @__PURE__ */ new Set([
|
|
|
1004
1080
|
"--expect-text",
|
|
1005
1081
|
"--scroll-to",
|
|
1006
1082
|
"--screenshot",
|
|
1083
|
+
"--storage-state-out",
|
|
1007
1084
|
"--keep-open",
|
|
1008
1085
|
...COMMON_FLAGS
|
|
1009
1086
|
]);
|
|
@@ -1035,7 +1112,19 @@ ${USAGE}`);
|
|
|
1035
1112
|
process.stdout.write(USAGE);
|
|
1036
1113
|
process.exit(0);
|
|
1037
1114
|
}
|
|
1038
|
-
const {
|
|
1115
|
+
const {
|
|
1116
|
+
url,
|
|
1117
|
+
email,
|
|
1118
|
+
password,
|
|
1119
|
+
success,
|
|
1120
|
+
timeoutMs,
|
|
1121
|
+
headed,
|
|
1122
|
+
postClick,
|
|
1123
|
+
expectText,
|
|
1124
|
+
scrollToText,
|
|
1125
|
+
screenshotPath,
|
|
1126
|
+
storageStateOut
|
|
1127
|
+
} = args;
|
|
1039
1128
|
const log = makeLogger("[login-web]", args.quiet);
|
|
1040
1129
|
const transport = createTransport({
|
|
1041
1130
|
kind: "injected",
|
|
@@ -1050,9 +1139,12 @@ ${USAGE}`);
|
|
|
1050
1139
|
}
|
|
1051
1140
|
const finalUrl = page.url();
|
|
1052
1141
|
log(`final ${finalUrl}`);
|
|
1053
|
-
await page.waitForFunction(
|
|
1054
|
-
|
|
1055
|
-
|
|
1142
|
+
await page.waitForFunction(
|
|
1143
|
+
() => window.__uiBridgeInjected?.ready === true,
|
|
1144
|
+
{
|
|
1145
|
+
timeout: 15e3
|
|
1146
|
+
}
|
|
1147
|
+
).catch(() => {
|
|
1056
1148
|
});
|
|
1057
1149
|
let snap = null;
|
|
1058
1150
|
try {
|
|
@@ -1077,6 +1169,9 @@ ${USAGE}`);
|
|
|
1077
1169
|
await target.click();
|
|
1078
1170
|
postLoginClicked = true;
|
|
1079
1171
|
log(`post-login click: ${postClick}`);
|
|
1172
|
+
await target.waitFor({ state: "hidden", timeout: 2e3 }).catch(
|
|
1173
|
+
() => log(`post-login click target still visible after 2s (non-fatal): ${postClick}`)
|
|
1174
|
+
);
|
|
1080
1175
|
} catch {
|
|
1081
1176
|
log(`post-login click target never visible (non-fatal): ${postClick}`);
|
|
1082
1177
|
}
|
|
@@ -1094,6 +1189,50 @@ ${USAGE}`);
|
|
|
1094
1189
|
log(`screenshot failed (non-fatal): ${err instanceof Error ? err.message : String(err)}`);
|
|
1095
1190
|
}
|
|
1096
1191
|
}
|
|
1192
|
+
let storageStateWritten = null;
|
|
1193
|
+
if (ok && storageStateOut) {
|
|
1194
|
+
try {
|
|
1195
|
+
await ctx.browserContext.storageState({ path: storageStateOut });
|
|
1196
|
+
storageStateWritten = storageStateOut;
|
|
1197
|
+
log(`storage-state written: ${storageStateOut}`);
|
|
1198
|
+
try {
|
|
1199
|
+
const frames = [];
|
|
1200
|
+
for (const frame of page.frames()) {
|
|
1201
|
+
let kv = null;
|
|
1202
|
+
try {
|
|
1203
|
+
kv = await frame.evaluate(() => {
|
|
1204
|
+
const o = {};
|
|
1205
|
+
for (let i = 0; i < sessionStorage.length; i++) {
|
|
1206
|
+
const k = sessionStorage.key(i);
|
|
1207
|
+
if (k !== null) o[k] = sessionStorage.getItem(k) ?? "";
|
|
1208
|
+
}
|
|
1209
|
+
return o;
|
|
1210
|
+
});
|
|
1211
|
+
} catch {
|
|
1212
|
+
kv = null;
|
|
1213
|
+
}
|
|
1214
|
+
frames.push({ url: frame.url(), kv });
|
|
1215
|
+
}
|
|
1216
|
+
const map = buildMultiOriginSessionStorageMap(frames);
|
|
1217
|
+
const artifact = JSON.parse(fs.readFileSync(storageStateOut, "utf8"));
|
|
1218
|
+
mergeMultiOriginSessionStorageIntoArtifact(artifact, map);
|
|
1219
|
+
fs.writeFileSync(storageStateOut, JSON.stringify(artifact));
|
|
1220
|
+
const origins = Object.keys(map);
|
|
1221
|
+
const keyCount = origins.reduce((n, o) => n + Object.keys(map[o]).length, 0);
|
|
1222
|
+
log(
|
|
1223
|
+
`sessionStorage captured across ${origins.length} origin(s) [${origins.join(", ")}]: ${keyCount} key(s) total`
|
|
1224
|
+
);
|
|
1225
|
+
} catch (err) {
|
|
1226
|
+
log(
|
|
1227
|
+
`sessionStorage capture failed (non-fatal, storageState still written): ${err instanceof Error ? err.message : String(err)}`
|
|
1228
|
+
);
|
|
1229
|
+
}
|
|
1230
|
+
} catch (err) {
|
|
1231
|
+
log(
|
|
1232
|
+
`storage-state export failed (non-fatal): ${err instanceof Error ? err.message : String(err)}`
|
|
1233
|
+
);
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1097
1236
|
let expectFound;
|
|
1098
1237
|
let expectMissing;
|
|
1099
1238
|
if (ok && expectText.length > 0) {
|
|
@@ -1115,7 +1254,8 @@ ${USAGE}`);
|
|
|
1115
1254
|
postLoginClicked,
|
|
1116
1255
|
expectFound,
|
|
1117
1256
|
expectMissing,
|
|
1118
|
-
screenshotPath: screenshotPath ? screenshotWritten : void 0
|
|
1257
|
+
screenshotPath: screenshotPath ? screenshotWritten : void 0,
|
|
1258
|
+
storageStatePath: storageStateOut ? storageStateWritten : void 0
|
|
1119
1259
|
};
|
|
1120
1260
|
});
|
|
1121
1261
|
let result;
|