spana-test 0.15.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.
Files changed (126) hide show
  1. package/dist/{accessibility-audit-MHQ65DUD.js → accessibility-audit-F5KLUHLS.js} +14 -3
  2. package/dist/accessibility-audit-F5KLUHLS.js.map +1 -0
  3. package/dist/agent/index.js +11 -11
  4. package/dist/agent/session.d.ts +1 -1
  5. package/dist/agent/session.d.ts.map +1 -1
  6. package/dist/api/app.d.ts +11 -2
  7. package/dist/api/app.d.ts.map +1 -1
  8. package/dist/api/expect.d.ts +2 -2
  9. package/dist/api/expect.d.ts.map +1 -1
  10. package/dist/api/flow.d.ts +2 -0
  11. package/dist/api/flow.d.ts.map +1 -1
  12. package/dist/{app-U35R7K2N.js → app-C353NGBT.js} +3 -3
  13. package/dist/channels/cdp-client.d.ts +11 -4
  14. package/dist/channels/cdp-client.d.ts.map +1 -1
  15. package/dist/channels/dom-channel.d.ts +2 -2
  16. package/dist/channels/dom-channel.d.ts.map +1 -1
  17. package/dist/{chunk-Q57EOH55.js → chunk-4TYO6O7T.js} +2 -2
  18. package/dist/{chunk-GFPMOB2T.js → chunk-5WPPWTC3.js} +740 -257
  19. package/dist/chunk-5WPPWTC3.js.map +1 -0
  20. package/dist/{chunk-TEN2FJ24.js → chunk-62SDNQKK.js} +3 -3
  21. package/dist/{chunk-VVSJIMMQ.js → chunk-7K7WVTFZ.js} +6 -6
  22. package/dist/{chunk-V5X5LTJ4.js → chunk-7O5YXVCD.js} +2 -2
  23. package/dist/{chunk-H53YJ4ZL.js → chunk-CA66JCX2.js} +262 -48
  24. package/dist/chunk-CA66JCX2.js.map +1 -0
  25. package/dist/{chunk-ECKFZNCV.js → chunk-EA7DZ5TN.js} +11 -2
  26. package/dist/chunk-EA7DZ5TN.js.map +1 -0
  27. package/dist/{chunk-MDXK33X7.js → chunk-GMEVJQTT.js} +2 -2
  28. package/dist/{chunk-N26ARDAP.js → chunk-HIEOI3WN.js} +310 -107
  29. package/dist/chunk-HIEOI3WN.js.map +1 -0
  30. package/dist/{chunk-KAIVNY7F.js → chunk-HJZT6YOA.js} +2 -2
  31. package/dist/{chunk-5HWERJJ2.js → chunk-JRGJTUPS.js} +3 -3
  32. package/dist/{chunk-MRLSHYL5.js → chunk-KIFNHFFI.js} +45 -18
  33. package/dist/chunk-KIFNHFFI.js.map +1 -0
  34. package/dist/{chunk-CE3ANP5J.js → chunk-LGFTUVN4.js} +2 -2
  35. package/dist/{chunk-QFGRV4UF.js → chunk-UZU7VYKN.js} +107 -24
  36. package/dist/chunk-UZU7VYKN.js.map +1 -0
  37. package/dist/{chunk-JBON4ZDX.js → chunk-WBCAF7SC.js} +90 -54
  38. package/dist/chunk-WBCAF7SC.js.map +1 -0
  39. package/dist/{chunk-UEAUXXJQ.js → chunk-ZCSH3QKX.js} +877 -425
  40. package/dist/chunk-ZCSH3QKX.js.map +1 -0
  41. package/dist/cli/test-command.d.ts +18 -0
  42. package/dist/cli/test-command.d.ts.map +1 -1
  43. package/dist/cli.js +16 -14
  44. package/dist/cli.js.map +1 -1
  45. package/dist/config-loader-TSADVSBY.js +10 -0
  46. package/dist/core/accessibility-audit.d.ts.map +1 -1
  47. package/dist/core/engine.d.ts.map +1 -1
  48. package/dist/core/orchestrator.d.ts +2 -0
  49. package/dist/core/orchestrator.d.ts.map +1 -1
  50. package/dist/core/parallel.d.ts +9 -1
  51. package/dist/core/parallel.d.ts.map +1 -1
  52. package/dist/core/worker-pool.d.ts +5 -2
  53. package/dist/core/worker-pool.d.ts.map +1 -1
  54. package/dist/{doctor-command-IXDNCYHH.js → doctor-command-UUQ4RFMK.js} +7 -7
  55. package/dist/{driver-DXXQA3CS.js → driver-3HBDKESK.js} +5 -5
  56. package/dist/{driver-HRGZZ2HK.js → driver-LKXSKNG3.js} +4 -4
  57. package/dist/drivers/cdp-browser.d.ts +8 -0
  58. package/dist/drivers/cdp-browser.d.ts.map +1 -1
  59. package/dist/drivers/playwright.d.ts +2 -0
  60. package/dist/drivers/playwright.d.ts.map +1 -1
  61. package/dist/drivers/raw-driver.d.ts +2 -0
  62. package/dist/drivers/raw-driver.d.ts.map +1 -1
  63. package/dist/{electrobun-7TYBSRMP.js → electrobun-HILYDIJ3.js} +5 -5
  64. package/dist/index.d.ts +5 -4
  65. package/dist/index.d.ts.map +1 -1
  66. package/dist/index.js +23 -13
  67. package/dist/index.js.map +1 -1
  68. package/dist/{json-57Z2YSES.js → json-67HY4VQK.js} +6 -1
  69. package/dist/json-67HY4VQK.js.map +1 -0
  70. package/dist/{local-RDZO7L7L.js → local-J2NC6YKI.js} +5 -5
  71. package/dist/{playwright-ILWU2XLC.js → playwright-JMHCABDJ.js} +5 -5
  72. package/dist/report/json.d.ts.map +1 -1
  73. package/dist/report/types.d.ts +2 -0
  74. package/dist/report/types.d.ts.map +1 -1
  75. package/dist/runtime/local.d.ts +0 -4
  76. package/dist/runtime/local.d.ts.map +1 -1
  77. package/dist/schemas/config.d.ts +40 -4
  78. package/dist/schemas/config.d.ts.map +1 -1
  79. package/dist/schemas/element.d.ts +2 -0
  80. package/dist/schemas/element.d.ts.map +1 -1
  81. package/dist/{server-ZHUQ36R7.js → server-RHAHCANZ.js} +2 -2
  82. package/dist/{server-Q5O666EK.js → server-RTDMJIQZ.js} +14 -13
  83. package/dist/{server-Q5O666EK.js.map → server-RTDMJIQZ.js.map} +1 -1
  84. package/dist/{session-7HFE3POF.js → session-7CWHTQ2E.js} +12 -12
  85. package/dist/smart/auto-wait.d.ts.map +1 -1
  86. package/dist/smart/coordinator.d.ts +2 -2
  87. package/dist/smart/coordinator.d.ts.map +1 -1
  88. package/dist/studio/api.d.ts +2 -0
  89. package/dist/studio/api.d.ts.map +1 -1
  90. package/dist/studio/routers/inspector.d.ts +2 -0
  91. package/dist/studio/routers/inspector.d.ts.map +1 -1
  92. package/dist/{studio-command-WQTVBE3N.js → studio-command-PZHMLCKE.js} +2 -2
  93. package/dist/{test-command-W7K6FKEU.js → test-command-FJOP2GYD.js} +341 -83
  94. package/dist/test-command-FJOP2GYD.js.map +1 -0
  95. package/package.json +4 -8
  96. package/dist/accessibility-audit-MHQ65DUD.js.map +0 -1
  97. package/dist/chunk-ECKFZNCV.js.map +0 -1
  98. package/dist/chunk-GFPMOB2T.js.map +0 -1
  99. package/dist/chunk-H53YJ4ZL.js.map +0 -1
  100. package/dist/chunk-JBON4ZDX.js.map +0 -1
  101. package/dist/chunk-MRLSHYL5.js.map +0 -1
  102. package/dist/chunk-N26ARDAP.js.map +0 -1
  103. package/dist/chunk-QFGRV4UF.js.map +0 -1
  104. package/dist/chunk-UEAUXXJQ.js.map +0 -1
  105. package/dist/config-loader-H2MCYBYC.js +0 -10
  106. package/dist/json-57Z2YSES.js.map +0 -1
  107. package/dist/test-command-W7K6FKEU.js.map +0 -1
  108. /package/dist/{app-U35R7K2N.js.map → app-C353NGBT.js.map} +0 -0
  109. /package/dist/{chunk-Q57EOH55.js.map → chunk-4TYO6O7T.js.map} +0 -0
  110. /package/dist/{chunk-TEN2FJ24.js.map → chunk-62SDNQKK.js.map} +0 -0
  111. /package/dist/{chunk-VVSJIMMQ.js.map → chunk-7K7WVTFZ.js.map} +0 -0
  112. /package/dist/{chunk-V5X5LTJ4.js.map → chunk-7O5YXVCD.js.map} +0 -0
  113. /package/dist/{chunk-MDXK33X7.js.map → chunk-GMEVJQTT.js.map} +0 -0
  114. /package/dist/{chunk-KAIVNY7F.js.map → chunk-HJZT6YOA.js.map} +0 -0
  115. /package/dist/{chunk-5HWERJJ2.js.map → chunk-JRGJTUPS.js.map} +0 -0
  116. /package/dist/{chunk-CE3ANP5J.js.map → chunk-LGFTUVN4.js.map} +0 -0
  117. /package/dist/{config-loader-H2MCYBYC.js.map → config-loader-TSADVSBY.js.map} +0 -0
  118. /package/dist/{doctor-command-IXDNCYHH.js.map → doctor-command-UUQ4RFMK.js.map} +0 -0
  119. /package/dist/{driver-DXXQA3CS.js.map → driver-3HBDKESK.js.map} +0 -0
  120. /package/dist/{driver-HRGZZ2HK.js.map → driver-LKXSKNG3.js.map} +0 -0
  121. /package/dist/{electrobun-7TYBSRMP.js.map → electrobun-HILYDIJ3.js.map} +0 -0
  122. /package/dist/{local-RDZO7L7L.js.map → local-J2NC6YKI.js.map} +0 -0
  123. /package/dist/{playwright-ILWU2XLC.js.map → playwright-JMHCABDJ.js.map} +0 -0
  124. /package/dist/{server-ZHUQ36R7.js.map → server-RHAHCANZ.js.map} +0 -0
  125. /package/dist/{session-7HFE3POF.js.map → session-7CWHTQ2E.js.map} +0 -0
  126. /package/dist/{studio-command-WQTVBE3N.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-H53YJ4ZL.js";
13
+ } from "./chunk-CA66JCX2.js";
14
14
  import {
15
15
  init_esm_shims
16
16
  } from "./chunk-FTXUQMGH.js";
