@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.cjs
CHANGED
|
@@ -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();
|
|
@@ -758,6 +788,12 @@ Exec (Variant A \u2014 one-shot; presence of any --exec/--exec-stdin selects thi
|
|
|
758
788
|
{"action":"...","payload":{...}}
|
|
759
789
|
|
|
760
790
|
Optional:
|
|
791
|
+
--storage-state <path> Seed the browser context from a Playwright storageState
|
|
792
|
+
JSON file (cookies + localStorage) produced by
|
|
793
|
+
'ui-bridge-login-web --storage-state-out <path>'. This
|
|
794
|
+
carries a saved authenticated session past a login wall,
|
|
795
|
+
so you can drive a login-walled page (e.g. an /admin
|
|
796
|
+
wizard) WITHOUT re-driving the hosted-UI login each run.
|
|
761
797
|
--headed Launch with a visible window (default: headless)
|
|
762
798
|
--ready-timeout <ms> Max wait for the injected runtime ready/settle gate (default 30000)
|
|
763
799
|
--no-settle Gate ready on the runtime being live only, NOT on the DOM
|
|
@@ -772,6 +808,13 @@ Optional:
|
|
|
772
808
|
before --settle-timeout, ready() fails with a BLOCKED error
|
|
773
809
|
instead of returning a control-less page.
|
|
774
810
|
--viewport <WxH> Viewport size, e.g. 1280x720
|
|
811
|
+
--launch-arg <arg> Extra Chromium command-line argument (repeatable),
|
|
812
|
+
passed through to chromium.launch({ args }).
|
|
813
|
+
NOTE: when --url is https and --relay resolves to a
|
|
814
|
+
loopback host, the LNA-disable flags
|
|
815
|
+
(--disable-features=LocalNetworkAccessChecks,...) are
|
|
816
|
+
auto-appended \u2014 Chromium otherwise blocks the
|
|
817
|
+
https-page \u2192 loopback-relay fetch (Local Network Access).
|
|
775
818
|
--quiet Suppress human-readable logs (JSON results still print)
|
|
776
819
|
--help, -h Print this help and exit
|
|
777
820
|
|
|
@@ -787,6 +830,12 @@ Examples:
|
|
|
787
830
|
# Variant A: find a control and act on it
|
|
788
831
|
ui-bridge-inject --url https://example.com/login \\
|
|
789
832
|
--exec 'find {"text":"Sign in"}'
|
|
833
|
+
|
|
834
|
+
# Reuse a saved login: drive a login-walled page with a captured auth artifact
|
|
835
|
+
ui-bridge-login-web --url "https://qontinui.io/login?next=%2Fadmin" \\
|
|
836
|
+
--success /admin --storage-state-out auth.json
|
|
837
|
+
ui-bridge-inject --url https://qontinui.io/admin \\
|
|
838
|
+
--storage-state auth.json --exec 'getControlSnapshot {}'
|
|
790
839
|
`;
|
|
791
840
|
var InjectCliArgError = class extends Error {
|
|
792
841
|
constructor(message) {
|
|
@@ -834,6 +883,8 @@ function parseArgs(argv) {
|
|
|
834
883
|
tabId: null,
|
|
835
884
|
viewportWidth: null,
|
|
836
885
|
viewportHeight: null,
|
|
886
|
+
storageState: null,
|
|
887
|
+
launchArgs: [],
|
|
837
888
|
execActions: [],
|
|
838
889
|
execStdin: false,
|
|
839
890
|
quiet: false,
|
|
@@ -876,6 +927,24 @@ function parseArgs(argv) {
|
|
|
876
927
|
case "--tab-id":
|
|
877
928
|
args.tabId = consumeValue("--tab-id", argv[++i], mkError);
|
|
878
929
|
break;
|
|
930
|
+
case "--storage-state": {
|
|
931
|
+
const raw = consumeValue("--storage-state", argv[++i], mkError);
|
|
932
|
+
if (raw === null || raw.length === 0) {
|
|
933
|
+
throw new InjectCliArgError(
|
|
934
|
+
`--storage-state expects a path to a storageState JSON file (got <missing>)`
|
|
935
|
+
);
|
|
936
|
+
}
|
|
937
|
+
args.storageState = raw;
|
|
938
|
+
break;
|
|
939
|
+
}
|
|
940
|
+
case "--launch-arg": {
|
|
941
|
+
const raw = argv[++i];
|
|
942
|
+
if (raw === void 0 || raw.length === 0) {
|
|
943
|
+
throw new InjectCliArgError(`--launch-arg expects a Chromium argument (got <missing>)`);
|
|
944
|
+
}
|
|
945
|
+
args.launchArgs.push(raw);
|
|
946
|
+
break;
|
|
947
|
+
}
|
|
879
948
|
case "--exec": {
|
|
880
949
|
const raw = consumeValue("--exec", argv[++i], mkError);
|
|
881
950
|
if (raw === null) {
|
|
@@ -988,9 +1057,48 @@ function validateArgs(args) {
|
|
|
988
1057
|
function selectMode(args) {
|
|
989
1058
|
return args.execActions.length > 0 || args.execStdin ? "exec" : "relay";
|
|
990
1059
|
}
|
|
1060
|
+
var LNA_DISABLE_FEATURES = [
|
|
1061
|
+
"LocalNetworkAccessChecks",
|
|
1062
|
+
"PrivateNetworkAccessSendPreflights",
|
|
1063
|
+
"PrivateNetworkAccessRespectPreflightResults"
|
|
1064
|
+
];
|
|
1065
|
+
function isLoopbackHost(hostname) {
|
|
1066
|
+
const h = hostname.toLowerCase();
|
|
1067
|
+
return h === "localhost" || h.endsWith(".localhost") || h.startsWith("127.") || h === "::1" || h === "[::1]";
|
|
1068
|
+
}
|
|
1069
|
+
function buildLaunchArgs(args) {
|
|
1070
|
+
const launchArgs = [...args.launchArgs];
|
|
1071
|
+
let lnaAutoAppended = false;
|
|
1072
|
+
let relayIsLoopback = false;
|
|
1073
|
+
if (args.relay) {
|
|
1074
|
+
try {
|
|
1075
|
+
relayIsLoopback = isLoopbackHost(new URL(args.relay).hostname);
|
|
1076
|
+
} catch {
|
|
1077
|
+
relayIsLoopback = false;
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
if (/^https:\/\//i.test(args.url) && relayIsLoopback) {
|
|
1081
|
+
const prefix = "--disable-features=";
|
|
1082
|
+
const existingIdx = launchArgs.findIndex((a) => a.startsWith(prefix));
|
|
1083
|
+
if (existingIdx === -1) {
|
|
1084
|
+
launchArgs.push(`${prefix}${LNA_DISABLE_FEATURES.join(",")}`);
|
|
1085
|
+
lnaAutoAppended = true;
|
|
1086
|
+
} else {
|
|
1087
|
+
const existing = launchArgs[existingIdx].slice(prefix.length).split(",").filter(Boolean);
|
|
1088
|
+
const missing = LNA_DISABLE_FEATURES.filter((f) => !existing.includes(f));
|
|
1089
|
+
if (missing.length > 0) {
|
|
1090
|
+
launchArgs[existingIdx] = `${prefix}${[...existing, ...missing].join(",")}`;
|
|
1091
|
+
lnaAutoAppended = true;
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
return { launchArgs, lnaAutoAppended };
|
|
1096
|
+
}
|
|
991
1097
|
function buildTransportOptions(args) {
|
|
992
1098
|
const options = { targetUrl: args.url };
|
|
993
1099
|
if (args.relay) options.uiBridgeBase = args.relay;
|
|
1100
|
+
const { launchArgs } = buildLaunchArgs(args);
|
|
1101
|
+
if (launchArgs.length > 0) options.launchArgs = launchArgs;
|
|
994
1102
|
if (args.authToken) options.authToken = args.authToken;
|
|
995
1103
|
if (args.registrationMetadata) options.registrationMetadata = args.registrationMetadata;
|
|
996
1104
|
if (args.headed) options.headed = true;
|
|
@@ -1004,6 +1112,7 @@ function buildTransportOptions(args) {
|
|
|
1004
1112
|
if (args.tabId) options.tabId = args.tabId;
|
|
1005
1113
|
if (args.viewportWidth !== null) options.viewportWidth = args.viewportWidth;
|
|
1006
1114
|
if (args.viewportHeight !== null) options.viewportHeight = args.viewportHeight;
|
|
1115
|
+
if (args.storageState) options.storageStatePath = args.storageState;
|
|
1007
1116
|
return options;
|
|
1008
1117
|
}
|
|
1009
1118
|
function die(msg) {
|
|
@@ -1065,6 +1174,13 @@ ${USAGE}`);
|
|
|
1065
1174
|
process.exit(0);
|
|
1066
1175
|
}
|
|
1067
1176
|
const mode = selectMode(args);
|
|
1177
|
+
const { launchArgs, lnaAutoAppended } = buildLaunchArgs(args);
|
|
1178
|
+
if (lnaAutoAppended) {
|
|
1179
|
+
log(
|
|
1180
|
+
args.quiet,
|
|
1181
|
+
`[ui-bridge-inject] https page + loopback relay detected \u2014 auto-appending Chromium LNA-disable flags so the page can fetch the relay: --disable-features=${LNA_DISABLE_FEATURES.join(",")} (effective launch args: ${JSON.stringify(launchArgs)})`
|
|
1182
|
+
);
|
|
1183
|
+
}
|
|
1068
1184
|
const transport = createTransport({ kind: "injected", options: buildTransportOptions(args) });
|
|
1069
1185
|
transport.register("__inject_cli_info", (_p, ctx) => {
|
|
1070
1186
|
const c = ctx;
|
|
@@ -1196,8 +1312,11 @@ if (isMain) {
|
|
|
1196
1312
|
}
|
|
1197
1313
|
|
|
1198
1314
|
exports.InjectCliArgError = InjectCliArgError;
|
|
1315
|
+
exports.LNA_DISABLE_FEATURES = LNA_DISABLE_FEATURES;
|
|
1199
1316
|
exports.USAGE = USAGE;
|
|
1317
|
+
exports.buildLaunchArgs = buildLaunchArgs;
|
|
1200
1318
|
exports.buildTransportOptions = buildTransportOptions;
|
|
1319
|
+
exports.isLoopbackHost = isLoopbackHost;
|
|
1201
1320
|
exports.parseArgs = parseArgs;
|
|
1202
1321
|
exports.selectMode = selectMode;
|
|
1203
1322
|
exports.validateArgs = validateArgs;
|