spana-test 0.14.0 → 0.16.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/dist/{accessibility-audit-MHQ65DUD.js → accessibility-audit-F5KLUHLS.js} +14 -3
- package/dist/accessibility-audit-F5KLUHLS.js.map +1 -0
- package/dist/agent/index.js +11 -11
- package/dist/agent/session.d.ts +1 -1
- package/dist/agent/session.d.ts.map +1 -1
- package/dist/api/app.d.ts +11 -2
- package/dist/api/app.d.ts.map +1 -1
- package/dist/api/expect.d.ts +2 -2
- package/dist/api/expect.d.ts.map +1 -1
- package/dist/api/flow.d.ts +2 -0
- package/dist/api/flow.d.ts.map +1 -1
- package/dist/{app-JTWXTFDY.js → app-C353NGBT.js} +3 -3
- package/dist/channels/cdp-client.d.ts +14 -5
- package/dist/channels/cdp-client.d.ts.map +1 -1
- package/dist/channels/dom-channel.d.ts +4 -2
- package/dist/channels/dom-channel.d.ts.map +1 -1
- package/dist/{chunk-IWGRZNKU.js → chunk-4TYO6O7T.js} +2 -2
- package/dist/{chunk-T4FCROSE.js → chunk-5WPPWTC3.js} +740 -257
- package/dist/chunk-5WPPWTC3.js.map +1 -0
- package/dist/{chunk-PCVXXIEJ.js → chunk-62SDNQKK.js} +3 -3
- package/dist/{chunk-WKN6ZW7V.js → chunk-7K7WVTFZ.js} +6 -6
- package/dist/{chunk-KWIB77C7.js → chunk-7O5YXVCD.js} +2 -2
- package/dist/{chunk-63OBFF2I.js → chunk-CA66JCX2.js} +282 -52
- package/dist/chunk-CA66JCX2.js.map +1 -0
- package/dist/{chunk-MTCRATOA.js → chunk-EA7DZ5TN.js} +13 -2
- package/dist/chunk-EA7DZ5TN.js.map +1 -0
- package/dist/{chunk-U7633AII.js → chunk-GMEVJQTT.js} +5 -2
- package/dist/chunk-GMEVJQTT.js.map +1 -0
- package/dist/{chunk-7WC7NPRU.js → chunk-HIEOI3WN.js} +411 -135
- package/dist/chunk-HIEOI3WN.js.map +1 -0
- package/dist/{chunk-RGLPQNJG.js → chunk-HJZT6YOA.js} +2 -2
- package/dist/{chunk-RQ5TJJZU.js → chunk-JRGJTUPS.js} +3 -3
- package/dist/{chunk-JHJSAIPG.js → chunk-KIFNHFFI.js} +47 -19
- package/dist/chunk-KIFNHFFI.js.map +1 -0
- package/dist/{chunk-NMN2ENQZ.js → chunk-LGFTUVN4.js} +2 -2
- package/dist/{chunk-E2JJOVPP.js → chunk-UZU7VYKN.js} +107 -24
- package/dist/chunk-UZU7VYKN.js.map +1 -0
- package/dist/{chunk-2SJNPLLU.js → chunk-WBCAF7SC.js} +285 -77
- package/dist/chunk-WBCAF7SC.js.map +1 -0
- package/dist/{chunk-7EMHU56B.js → chunk-ZCSH3QKX.js} +882 -426
- package/dist/chunk-ZCSH3QKX.js.map +1 -0
- package/dist/cli/config-loader.d.ts.map +1 -1
- package/dist/cli/iteration.d.ts +13 -0
- package/dist/cli/iteration.d.ts.map +1 -1
- package/dist/cli/test-command.d.ts +22 -0
- package/dist/cli/test-command.d.ts.map +1 -1
- package/dist/cli.js +27 -15
- package/dist/cli.js.map +1 -1
- package/dist/config-loader-TSADVSBY.js +10 -0
- package/dist/core/accessibility-audit.d.ts.map +1 -1
- package/dist/core/engine.d.ts.map +1 -1
- package/dist/core/orchestrator.d.ts +2 -0
- package/dist/core/orchestrator.d.ts.map +1 -1
- package/dist/core/parallel.d.ts +9 -1
- package/dist/core/parallel.d.ts.map +1 -1
- package/dist/core/worker-pool.d.ts +5 -2
- package/dist/core/worker-pool.d.ts.map +1 -1
- package/dist/{doctor-command-BYKRBS4V.js → doctor-command-UUQ4RFMK.js} +7 -7
- package/dist/{driver-GOPO5ZZP.js → driver-3HBDKESK.js} +5 -5
- package/dist/{driver-HK4HQAYL.js → driver-LKXSKNG3.js} +4 -4
- package/dist/drivers/cdp-browser.d.ts +8 -0
- package/dist/drivers/cdp-browser.d.ts.map +1 -1
- package/dist/drivers/playwright.d.ts +2 -0
- package/dist/drivers/playwright.d.ts.map +1 -1
- package/dist/drivers/raw-driver.d.ts +2 -0
- package/dist/drivers/raw-driver.d.ts.map +1 -1
- package/dist/{electrobun-65Z6KOVN.js → electrobun-HILYDIJ3.js} +5 -5
- package/dist/index.d.ts +6 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +27 -13
- package/dist/index.js.map +1 -1
- package/dist/{json-57Z2YSES.js → json-67HY4VQK.js} +6 -1
- package/dist/json-67HY4VQK.js.map +1 -0
- package/dist/{local-6NRVD5VP.js → local-J2NC6YKI.js} +5 -5
- package/dist/{playwright-JUAD3TT4.js → playwright-JMHCABDJ.js} +5 -5
- package/dist/report/json.d.ts.map +1 -1
- package/dist/report/types.d.ts +2 -0
- package/dist/report/types.d.ts.map +1 -1
- package/dist/runtime/local.d.ts +0 -4
- package/dist/runtime/local.d.ts.map +1 -1
- package/dist/schemas/config.d.ts +46 -4
- package/dist/schemas/config.d.ts.map +1 -1
- package/dist/schemas/element.d.ts +2 -0
- package/dist/schemas/element.d.ts.map +1 -1
- package/dist/{server-UJ3RDZWT.js → server-RHAHCANZ.js} +2 -2
- package/dist/{server-2RCONJCW.js → server-RTDMJIQZ.js} +14 -13
- package/dist/{server-2RCONJCW.js.map → server-RTDMJIQZ.js.map} +1 -1
- package/dist/{session-7N5XYDXQ.js → session-7CWHTQ2E.js} +12 -12
- package/dist/smart/auto-wait.d.ts +2 -0
- package/dist/smart/auto-wait.d.ts.map +1 -1
- package/dist/smart/coordinator.d.ts +2 -2
- package/dist/smart/coordinator.d.ts.map +1 -1
- package/dist/studio/api.d.ts +2 -0
- package/dist/studio/api.d.ts.map +1 -1
- package/dist/studio/routers/inspector.d.ts +2 -0
- package/dist/studio/routers/inspector.d.ts.map +1 -1
- package/dist/{studio-command-ZCR64XWV.js → studio-command-PZHMLCKE.js} +2 -2
- package/dist/{test-command-ENL3DRN4.js → test-command-FJOP2GYD.js} +403 -210
- package/dist/test-command-FJOP2GYD.js.map +1 -0
- package/package.json +4 -8
- package/dist/accessibility-audit-MHQ65DUD.js.map +0 -1
- package/dist/chunk-2SJNPLLU.js.map +0 -1
- package/dist/chunk-63OBFF2I.js.map +0 -1
- package/dist/chunk-7EMHU56B.js.map +0 -1
- package/dist/chunk-7WC7NPRU.js.map +0 -1
- package/dist/chunk-E2JJOVPP.js.map +0 -1
- package/dist/chunk-JHJSAIPG.js.map +0 -1
- package/dist/chunk-MTCRATOA.js.map +0 -1
- package/dist/chunk-T4FCROSE.js.map +0 -1
- package/dist/chunk-U7633AII.js.map +0 -1
- package/dist/config-loader-4X7R7XDL.js +0 -10
- package/dist/json-57Z2YSES.js.map +0 -1
- package/dist/test-command-ENL3DRN4.js.map +0 -1
- /package/dist/{app-JTWXTFDY.js.map → app-C353NGBT.js.map} +0 -0
- /package/dist/{chunk-IWGRZNKU.js.map → chunk-4TYO6O7T.js.map} +0 -0
- /package/dist/{chunk-PCVXXIEJ.js.map → chunk-62SDNQKK.js.map} +0 -0
- /package/dist/{chunk-WKN6ZW7V.js.map → chunk-7K7WVTFZ.js.map} +0 -0
- /package/dist/{chunk-KWIB77C7.js.map → chunk-7O5YXVCD.js.map} +0 -0
- /package/dist/{chunk-RGLPQNJG.js.map → chunk-HJZT6YOA.js.map} +0 -0
- /package/dist/{chunk-RQ5TJJZU.js.map → chunk-JRGJTUPS.js.map} +0 -0
- /package/dist/{chunk-NMN2ENQZ.js.map → chunk-LGFTUVN4.js.map} +0 -0
- /package/dist/{config-loader-4X7R7XDL.js.map → config-loader-TSADVSBY.js.map} +0 -0
- /package/dist/{doctor-command-BYKRBS4V.js.map → doctor-command-UUQ4RFMK.js.map} +0 -0
- /package/dist/{driver-GOPO5ZZP.js.map → driver-3HBDKESK.js.map} +0 -0
- /package/dist/{driver-HK4HQAYL.js.map → driver-LKXSKNG3.js.map} +0 -0
- /package/dist/{electrobun-65Z6KOVN.js.map → electrobun-HILYDIJ3.js.map} +0 -0
- /package/dist/{local-6NRVD5VP.js.map → local-J2NC6YKI.js.map} +0 -0
- /package/dist/{playwright-JUAD3TT4.js.map → playwright-JMHCABDJ.js.map} +0 -0
- /package/dist/{server-UJ3RDZWT.js.map → server-RHAHCANZ.js.map} +0 -0
- /package/dist/{session-7N5XYDXQ.js.map → session-7CWHTQ2E.js.map} +0 -0
- /package/dist/{studio-command-ZCR64XWV.js.map → studio-command-PZHMLCKE.js.map} +0 -0
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
buildDomWaitForSelectorScript,
|
|
11
11
|
buildEvaluateExpression,
|
|
12
12
|
buildInjectedCallScript
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-CA66JCX2.js";
|
|
14
14
|
import {
|
|
15
15
|
init_esm_shims
|
|
16
16
|
} from "./chunk-FTXUQMGH.js";
|
|
@@ -279,12 +279,15 @@ var CdpDomChannel = class {
|
|
|
279
279
|
createWebSocket;
|
|
280
280
|
ws = null;
|
|
281
281
|
connected = false;
|
|
282
|
+
permanentlyClosed = false;
|
|
283
|
+
closedReason = "Browser context closed";
|
|
282
284
|
nextId = 1;
|
|
283
285
|
pending = /* @__PURE__ */ new Map();
|
|
284
286
|
eventListeners = /* @__PURE__ */ new Map();
|
|
285
287
|
currentTargetId = null;
|
|
286
288
|
activeSessionId = null;
|
|
287
289
|
childSessions = /* @__PURE__ */ new Map();
|
|
290
|
+
inProcessFrameWorlds = /* @__PURE__ */ new Map();
|
|
288
291
|
frameOffsetResolver;
|
|
289
292
|
constructor(options) {
|
|
290
293
|
this.endpointUrl = options.endpointUrl.replace(/\/+$/, "");
|
|
@@ -295,7 +298,18 @@ var CdpDomChannel = class {
|
|
|
295
298
|
this.createWebSocket = options.createWebSocket ?? defaultWebSocketFactory;
|
|
296
299
|
}
|
|
297
300
|
isConnected() {
|
|
298
|
-
return this.connected && this.ws !== null && this.ws.readyState === WS_OPEN;
|
|
301
|
+
return !this.permanentlyClosed && this.connected && this.ws !== null && this.ws.readyState === WS_OPEN;
|
|
302
|
+
}
|
|
303
|
+
/** Permanently close this channel so subsequent commands reject immediately instead of auto-reconnecting. */
|
|
304
|
+
markClosed(reason = "Browser context closed") {
|
|
305
|
+
this.permanentlyClosed = true;
|
|
306
|
+
this.closedReason = reason;
|
|
307
|
+
this.connected = false;
|
|
308
|
+
this.inProcessFrameWorlds.clear();
|
|
309
|
+
this.rejectAllPending(new Error(reason));
|
|
310
|
+
}
|
|
311
|
+
isPermanentlyClosed() {
|
|
312
|
+
return this.permanentlyClosed;
|
|
299
313
|
}
|
|
300
314
|
async listTargets() {
|
|
301
315
|
const raw = await this.fetchTargets();
|
|
@@ -331,6 +345,9 @@ var CdpDomChannel = class {
|
|
|
331
345
|
await this.openSocket(target.webSocketDebuggerUrl);
|
|
332
346
|
}
|
|
333
347
|
async connect() {
|
|
348
|
+
if (this.permanentlyClosed) {
|
|
349
|
+
throw new Error(this.closedReason);
|
|
350
|
+
}
|
|
334
351
|
if (this.isConnected()) return;
|
|
335
352
|
let wsUrl = this.explicitWsUrl;
|
|
336
353
|
if (!wsUrl) {
|
|
@@ -405,10 +422,22 @@ var CdpDomChannel = class {
|
|
|
405
422
|
}
|
|
406
423
|
const method = parsed["method"];
|
|
407
424
|
if (typeof method === "string") {
|
|
425
|
+
const params = parsed["params"];
|
|
426
|
+
const sessionId = typeof parsed["sessionId"] === "string" ? parsed["sessionId"] : void 0;
|
|
427
|
+
if (method === "Page.frameNavigated" || method === "Page.frameDetached") {
|
|
428
|
+
const fid = typeof params?.frame?.id === "string" ? params.frame.id : typeof params?.frameId === "string" ? params.frameId : void 0;
|
|
429
|
+
if (fid) {
|
|
430
|
+
this.inProcessFrameWorlds.delete(`${sessionId ?? this.activeSessionId ?? ""}:${fid}`);
|
|
431
|
+
if (method === "Page.frameNavigated" && !params?.frame?.parentId) {
|
|
432
|
+
const prefix = `${sessionId ?? this.activeSessionId ?? ""}:`;
|
|
433
|
+
for (const key of this.inProcessFrameWorlds.keys()) {
|
|
434
|
+
if (key.startsWith(prefix)) this.inProcessFrameWorlds.delete(key);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
}
|
|
408
439
|
const listeners = this.eventListeners.get(method);
|
|
409
440
|
if (listeners && listeners.size > 0) {
|
|
410
|
-
const params = parsed["params"];
|
|
411
|
-
const sessionId = typeof parsed["sessionId"] === "string" ? parsed["sessionId"] : void 0;
|
|
412
441
|
for (const fn of listeners) {
|
|
413
442
|
try {
|
|
414
443
|
fn(params, sessionId);
|
|
@@ -436,6 +465,7 @@ var CdpDomChannel = class {
|
|
|
436
465
|
}
|
|
437
466
|
setSessionId(sessionId) {
|
|
438
467
|
this.activeSessionId = sessionId;
|
|
468
|
+
this.inProcessFrameWorlds.clear();
|
|
439
469
|
}
|
|
440
470
|
get sessionId() {
|
|
441
471
|
return this.activeSessionId;
|
|
@@ -449,6 +479,7 @@ var CdpDomChannel = class {
|
|
|
449
479
|
}
|
|
450
480
|
clearChildSessions() {
|
|
451
481
|
this.childSessions.clear();
|
|
482
|
+
this.inProcessFrameWorlds.clear();
|
|
452
483
|
}
|
|
453
484
|
getChildSessions() {
|
|
454
485
|
return Array.from(this.childSessions.values());
|
|
@@ -511,6 +542,9 @@ var CdpDomChannel = class {
|
|
|
511
542
|
});
|
|
512
543
|
}
|
|
513
544
|
async sendCommand(method, params = {}, sessionId, timeoutMs) {
|
|
545
|
+
if (this.permanentlyClosed) {
|
|
546
|
+
throw new Error(this.closedReason);
|
|
547
|
+
}
|
|
514
548
|
if (!this.isConnected()) {
|
|
515
549
|
await this.connect();
|
|
516
550
|
}
|
|
@@ -540,8 +574,12 @@ var CdpDomChannel = class {
|
|
|
540
574
|
const effectiveTimeout = timeoutMs ?? this.timeoutMs;
|
|
541
575
|
const deadline = Date.now() + effectiveTimeout;
|
|
542
576
|
let lastError;
|
|
577
|
+
const targetSid = sessionId === void 0 ? this.activeSessionId : sessionId;
|
|
543
578
|
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
544
579
|
const remaining = Math.max(250, deadline - Date.now());
|
|
580
|
+
let offDestroyed;
|
|
581
|
+
let offCleared;
|
|
582
|
+
let offNavigated;
|
|
545
583
|
try {
|
|
546
584
|
const evalParams = {
|
|
547
585
|
expression,
|
|
@@ -551,7 +589,32 @@ var CdpDomChannel = class {
|
|
|
551
589
|
if (contextId !== void 0) {
|
|
552
590
|
evalParams["contextId"] = contextId;
|
|
553
591
|
}
|
|
554
|
-
const
|
|
592
|
+
const evalPromise = this.sendCommand("Runtime.evaluate", evalParams, sessionId, remaining);
|
|
593
|
+
const contextDestroyedPromise = new Promise((_resolve, reject) => {
|
|
594
|
+
const matchesTargetSession = (sid) => (sid ?? null) === (targetSid ?? null) || !targetSid && !sid;
|
|
595
|
+
const triggerAbort = (reason) => {
|
|
596
|
+
reject(new Error(`Execution context was destroyed (${reason})`));
|
|
597
|
+
};
|
|
598
|
+
offCleared = this.onEvent("Runtime.executionContextsCleared", (_p, sid) => {
|
|
599
|
+
if (matchesTargetSession(sid)) triggerAbort("executionContextsCleared");
|
|
600
|
+
});
|
|
601
|
+
if (contextId !== void 0) {
|
|
602
|
+
offDestroyed = this.onEvent("Runtime.executionContextDestroyed", (p, sid) => {
|
|
603
|
+
if (matchesTargetSession(sid) && p?.executionContextId === contextId) {
|
|
604
|
+
triggerAbort("executionContextDestroyed");
|
|
605
|
+
}
|
|
606
|
+
});
|
|
607
|
+
} else {
|
|
608
|
+
offNavigated = this.onEvent("Page.frameNavigated", (p, sid) => {
|
|
609
|
+
if (matchesTargetSession(sid) && p?.frame && !p.frame.parentId) {
|
|
610
|
+
triggerAbort("mainFrameNavigated");
|
|
611
|
+
}
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
});
|
|
615
|
+
contextDestroyedPromise.catch(() => {
|
|
616
|
+
});
|
|
617
|
+
const response = await Promise.race([evalPromise, contextDestroyedPromise]);
|
|
555
618
|
if (response?.exceptionDetails) {
|
|
556
619
|
const detail = response.exceptionDetails.exception?.description ?? response.exceptionDetails.text ?? "Evaluation threw an exception";
|
|
557
620
|
throw new Error(`CDP evaluate failed: ${detail}`);
|
|
@@ -575,6 +638,10 @@ var CdpDomChannel = class {
|
|
|
575
638
|
continue;
|
|
576
639
|
}
|
|
577
640
|
throw err;
|
|
641
|
+
} finally {
|
|
642
|
+
offDestroyed?.();
|
|
643
|
+
offCleared?.();
|
|
644
|
+
offNavigated?.();
|
|
578
645
|
}
|
|
579
646
|
}
|
|
580
647
|
throw lastError ?? new Error("CDP evaluate failed: execution context was destroyed");
|
|
@@ -583,8 +650,12 @@ var CdpDomChannel = class {
|
|
|
583
650
|
async evaluateFast(script, ...args) {
|
|
584
651
|
return this.evaluateOnSessionWithTimeout(void 0, script, 2e3, args, void 0, 1);
|
|
585
652
|
}
|
|
653
|
+
/** Single-attempt evaluate with the default command timeout — used for user `app.evaluate()` so navigation aborts immediately instead of re-executing user code in the new document. */
|
|
654
|
+
async evaluateOnce(script, ...args) {
|
|
655
|
+
return this.evaluateOnSessionWithTimeout(void 0, script, void 0, args, void 0, 1);
|
|
656
|
+
}
|
|
586
657
|
async evaluateOnSession(sessionId, script, ...args) {
|
|
587
|
-
return this.evaluateOnSessionWithTimeout(sessionId, script, void 0, args);
|
|
658
|
+
return this.evaluateOnSessionWithTimeout(sessionId, script, void 0, args, void 0, 3);
|
|
588
659
|
}
|
|
589
660
|
async evaluate(script, ...args) {
|
|
590
661
|
return this.evaluateOnSession(void 0, script, ...args);
|
|
@@ -622,12 +693,96 @@ var CdpDomChannel = class {
|
|
|
622
693
|
}
|
|
623
694
|
}));
|
|
624
695
|
}
|
|
696
|
+
async inspectMatchingIframes(frameSel, contextId, sessionId) {
|
|
697
|
+
const matcherFn = `function __matchIframes(fSel) {
|
|
698
|
+
var iframes = Array.from(document.querySelectorAll("iframe"));
|
|
699
|
+
var matched = [];
|
|
700
|
+
for (var i = 0; i < iframes.length; i++) {
|
|
701
|
+
var el = iframes[i];
|
|
702
|
+
var ok = false;
|
|
703
|
+
if (typeof fSel === "string") {
|
|
704
|
+
if (el.getAttribute("title") === fSel || el.getAttribute("aria-label") === fSel || el.getAttribute("name") === fSel) ok = true;
|
|
705
|
+
else { try { if (el.matches(fSel)) ok = true; } catch (e) {} }
|
|
706
|
+
} else if (fSel && typeof fSel === "object") {
|
|
707
|
+
if (fSel.css) {
|
|
708
|
+
try { if (el.matches(fSel.css)) ok = true; } catch (e) {}
|
|
709
|
+
} else if (fSel.testID && (el.getAttribute("data-testid") === fSel.testID || el.getAttribute("testID") === fSel.testID)) {
|
|
710
|
+
ok = true;
|
|
711
|
+
} else if (fSel.accessibilityLabel && (el.getAttribute("aria-label") === fSel.accessibilityLabel || el.getAttribute("title") === fSel.accessibilityLabel)) {
|
|
712
|
+
ok = true;
|
|
713
|
+
} else if (fSel.text && (el.getAttribute("title") === fSel.text || el.getAttribute("aria-label") === fSel.text)) {
|
|
714
|
+
ok = true;
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
if (ok) matched.push(el);
|
|
718
|
+
}
|
|
719
|
+
return matched;
|
|
720
|
+
}`;
|
|
721
|
+
const metaList = await this.evaluateOnSessionWithTimeout(
|
|
722
|
+
sessionId,
|
|
723
|
+
`((fSel) => {
|
|
724
|
+
try {
|
|
725
|
+
${matcherFn}
|
|
726
|
+
return __matchIframes(fSel).map((el) => {
|
|
727
|
+
var r = el.getBoundingClientRect();
|
|
728
|
+
var accessible = false;
|
|
729
|
+
try {
|
|
730
|
+
var srcAttr = el.getAttribute("src") || "";
|
|
731
|
+
var crossOriginSrc = false;
|
|
732
|
+
if (srcAttr && !srcAttr.startsWith("about:") && !srcAttr.startsWith("javascript:")) {
|
|
733
|
+
try {
|
|
734
|
+
var parsedSrc = new URL(srcAttr, window.location.href);
|
|
735
|
+
if (parsedSrc.origin !== window.location.origin) crossOriginSrc = true;
|
|
736
|
+
} catch (e2) {}
|
|
737
|
+
}
|
|
738
|
+
accessible = !crossOriginSrc && Boolean(el.contentDocument && el.contentDocument.documentElement);
|
|
739
|
+
} catch (e) {}
|
|
740
|
+
return { src: el.src || "", name: el.getAttribute("name") || "", x: r.left, y: r.top, sameOriginAccessible: accessible };
|
|
741
|
+
});
|
|
742
|
+
} catch (e) { return []; }
|
|
743
|
+
})(${JSON.stringify(frameSel)})`,
|
|
744
|
+
3e3,
|
|
745
|
+
[],
|
|
746
|
+
contextId,
|
|
747
|
+
1
|
|
748
|
+
).catch(() => []);
|
|
749
|
+
if (!Array.isArray(metaList) || metaList.length === 0) return [];
|
|
750
|
+
const enriched = [];
|
|
751
|
+
for (let idx = 0; idx < metaList.length; idx++) {
|
|
752
|
+
const info = metaList[idx];
|
|
753
|
+
let frameId;
|
|
754
|
+
try {
|
|
755
|
+
const evalParams = {
|
|
756
|
+
expression: `((fSel, idx) => { ${matcherFn} return __matchIframes(fSel)[idx] || null; })(${JSON.stringify(frameSel)}, ${idx})`,
|
|
757
|
+
returnByValue: false
|
|
758
|
+
};
|
|
759
|
+
if (contextId !== void 0) evalParams["contextId"] = contextId;
|
|
760
|
+
const evalRes = await this.sendCommand(
|
|
761
|
+
"Runtime.evaluate",
|
|
762
|
+
evalParams,
|
|
763
|
+
sessionId,
|
|
764
|
+
2e3
|
|
765
|
+
);
|
|
766
|
+
const objectId = evalRes?.result?.objectId;
|
|
767
|
+
if (objectId) {
|
|
768
|
+
const desc = await this.sendCommand("DOM.describeNode", { objectId, depth: 1 }, sessionId, 2e3).catch(() => null);
|
|
769
|
+
frameId = desc?.node?.contentDocument?.frameId ?? desc?.node?.frameId;
|
|
770
|
+
void this.sendCommand("Runtime.releaseObject", { objectId }, sessionId, 1e3).catch(
|
|
771
|
+
() => {
|
|
772
|
+
}
|
|
773
|
+
);
|
|
774
|
+
}
|
|
775
|
+
} catch {
|
|
776
|
+
}
|
|
777
|
+
enriched.push({ ...info, ...frameId ? { frameId } : {} });
|
|
778
|
+
}
|
|
779
|
+
return enriched;
|
|
780
|
+
}
|
|
625
781
|
/**
|
|
626
782
|
* Resolve in-process cross-origin child frames (e.g. same-site subdomains such as
|
|
627
|
-
* `notes.app.localhost` embedded in `studio.app.localhost`)
|
|
628
|
-
*
|
|
629
|
-
*
|
|
630
|
-
* Using `Page.getFrameTree` + `Page.createIsolatedWorld` accesses them cleanly via CDP.
|
|
783
|
+
* `notes.app.localhost` embedded in `studio.app.localhost`), including nested iframes.
|
|
784
|
+
* Uses `DOM.describeNode` for exact `frameId` resolution + `Page.getFrameTree` +
|
|
785
|
+
* `Page.createIsolatedWorld` so multiple iframes sharing an origin never collide.
|
|
631
786
|
*/
|
|
632
787
|
async resolveInProcessChildFrames(selector) {
|
|
633
788
|
if (!this.hasExplicitFrame(selector)) return [];
|
|
@@ -635,56 +790,28 @@ var CdpDomChannel = class {
|
|
|
635
790
|
const treeRes = await this.sendCommand("Page.getFrameTree").catch(() => null);
|
|
636
791
|
if (!treeRes?.frameTree?.childFrames?.length) return [];
|
|
637
792
|
const flatFrames = [];
|
|
638
|
-
const walk = (nodes) => {
|
|
793
|
+
const walk = (nodes, parentId) => {
|
|
639
794
|
if (!Array.isArray(nodes)) return;
|
|
640
795
|
for (const n of nodes) {
|
|
641
796
|
if (n?.frame?.id) {
|
|
642
797
|
flatFrames.push({
|
|
643
798
|
id: n.frame.id,
|
|
799
|
+
parentId: n.frame.parentId ?? parentId,
|
|
644
800
|
url: n.frame.url ?? "",
|
|
645
801
|
name: n.frame.name ?? ""
|
|
646
802
|
});
|
|
647
803
|
}
|
|
648
|
-
if (n?.childFrames) walk(n.childFrames);
|
|
804
|
+
if (n?.childFrames) walk(n.childFrames, n?.frame?.id);
|
|
649
805
|
}
|
|
650
806
|
};
|
|
651
|
-
walk(treeRes.frameTree.childFrames);
|
|
807
|
+
walk(treeRes.frameTree.childFrames, treeRes.frameTree.frame?.id);
|
|
652
808
|
if (flatFrames.length === 0) return [];
|
|
653
|
-
const
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
for (const el of iframes) {
|
|
660
|
-
let ok = false;
|
|
661
|
-
if (typeof fSel === "string") {
|
|
662
|
-
if (el.getAttribute("title") === fSel || el.getAttribute("aria-label") === fSel || el.getAttribute("name") === fSel) ok = true;
|
|
663
|
-
else { try { if (el.matches(fSel)) ok = true; } catch {} }
|
|
664
|
-
} else if (fSel && typeof fSel === "object") {
|
|
665
|
-
if (fSel.css) {
|
|
666
|
-
try { if (el.matches(fSel.css)) ok = true; } catch {}
|
|
667
|
-
} else if (fSel.testID && (el.getAttribute("data-testid") === fSel.testID || el.getAttribute("testID") === fSel.testID)) {
|
|
668
|
-
ok = true;
|
|
669
|
-
} else if (fSel.accessibilityLabel && (el.getAttribute("aria-label") === fSel.accessibilityLabel || el.getAttribute("title") === fSel.accessibilityLabel)) {
|
|
670
|
-
ok = true;
|
|
671
|
-
} else if (fSel.text && (el.getAttribute("title") === fSel.text || el.getAttribute("aria-label") === fSel.text)) {
|
|
672
|
-
ok = true;
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
if (ok) {
|
|
676
|
-
const r = el.getBoundingClientRect();
|
|
677
|
-
matched.push({ src: el.src || "", name: el.getAttribute("name") || "", x: r.left, y: r.top });
|
|
678
|
-
}
|
|
679
|
-
}
|
|
680
|
-
return matched;
|
|
681
|
-
} catch { return []; }
|
|
682
|
-
})(${JSON.stringify(frameSel)})`
|
|
683
|
-
).catch(() => []);
|
|
684
|
-
if (iframeInfos.length === 0) return [];
|
|
685
|
-
const out = [];
|
|
686
|
-
for (const info of iframeInfos) {
|
|
687
|
-
const match = flatFrames.find((f) => {
|
|
809
|
+
const matchInfoToFrame = (info, pool) => {
|
|
810
|
+
if (info.frameId) {
|
|
811
|
+
const exact = pool.find((f) => f.id === info.frameId);
|
|
812
|
+
if (exact) return exact;
|
|
813
|
+
}
|
|
814
|
+
return pool.find((f) => {
|
|
688
815
|
if (info.name && f.name && f.name === info.name) return true;
|
|
689
816
|
if (!info.src || !f.url) return false;
|
|
690
817
|
try {
|
|
@@ -694,7 +821,7 @@ var CdpDomChannel = class {
|
|
|
694
821
|
} catch {
|
|
695
822
|
return f.url === info.src || f.url.startsWith(info.src);
|
|
696
823
|
}
|
|
697
|
-
}) ??
|
|
824
|
+
}) ?? pool.find((f) => {
|
|
698
825
|
if (!info.src || !f.url) return false;
|
|
699
826
|
try {
|
|
700
827
|
return new URL(info.src).origin === new URL(f.url).origin;
|
|
@@ -702,13 +829,78 @@ var CdpDomChannel = class {
|
|
|
702
829
|
return false;
|
|
703
830
|
}
|
|
704
831
|
});
|
|
832
|
+
};
|
|
833
|
+
const out = [];
|
|
834
|
+
const topInfos = await this.inspectMatchingIframes(frameSel);
|
|
835
|
+
for (const info of topInfos) {
|
|
836
|
+
const match = matchInfoToFrame(info, flatFrames);
|
|
705
837
|
if (match && !out.some((x) => x.frameId === match.id)) {
|
|
706
838
|
out.push({ frameId: match.id, url: match.url, offset: { x: info.x, y: info.y } });
|
|
707
839
|
}
|
|
708
840
|
}
|
|
841
|
+
if (out.length === 0) {
|
|
842
|
+
const topFrameId = treeRes.frameTree.frame?.id;
|
|
843
|
+
const visited = /* @__PURE__ */ new Set();
|
|
844
|
+
const searchChildrenOf = async (parentFrameId, parentOffset, depth) => {
|
|
845
|
+
if (depth > 4 || visited.has(parentFrameId)) return;
|
|
846
|
+
visited.add(parentFrameId);
|
|
847
|
+
const directChildren = flatFrames.filter((f) => f.parentId === parentFrameId);
|
|
848
|
+
if (directChildren.length === 0) return;
|
|
849
|
+
const childIframeRects = await (async () => {
|
|
850
|
+
if (parentFrameId === topFrameId) {
|
|
851
|
+
return this.inspectMatchingIframes("iframe");
|
|
852
|
+
}
|
|
853
|
+
try {
|
|
854
|
+
const ctxId = await this.getOrCreateFrameWorld(parentFrameId);
|
|
855
|
+
return await this.inspectMatchingIframes("iframe", ctxId);
|
|
856
|
+
} catch {
|
|
857
|
+
return [];
|
|
858
|
+
}
|
|
859
|
+
})();
|
|
860
|
+
for (const childFrame of directChildren) {
|
|
861
|
+
const rectInfo = childIframeRects.find(
|
|
862
|
+
(r) => r.frameId === childFrame.id || r.name && childFrame.name && r.name === childFrame.name || r.src && childFrame.url && childFrame.url.startsWith(r.src)
|
|
863
|
+
);
|
|
864
|
+
const childOffset = {
|
|
865
|
+
x: parentOffset.x + (rectInfo?.x ?? 0),
|
|
866
|
+
y: parentOffset.y + (rectInfo?.y ?? 0)
|
|
867
|
+
};
|
|
868
|
+
try {
|
|
869
|
+
const ctxId = await this.getOrCreateFrameWorld(childFrame.id);
|
|
870
|
+
const nestedInfos = await this.inspectMatchingIframes(frameSel, ctxId);
|
|
871
|
+
for (const nInfo of nestedInfos) {
|
|
872
|
+
const grandChildren = flatFrames.filter((f) => f.parentId === childFrame.id);
|
|
873
|
+
const match = matchInfoToFrame(
|
|
874
|
+
nInfo,
|
|
875
|
+
grandChildren.length > 0 ? grandChildren : flatFrames
|
|
876
|
+
);
|
|
877
|
+
if (match && !out.some((x) => x.frameId === match.id)) {
|
|
878
|
+
out.push({
|
|
879
|
+
frameId: match.id,
|
|
880
|
+
url: match.url,
|
|
881
|
+
offset: { x: childOffset.x + nInfo.x, y: childOffset.y + nInfo.y }
|
|
882
|
+
});
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
} catch {
|
|
886
|
+
}
|
|
887
|
+
if (out.length === 0) {
|
|
888
|
+
await searchChildrenOf(childFrame.id, childOffset, depth + 1);
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
};
|
|
892
|
+
if (topFrameId) {
|
|
893
|
+
await searchChildrenOf(topFrameId, { x: 0, y: 0 }, 0);
|
|
894
|
+
}
|
|
895
|
+
}
|
|
709
896
|
return out;
|
|
710
897
|
}
|
|
711
|
-
async
|
|
898
|
+
async getOrCreateFrameWorld(frameId, forceFresh = false) {
|
|
899
|
+
const key = `${this.activeSessionId ?? ""}:${frameId}`;
|
|
900
|
+
if (!forceFresh) {
|
|
901
|
+
const cached = this.inProcessFrameWorlds.get(key);
|
|
902
|
+
if (cached !== void 0) return cached;
|
|
903
|
+
}
|
|
712
904
|
const world = await this.sendCommand(
|
|
713
905
|
"Page.createIsolatedWorld",
|
|
714
906
|
{
|
|
@@ -717,13 +909,51 @@ var CdpDomChannel = class {
|
|
|
717
909
|
grantUniveralAccess: false
|
|
718
910
|
}
|
|
719
911
|
);
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
912
|
+
this.inProcessFrameWorlds.set(key, world.executionContextId);
|
|
913
|
+
return world.executionContextId;
|
|
914
|
+
}
|
|
915
|
+
async invokeInProcessFrame(frameId, method, args, fallbackScript, timeoutMs) {
|
|
916
|
+
const key = `${this.activeSessionId ?? ""}:${frameId}`;
|
|
917
|
+
const runWithContext = async (contextId2) => {
|
|
918
|
+
if (!this.useInjectedRuntime) {
|
|
919
|
+
return this.evaluateOnSessionWithTimeout(
|
|
920
|
+
void 0,
|
|
921
|
+
fallbackScript(),
|
|
922
|
+
timeoutMs,
|
|
923
|
+
[],
|
|
924
|
+
contextId2,
|
|
925
|
+
1
|
|
926
|
+
);
|
|
927
|
+
}
|
|
928
|
+
const callExpr = buildInjectedCallScript(method, ...args);
|
|
929
|
+
const res = await this.evaluateOnSessionWithTimeout(void 0, callExpr, timeoutMs, [], contextId2, 1);
|
|
930
|
+
if (res !== SPANA_RUNTIME_MISSING_SENTINEL) {
|
|
931
|
+
return res;
|
|
932
|
+
}
|
|
933
|
+
await this.evaluateOnSessionWithTimeout(
|
|
934
|
+
void 0,
|
|
935
|
+
SPANA_INJECTED_RUNTIME_SCRIPT,
|
|
936
|
+
timeoutMs,
|
|
937
|
+
[],
|
|
938
|
+
contextId2,
|
|
939
|
+
1
|
|
940
|
+
);
|
|
941
|
+
return this.evaluateOnSessionWithTimeout(void 0, callExpr, timeoutMs, [], contextId2, 1);
|
|
942
|
+
};
|
|
943
|
+
const contextId = await this.getOrCreateFrameWorld(frameId);
|
|
944
|
+
try {
|
|
945
|
+
return await runWithContext(contextId);
|
|
946
|
+
} catch (err) {
|
|
947
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
948
|
+
if (/Execution context was destroyed|Cannot find context with specified id|No frame for given id/i.test(
|
|
949
|
+
msg
|
|
950
|
+
)) {
|
|
951
|
+
this.inProcessFrameWorlds.delete(key);
|
|
952
|
+
const freshContextId = await this.getOrCreateFrameWorld(frameId, true);
|
|
953
|
+
return runWithContext(freshContextId);
|
|
954
|
+
}
|
|
955
|
+
throw err;
|
|
956
|
+
}
|
|
727
957
|
}
|
|
728
958
|
async resolveMatchingChildSessions(selector) {
|
|
729
959
|
const all = Array.from(this.childSessions.values());
|
|
@@ -742,31 +972,15 @@ var CdpDomChannel = class {
|
|
|
742
972
|
}
|
|
743
973
|
if ("text" in frameSel && frameSel.text) hints.push(frameSel.text);
|
|
744
974
|
}
|
|
745
|
-
const
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
if (el.src) matched.push(el.src);
|
|
755
|
-
}
|
|
756
|
-
} else if (fSel && typeof fSel === "object") {
|
|
757
|
-
if (fSel.css) {
|
|
758
|
-
try { if (el.matches(fSel.css) && el.src) matched.push(el.src); } catch {}
|
|
759
|
-
} else if (fSel.testID && (el.getAttribute("data-testid") === fSel.testID || el.getAttribute("testID") === fSel.testID)) {
|
|
760
|
-
if (el.src) matched.push(el.src);
|
|
761
|
-
} else if (fSel.accessibilityLabel && (el.getAttribute("aria-label") === fSel.accessibilityLabel || el.getAttribute("title") === fSel.accessibilityLabel)) {
|
|
762
|
-
if (el.src) matched.push(el.src);
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
return matched;
|
|
767
|
-
} catch { return []; }
|
|
768
|
-
})(${JSON.stringify(frameSel)})`
|
|
769
|
-
).catch(() => []);
|
|
975
|
+
const inspected = await this.inspectMatchingIframes(frameSel);
|
|
976
|
+
const exactFrameIds = new Set(
|
|
977
|
+
inspected.map((i) => i.frameId).filter((id) => Boolean(id))
|
|
978
|
+
);
|
|
979
|
+
if (exactFrameIds.size > 0) {
|
|
980
|
+
const byExactId = all.filter((c) => c.targetId && exactFrameIds.has(c.targetId));
|
|
981
|
+
if (byExactId.length > 0) return byExactId;
|
|
982
|
+
}
|
|
983
|
+
const iframeSrcs = inspected.map((i) => i.src).filter(Boolean);
|
|
770
984
|
if (iframeSrcs.length > 0) {
|
|
771
985
|
const matched = all.filter(
|
|
772
986
|
(c) => c.url && iframeSrcs.some((src) => {
|
|
@@ -785,7 +999,7 @@ var CdpDomChannel = class {
|
|
|
785
999
|
const byHint = all.filter((c) => c.url && hints.some((h) => c.url.includes(h)));
|
|
786
1000
|
if (byHint.length > 0) return byHint;
|
|
787
1001
|
}
|
|
788
|
-
return all;
|
|
1002
|
+
return inspected.length === 0 ? [] : all;
|
|
789
1003
|
}
|
|
790
1004
|
async query(selector) {
|
|
791
1005
|
const fallback = () => buildDomQueryScript(selector);
|
|
@@ -815,9 +1029,11 @@ var CdpDomChannel = class {
|
|
|
815
1029
|
if (this.hasExplicitFrame(selector)) {
|
|
816
1030
|
const inProcessFrames = await this.resolveInProcessChildFrames(selector);
|
|
817
1031
|
for (const frame of inProcessFrames) {
|
|
818
|
-
const frameRes = await this.
|
|
1032
|
+
const frameRes = await this.invokeInProcessFrame(
|
|
819
1033
|
frame.frameId,
|
|
820
|
-
|
|
1034
|
+
"query",
|
|
1035
|
+
[innerSel],
|
|
1036
|
+
childFallback
|
|
821
1037
|
).catch(() => []);
|
|
822
1038
|
if (Array.isArray(frameRes) && frameRes.length > 0) {
|
|
823
1039
|
return this.applyFrameOffset(frameRes, frame.offset);
|
|
@@ -866,9 +1082,11 @@ var CdpDomChannel = class {
|
|
|
866
1082
|
return Array.isArray(res) && res.length > 0 ? this.applyChildOffset(res, child) : [];
|
|
867
1083
|
}),
|
|
868
1084
|
...inProcessFrames.map(async (frame) => {
|
|
869
|
-
const res = await this.
|
|
1085
|
+
const res = await this.invokeInProcessFrame(
|
|
870
1086
|
frame.frameId,
|
|
871
|
-
|
|
1087
|
+
"waitForSelector",
|
|
1088
|
+
[innerSel, opts ?? {}],
|
|
1089
|
+
childFallback,
|
|
872
1090
|
rpcTimeout
|
|
873
1091
|
).catch(() => []);
|
|
874
1092
|
return Array.isArray(res) && res.length > 0 ? this.applyFrameOffset(res, frame.offset) : [];
|
|
@@ -883,14 +1101,13 @@ var CdpDomChannel = class {
|
|
|
883
1101
|
const appeared = await this.resolveInProcessChildFrames(selector);
|
|
884
1102
|
if (appeared.length > 0) {
|
|
885
1103
|
const remaining = Math.max(200, deadline - Date.now());
|
|
886
|
-
const
|
|
887
|
-
...opts,
|
|
888
|
-
timeoutMs: remaining
|
|
889
|
-
});
|
|
1104
|
+
const remOpts = { ...opts, timeoutMs: remaining };
|
|
890
1105
|
for (const frame of appeared) {
|
|
891
|
-
const res = await this.
|
|
1106
|
+
const res = await this.invokeInProcessFrame(
|
|
892
1107
|
frame.frameId,
|
|
893
|
-
|
|
1108
|
+
"waitForSelector",
|
|
1109
|
+
[innerSel, remOpts],
|
|
1110
|
+
() => buildDomWaitForSelectorScript(innerSel, remOpts),
|
|
894
1111
|
remaining + 2e3
|
|
895
1112
|
).catch(() => []);
|
|
896
1113
|
if (Array.isArray(res) && res.length > 0) {
|
|
@@ -903,7 +1120,7 @@ var CdpDomChannel = class {
|
|
|
903
1120
|
})()
|
|
904
1121
|
);
|
|
905
1122
|
}
|
|
906
|
-
|
|
1123
|
+
const finalMatches = await new Promise((resolve) => {
|
|
907
1124
|
let remaining = racers.length;
|
|
908
1125
|
let resolved = false;
|
|
909
1126
|
for (const p of racers) {
|
|
@@ -922,6 +1139,16 @@ var CdpDomChannel = class {
|
|
|
922
1139
|
});
|
|
923
1140
|
}
|
|
924
1141
|
});
|
|
1142
|
+
if (finalMatches.length === 0 && explicitFrame) {
|
|
1143
|
+
const frameSel = selector.frame;
|
|
1144
|
+
const stillMissing = (await this.inspectMatchingIframes(frameSel)).length === 0 && (await this.resolveInProcessChildFrames(selector)).length === 0 && (await this.resolveMatchingChildSessions(selector)).length === 0;
|
|
1145
|
+
if (stillMissing) {
|
|
1146
|
+
throw new Error(
|
|
1147
|
+
`Iframe matching ${JSON.stringify(frameSel)} not found within ${opts?.timeoutMs ?? 5e3}ms`
|
|
1148
|
+
);
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
return finalMatches;
|
|
925
1152
|
}
|
|
926
1153
|
async waitForHidden(selector, opts) {
|
|
927
1154
|
const rpcTimeout = Math.max((opts?.timeoutMs ?? 5e3) + 5e3, this.timeoutMs);
|
|
@@ -933,9 +1160,11 @@ var CdpDomChannel = class {
|
|
|
933
1160
|
const childFallback2 = () => buildDomWaitForHiddenScript(innerSel2, opts);
|
|
934
1161
|
for (const frame of inProcessFrames) {
|
|
935
1162
|
const ok = Boolean(
|
|
936
|
-
await this.
|
|
1163
|
+
await this.invokeInProcessFrame(
|
|
937
1164
|
frame.frameId,
|
|
938
|
-
|
|
1165
|
+
"waitForHidden",
|
|
1166
|
+
[innerSel2, opts ?? {}],
|
|
1167
|
+
childFallback2,
|
|
939
1168
|
rpcTimeout
|
|
940
1169
|
).catch(() => true)
|
|
941
1170
|
);
|
|
@@ -971,43 +1200,82 @@ var CdpDomChannel = class {
|
|
|
971
1200
|
return true;
|
|
972
1201
|
}
|
|
973
1202
|
async waitForMatch(selector, opts) {
|
|
974
|
-
const
|
|
1203
|
+
const timeoutMs = opts?.timeoutMs ?? 5e3;
|
|
1204
|
+
const deadline = Date.now() + timeoutMs;
|
|
1205
|
+
const rpcTimeout = Math.max(timeoutMs + 5e3, this.timeoutMs);
|
|
975
1206
|
const fallback = () => buildDomWaitForMatchScript(selector, opts);
|
|
976
1207
|
const explicitFrame = this.hasExplicitFrame(selector);
|
|
977
1208
|
const innerSel = this.stripFrameFromSelector(selector);
|
|
978
|
-
const childFallback = () => buildDomWaitForMatchScript(innerSel,
|
|
1209
|
+
const childFallback = (remOpts) => buildDomWaitForMatchScript(innerSel, remOpts);
|
|
979
1210
|
if (explicitFrame) {
|
|
980
|
-
const
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
return lastRes;
|
|
993
|
-
}
|
|
994
|
-
}
|
|
995
|
-
if (this.childSessions.size > 0) {
|
|
996
|
-
const candidates = await this.resolveMatchingChildSessions(selector);
|
|
997
|
-
if (explicitFrame && candidates.length > 0) {
|
|
998
|
-
let lastRes = { matched: false };
|
|
999
|
-
for (const child of candidates) {
|
|
1000
|
-
const childRes = await this.invokeDom(
|
|
1001
|
-
child.sessionId,
|
|
1211
|
+
const frameSel = selector.frame;
|
|
1212
|
+
let frameEverFound = false;
|
|
1213
|
+
let lastRes = { matched: false };
|
|
1214
|
+
while (true) {
|
|
1215
|
+
const remaining = Math.max(10, deadline - Date.now());
|
|
1216
|
+
const remOpts = { ...opts, timeoutMs: remaining };
|
|
1217
|
+
const remRpc = Math.max(remaining + 5e3, this.timeoutMs);
|
|
1218
|
+
const inspected = await this.inspectMatchingIframes(frameSel);
|
|
1219
|
+
if (inspected.some((i) => i.sameOriginAccessible)) {
|
|
1220
|
+
frameEverFound = true;
|
|
1221
|
+
const mainRes = await this.invokeDom(
|
|
1222
|
+
void 0,
|
|
1002
1223
|
"waitForMatch",
|
|
1003
|
-
[
|
|
1004
|
-
|
|
1005
|
-
|
|
1224
|
+
[selector, remOpts],
|
|
1225
|
+
() => buildDomWaitForMatchScript(selector, remOpts),
|
|
1226
|
+
remRpc
|
|
1006
1227
|
).catch(() => ({ matched: false }));
|
|
1007
|
-
if (
|
|
1008
|
-
lastRes =
|
|
1228
|
+
if (mainRes?.matched) return mainRes;
|
|
1229
|
+
lastRes = mainRes;
|
|
1230
|
+
if (Date.now() >= deadline) return lastRes;
|
|
1231
|
+
await new Promise((r) => setTimeout(r, 50));
|
|
1232
|
+
continue;
|
|
1009
1233
|
}
|
|
1010
|
-
|
|
1234
|
+
const inProcessFrames = await this.resolveInProcessChildFrames(selector);
|
|
1235
|
+
if (inProcessFrames.length > 0) {
|
|
1236
|
+
frameEverFound = true;
|
|
1237
|
+
for (const frame of inProcessFrames) {
|
|
1238
|
+
const frameRes = await this.invokeInProcessFrame(
|
|
1239
|
+
frame.frameId,
|
|
1240
|
+
"waitForMatch",
|
|
1241
|
+
[innerSel, remOpts],
|
|
1242
|
+
() => childFallback(remOpts),
|
|
1243
|
+
remRpc
|
|
1244
|
+
).catch(() => ({ matched: false }));
|
|
1245
|
+
if (frameRes?.matched) return frameRes;
|
|
1246
|
+
lastRes = frameRes;
|
|
1247
|
+
}
|
|
1248
|
+
if (Date.now() >= deadline) return lastRes;
|
|
1249
|
+
await new Promise((r) => setTimeout(r, 50));
|
|
1250
|
+
continue;
|
|
1251
|
+
}
|
|
1252
|
+
const candidates = this.childSessions.size > 0 ? await this.resolveMatchingChildSessions(selector) : [];
|
|
1253
|
+
if (candidates.length > 0) {
|
|
1254
|
+
frameEverFound = true;
|
|
1255
|
+
for (const child of candidates) {
|
|
1256
|
+
const childRes = await this.invokeDom(
|
|
1257
|
+
child.sessionId,
|
|
1258
|
+
"waitForMatch",
|
|
1259
|
+
[innerSel, remOpts],
|
|
1260
|
+
() => childFallback(remOpts),
|
|
1261
|
+
remRpc
|
|
1262
|
+
).catch(() => ({ matched: false }));
|
|
1263
|
+
if (childRes?.matched) return childRes;
|
|
1264
|
+
lastRes = childRes;
|
|
1265
|
+
}
|
|
1266
|
+
if (Date.now() >= deadline) return lastRes;
|
|
1267
|
+
await new Promise((r) => setTimeout(r, 50));
|
|
1268
|
+
continue;
|
|
1269
|
+
}
|
|
1270
|
+
if (Date.now() >= deadline) {
|
|
1271
|
+
if (!frameEverFound) {
|
|
1272
|
+
throw new Error(
|
|
1273
|
+
`Iframe matching ${JSON.stringify(frameSel)} not found within ${timeoutMs}ms`
|
|
1274
|
+
);
|
|
1275
|
+
}
|
|
1276
|
+
return lastRes;
|
|
1277
|
+
}
|
|
1278
|
+
await new Promise((r) => setTimeout(r, 60));
|
|
1011
1279
|
}
|
|
1012
1280
|
}
|
|
1013
1281
|
const result = await this.invokeDom(
|
|
@@ -1025,7 +1293,7 @@ var CdpDomChannel = class {
|
|
|
1025
1293
|
child.sessionId,
|
|
1026
1294
|
"waitForMatch",
|
|
1027
1295
|
[innerSel, opts],
|
|
1028
|
-
childFallback,
|
|
1296
|
+
() => childFallback(opts),
|
|
1029
1297
|
rpcTimeout
|
|
1030
1298
|
).catch(() => ({ matched: false }));
|
|
1031
1299
|
if (childRes?.matched) return childRes;
|
|
@@ -1044,9 +1312,11 @@ var CdpDomChannel = class {
|
|
|
1044
1312
|
if (inProcessFrames.length > 0) {
|
|
1045
1313
|
for (const frame of inProcessFrames) {
|
|
1046
1314
|
const ok = Boolean(
|
|
1047
|
-
await this.
|
|
1315
|
+
await this.invokeInProcessFrame(
|
|
1048
1316
|
frame.frameId,
|
|
1049
|
-
|
|
1317
|
+
"fill",
|
|
1318
|
+
[innerSel, value, opts ?? {}],
|
|
1319
|
+
childFallback,
|
|
1050
1320
|
rpcTimeout
|
|
1051
1321
|
).catch(() => false)
|
|
1052
1322
|
);
|
|
@@ -1104,9 +1374,12 @@ var CdpDomChannel = class {
|
|
|
1104
1374
|
const inProcessFrames = await this.resolveInProcessChildFrames(selector);
|
|
1105
1375
|
for (const frame of inProcessFrames) {
|
|
1106
1376
|
const ok = Boolean(
|
|
1107
|
-
await this.
|
|
1108
|
-
|
|
1109
|
-
|
|
1377
|
+
await this.invokeInProcessFrame(
|
|
1378
|
+
frame.frameId,
|
|
1379
|
+
"tap",
|
|
1380
|
+
[innerSel],
|
|
1381
|
+
childFallback
|
|
1382
|
+
).catch(() => false)
|
|
1110
1383
|
);
|
|
1111
1384
|
if (ok) return true;
|
|
1112
1385
|
}
|
|
@@ -1142,9 +1415,11 @@ var CdpDomChannel = class {
|
|
|
1142
1415
|
if (this.hasExplicitFrame(selector)) {
|
|
1143
1416
|
const inProcessFrames = await this.resolveInProcessChildFrames(selector);
|
|
1144
1417
|
for (const frame of inProcessFrames) {
|
|
1145
|
-
const frameRes = await this.
|
|
1418
|
+
const frameRes = await this.invokeInProcessFrame(
|
|
1146
1419
|
frame.frameId,
|
|
1147
|
-
|
|
1420
|
+
"scrollIntoView",
|
|
1421
|
+
[innerSel],
|
|
1422
|
+
childFallback
|
|
1148
1423
|
).catch(() => null);
|
|
1149
1424
|
if (frameRes) {
|
|
1150
1425
|
const adjusted = this.applyFrameOffset([frameRes], frame.offset);
|
|
@@ -1161,6 +1436,7 @@ var CdpDomChannel = class {
|
|
|
1161
1436
|
}
|
|
1162
1437
|
async disconnect() {
|
|
1163
1438
|
this.connected = false;
|
|
1439
|
+
this.inProcessFrameWorlds.clear();
|
|
1164
1440
|
this.rejectAllPending(new Error("CDP channel disconnected"));
|
|
1165
1441
|
if (this.ws) {
|
|
1166
1442
|
try {
|
|
@@ -1183,4 +1459,4 @@ export {
|
|
|
1183
1459
|
CdpDomChannel,
|
|
1184
1460
|
createCdpDomChannel
|
|
1185
1461
|
};
|
|
1186
|
-
//# sourceMappingURL=chunk-
|
|
1462
|
+
//# sourceMappingURL=chunk-HIEOI3WN.js.map
|