@@ -279,6 +279,8 @@ 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();
@@ -296,7 +298,18 @@ var CdpDomChannel = class {
296
298
  this.createWebSocket = options.createWebSocket ?? defaultWebSocketFactory;
297
299
  }
298
300
  isConnected() {
299
- 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;
300
313
  }
301
314
  async listTargets() {
302
315
  const raw = await this.fetchTargets();
@@ -332,6 +345,9 @@ var CdpDomChannel = class {
332
345
  await this.openSocket(target.webSocketDebuggerUrl);
333
346
  }
334
347
  async connect() {
348
+ if (this.permanentlyClosed) {
349
+ throw new Error(this.closedReason);
350
+ }
335
351
  if (this.isConnected()) return;
336
352
  let wsUrl = this.explicitWsUrl;
337
353
  if (!wsUrl) {
@@ -526,6 +542,9 @@ var CdpDomChannel = class {
526
542
  });
527
543
  }
528
544
  async sendCommand(method, params = {}, sessionId, timeoutMs) {
545
+ if (this.permanentlyClosed) {
546
+ throw new Error(this.closedReason);
547
+ }
529
548
  if (!this.isConnected()) {
530
549
  await this.connect();
531
550
  }
@@ -555,8 +574,12 @@ var CdpDomChannel = class {
555
574
  const effectiveTimeout = timeoutMs ?? this.timeoutMs;
556
575
  const deadline = Date.now() + effectiveTimeout;
557
576
  let lastError;
577
+ const targetSid = sessionId === void 0 ? this.activeSessionId : sessionId;
558
578
  for (let attempt = 0; attempt < maxAttempts; attempt++) {
559
579
  const remaining = Math.max(250, deadline - Date.now());
580
+ let offDestroyed;
581
+ let offCleared;
582
+ let offNavigated;
560
583
  try {
561
584
  const evalParams = {
562
585
  expression,
@@ -566,7 +589,32 @@ var CdpDomChannel = class {
566
589
  if (contextId !== void 0) {
567
590
  evalParams["contextId"] = contextId;
568
591
  }
569
- const response = await this.sendCommand("Runtime.evaluate", evalParams, sessionId, remaining);
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]);
570
618
  if (response?.exceptionDetails) {
571
619
  const detail = response.exceptionDetails.exception?.description ?? response.exceptionDetails.text ?? "Evaluation threw an exception";
572
620
  throw new Error(`CDP evaluate failed: ${detail}`);
@@ -590,6 +638,10 @@ var CdpDomChannel = class {
590
638
  continue;
591
639
  }
592
640
  throw err;
641
+ } finally {
642
+ offDestroyed?.();
643
+ offCleared?.();
644
+ offNavigated?.();
593
645
  }
594
646
  }
595
647
  throw lastError ?? new Error("CDP evaluate failed: execution context was destroyed");
@@ -598,8 +650,12 @@ var CdpDomChannel = class {
598
650
  async evaluateFast(script, ...args) {
599
651
  return this.evaluateOnSessionWithTimeout(void 0, script, 2e3, args, void 0, 1);
600
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
+ }
601
657
  async evaluateOnSession(sessionId, script, ...args) {
602
- return this.evaluateOnSessionWithTimeout(sessionId, script, void 0, args);
658
+ return this.evaluateOnSessionWithTimeout(sessionId, script, void 0, args, void 0, 3);
603
659
  }
604
660
  async evaluate(script, ...args) {
605
661
  return this.evaluateOnSession(void 0, script, ...args);
@@ -637,12 +693,96 @@ var CdpDomChannel = class {
637
693
  }
638
694
  }));
639
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
+ }
640
781
  /**
641
782
  * Resolve in-process cross-origin child frames (e.g. same-site subdomains such as
642
- * `notes.app.localhost` embedded in `studio.app.localhost`). Chromium places same-site
643
- * iframes in the same renderer process (so no OOPIF target/session is created), while
644
- * Same-Origin Policy still blocks `iframe.contentDocument` from JS in the top document.
645
- * 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.
646
786
  */
647
787
  async resolveInProcessChildFrames(selector) {
648
788
  if (!this.hasExplicitFrame(selector)) return [];
@@ -650,56 +790,28 @@ var CdpDomChannel = class {
650
790
  const treeRes = await this.sendCommand("Page.getFrameTree").catch(() => null);
651
791
  if (!treeRes?.frameTree?.childFrames?.length) return [];
652
792
  const flatFrames = [];
653
- const walk = (nodes) => {
793
+ const walk = (nodes, parentId) => {
654
794
  if (!Array.isArray(nodes)) return;
655
795
  for (const n of nodes) {
656
796
  if (n?.frame?.id) {
657
797
  flatFrames.push({
658
798
  id: n.frame.id,
799
+ parentId: n.frame.parentId ?? parentId,
659
800
  url: n.frame.url ?? "",
660
801
  name: n.frame.name ?? ""
661
802
  });
662
803
  }
663
- if (n?.childFrames) walk(n.childFrames);
804
+ if (n?.childFrames) walk(n.childFrames, n?.frame?.id);
664
805
  }
665
806
  };
666
- walk(treeRes.frameTree.childFrames);
807
+ walk(treeRes.frameTree.childFrames, treeRes.frameTree.frame?.id);
667
808
  if (flatFrames.length === 0) return [];
668
- const iframeInfos = await this.evaluateOnSession(
669
- void 0,
670
- `((fSel) => {
671
- try {
672
- const iframes = Array.from(document.querySelectorAll("iframe"));
673
- const matched = [];
674
- for (const el of iframes) {
675
- let ok = false;
676
- if (typeof fSel === "string") {
677
- if (el.getAttribute("title") === fSel || el.getAttribute("aria-label") === fSel || el.getAttribute("name") === fSel) ok = true;
678
- else { try { if (el.matches(fSel)) ok = true; } catch {} }
679
- } else if (fSel && typeof fSel === "object") {
680
- if (fSel.css) {
681
- try { if (el.matches(fSel.css)) ok = true; } catch {}
682
- } else if (fSel.testID && (el.getAttribute("data-testid") === fSel.testID || el.getAttribute("testID") === fSel.testID)) {
683
- ok = true;
684
- } else if (fSel.accessibilityLabel && (el.getAttribute("aria-label") === fSel.accessibilityLabel || el.getAttribute("title") === fSel.accessibilityLabel)) {
685
- ok = true;
686
- } else if (fSel.text && (el.getAttribute("title") === fSel.text || el.getAttribute("aria-label") === fSel.text)) {
687
- ok = true;
688
- }
689
- }
690
- if (ok) {
691
- const r = el.getBoundingClientRect();
692
- matched.push({ src: el.src || "", name: el.getAttribute("name") || "", x: r.left, y: r.top });
693
- }
694
- }
695
- return matched;
696
- } catch { return []; }
697
- })(${JSON.stringify(frameSel)})`
698
- ).catch(() => []);
699
- if (iframeInfos.length === 0) return [];
700
- const out = [];
701
- for (const info of iframeInfos) {
702
- 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) => {
703
815
  if (info.name && f.name && f.name === info.name) return true;
704
816
  if (!info.src || !f.url) return false;
705
817
  try {
@@ -709,7 +821,7 @@ var CdpDomChannel = class {
709
821
  } catch {
710
822
  return f.url === info.src || f.url.startsWith(info.src);
711
823
  }
712
- }) ?? flatFrames.find((f) => {
824
+ }) ?? pool.find((f) => {
713
825
  if (!info.src || !f.url) return false;
714
826
  try {
715
827
  return new URL(info.src).origin === new URL(f.url).origin;
@@ -717,10 +829,70 @@ var CdpDomChannel = class {
717
829
  return false;
718
830
  }
719
831
  });
832
+ };
833
+ const out = [];
834
+ const topInfos = await this.inspectMatchingIframes(frameSel);
835
+ for (const info of topInfos) {
836
+ const match = matchInfoToFrame(info, flatFrames);
720
837
  if (match && !out.some((x) => x.frameId === match.id)) {
721
838
  out.push({ frameId: match.id, url: match.url, offset: { x: info.x, y: info.y } });
722
839
  }
723
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
+ }
724
896
  return out;
725
897
  }
726
898
  async getOrCreateFrameWorld(frameId, forceFresh = false) {
@@ -800,31 +972,15 @@ var CdpDomChannel = class {
800
972
  }
801
973
  if ("text" in frameSel && frameSel.text) hints.push(frameSel.text);
802
974
  }
803
- const iframeSrcs = await this.evaluateOnSession(
804
- void 0,
805
- `((fSel) => {
806
- try {
807
- const iframes = Array.from(document.querySelectorAll("iframe"));
808
- const matched = [];
809
- for (const el of iframes) {
810
- if (typeof fSel === "string") {
811
- if (el.getAttribute("title") === fSel || el.getAttribute("aria-label") === fSel || el.getAttribute("name") === fSel || el.matches(fSel)) {
812
- if (el.src) matched.push(el.src);
813
- }
814
- } else if (fSel && typeof fSel === "object") {
815
- if (fSel.css) {
816
- try { if (el.matches(fSel.css) && el.src) matched.push(el.src); } catch {}
817
- } else if (fSel.testID && (el.getAttribute("data-testid") === fSel.testID || el.getAttribute("testID") === fSel.testID)) {
818
- if (el.src) matched.push(el.src);
819
- } else if (fSel.accessibilityLabel && (el.getAttribute("aria-label") === fSel.accessibilityLabel || el.getAttribute("title") === fSel.accessibilityLabel)) {
820
- if (el.src) matched.push(el.src);
821
- }
822
- }
823
- }
824
- return matched;
825
- } catch { return []; }
826
- })(${JSON.stringify(frameSel)})`
827
- ).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);
828
984
  if (iframeSrcs.length > 0) {
829
985
  const matched = all.filter(
830
986
  (c) => c.url && iframeSrcs.some((src) => {
@@ -843,7 +999,7 @@ var CdpDomChannel = class {
843
999
  const byHint = all.filter((c) => c.url && hints.some((h) => c.url.includes(h)));
844
1000
  if (byHint.length > 0) return byHint;
845
1001
  }
846
- return all;
1002
+ return inspected.length === 0 ? [] : all;
847
1003
  }
848
1004
  async query(selector) {
849
1005
  const fallback = () => buildDomQueryScript(selector);
@@ -964,7 +1120,7 @@ var CdpDomChannel = class {
964
1120
  })()
965
1121
  );
966
1122
  }
967
- return new Promise((resolve) => {
1123
+ const finalMatches = await new Promise((resolve) => {
968
1124
  let remaining = racers.length;
969
1125
  let resolved = false;
970
1126
  for (const p of racers) {
@@ -983,6 +1139,16 @@ var CdpDomChannel = class {
983
1139
  });
984
1140
  }
985
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;
986
1152
  }
987
1153
  async waitForHidden(selector, opts) {
988
1154
  const rpcTimeout = Math.max((opts?.timeoutMs ?? 5e3) + 5e3, this.timeoutMs);
@@ -1034,45 +1200,82 @@ var CdpDomChannel = class {
1034
1200
  return true;
1035
1201
  }
1036
1202
  async waitForMatch(selector, opts) {
1037
- const rpcTimeout = Math.max((opts?.timeoutMs ?? 5e3) + 5e3, this.timeoutMs);
1203
+ const timeoutMs = opts?.timeoutMs ?? 5e3;
1204
+ const deadline = Date.now() + timeoutMs;
1205
+ const rpcTimeout = Math.max(timeoutMs + 5e3, this.timeoutMs);
1038
1206
  const fallback = () => buildDomWaitForMatchScript(selector, opts);
1039
1207
  const explicitFrame = this.hasExplicitFrame(selector);
1040
1208
  const innerSel = this.stripFrameFromSelector(selector);
1041
- const childFallback = () => buildDomWaitForMatchScript(innerSel, opts);
1209
+ const childFallback = (remOpts) => buildDomWaitForMatchScript(innerSel, remOpts);
1042
1210
  if (explicitFrame) {
1043
- const inProcessFrames = await this.resolveInProcessChildFrames(selector);
1044
- if (inProcessFrames.length > 0) {
1045
- let lastRes = { matched: false };
1046
- for (const frame of inProcessFrames) {
1047
- const frameRes = await this.invokeInProcessFrame(
1048
- frame.frameId,
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,
1049
1223
  "waitForMatch",
1050
- [innerSel, opts],
1051
- childFallback,
1052
- rpcTimeout
1224
+ [selector, remOpts],
1225
+ () => buildDomWaitForMatchScript(selector, remOpts),
1226
+ remRpc
1053
1227
  ).catch(() => ({ matched: false }));
1054
- if (frameRes?.matched) return frameRes;
1055
- lastRes = frameRes;
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;
1056
1233
  }
1057
- return lastRes;
1058
- }
1059
- }
1060
- if (this.childSessions.size > 0) {
1061
- const candidates = await this.resolveMatchingChildSessions(selector);
1062
- if (explicitFrame && candidates.length > 0) {
1063
- let lastRes = { matched: false };
1064
- for (const child of candidates) {
1065
- const childRes = await this.invokeDom(
1066
- child.sessionId,
1067
- "waitForMatch",
1068
- [innerSel, opts],
1069
- childFallback,
1070
- rpcTimeout
1071
- ).catch(() => ({ matched: false }));
1072
- if (childRes?.matched) return childRes;
1073
- lastRes = childRes;
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;
1074
1251
  }
1075
- return lastRes;
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));
1076
1279
  }
1077
1280
  }
1078
1281
  const result = await this.invokeDom(
@@ -1090,7 +1293,7 @@ var CdpDomChannel = class {
1090
1293
  child.sessionId,
1091
1294
  "waitForMatch",
1092
1295
  [innerSel, opts],
1093
- childFallback,
1296
+ () => childFallback(opts),
1094
1297
  rpcTimeout
1095
1298
  ).catch(() => ({ matched: false }));
1096
1299
  if (childRes?.matched) return childRes;
@@ -1256,4 +1459,4 @@ export {
1256
1459
  CdpDomChannel,
1257
1460
  createCdpDomChannel
1258
1461
  };
1259
- //# sourceMappingURL=chunk-N26ARDAP.js.map
1462
+ //# sourceMappingURL=chunk-HIEOI3WN.js.map