spana-test 0.7.0 → 0.8.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/agent/index.d.ts +2 -2
- package/dist/agent/index.js +9 -9
- package/dist/{allure-RNMEYTXS.js → allure-RAEK4SIH.js} +2 -2
- package/dist/allure-RAEK4SIH.js.map +1 -0
- package/dist/{android-4NVTZMHL.js → android-6BOQTMM3.js} +2 -2
- package/dist/app-CgbLADmF.d.ts +1191 -0
- package/dist/{chunk-H27IBIGA.js → chunk-2AFWVHQK.js} +63 -43
- package/dist/chunk-2AFWVHQK.js.map +1 -0
- package/dist/{chunk-JYFPZRCN.js → chunk-2T4K7BJ3.js} +3 -1
- package/dist/chunk-2T4K7BJ3.js.map +1 -0
- package/dist/{chunk-6B5Y75V4.js → chunk-3FXDOTFI.js} +840 -271
- package/dist/chunk-3FXDOTFI.js.map +1 -0
- package/dist/{chunk-T5CROOR7.js → chunk-AJCSETN6.js} +1329 -245
- package/dist/chunk-AJCSETN6.js.map +1 -0
- package/dist/chunk-JPZCZHL4.js +79 -0
- package/dist/chunk-JPZCZHL4.js.map +1 -0
- package/dist/{chunk-RURZVMZ7.js → chunk-NS2HLJO4.js} +3 -3
- package/dist/{chunk-2IXXEXTL.js → chunk-PMXSU5MS.js} +2 -2
- package/dist/{chunk-HYSTRWYN.js → chunk-QP4MDUBY.js} +4 -4
- package/dist/chunk-RKYKRGHB.js +236 -0
- package/dist/chunk-RKYKRGHB.js.map +1 -0
- package/dist/{chunk-HCG4CJKR.js → chunk-SF7UYW4I.js} +3 -3
- package/dist/{chunk-T3EBOYLS.js → chunk-SNL4X67N.js} +1043 -99
- package/dist/chunk-SNL4X67N.js.map +1 -0
- package/dist/{chunk-KNSAHEXI.js → chunk-WKVU24B6.js} +8 -8
- package/dist/{chunk-S5JNNDXS.js → chunk-WV3ALL3H.js} +65 -37
- package/dist/chunk-WV3ALL3H.js.map +1 -0
- package/dist/cli.js +23 -11
- package/dist/cli.js.map +1 -1
- package/dist/config-loader-5FU45FXK.js +9 -0
- package/dist/{console-MI2XB5RG.js → console-BGAK7Z2L.js} +11 -1
- package/dist/{console-MI2XB5RG.js.map → console-BGAK7Z2L.js.map} +1 -1
- package/dist/{daemon-manager-FBISTX24.js → daemon-manager-DDYQITPD.js} +4 -2
- package/dist/{discover-LHEBSUIP.js → discover-RLSKEBAX.js} +5 -5
- package/dist/{doctor-command-WPEVZEZ4.js → doctor-command-HEQQOYUR.js} +26 -18
- package/dist/doctor-command-HEQQOYUR.js.map +1 -0
- package/dist/{flow-g6AICPAl.d.ts → flow-Md5xLwbX.d.ts} +3 -29
- package/dist/gherkin/steps.d.ts +2 -2
- package/dist/{html-IKCTZH2U.js → html-JO2YNRWX.js} +3 -3
- package/dist/html-JO2YNRWX.js.map +1 -0
- package/dist/index.d.ts +184 -20
- package/dist/index.js +230 -147
- package/dist/index.js.map +1 -1
- package/dist/{installer-VUPFWP5X.js → installer-IYGMG7LS.js} +4 -4
- package/dist/{ios-JPK43TFZ.js → ios-Y4TO5MBR.js} +7 -3
- package/dist/{server-IGLBFEU7.js → server-4PEREPHY.js} +2 -2
- package/dist/{server-EBPYK3VE.js → server-JPNH33MX.js} +50 -36
- package/dist/server-JPNH33MX.js.map +1 -0
- package/dist/{session-cJ_tZjCL.d.ts → session-D9e30RVS.d.ts} +1 -1
- package/dist/session-V4PYJXNB.js +18 -0
- package/dist/{studio-command-FLA5HKRK.js → studio-command-JOIFCOHC.js} +2 -2
- package/dist/{test-command-P5W7UD52.js → test-command-JCO2HPYI.js} +221 -27
- package/dist/test-command-JCO2HPYI.js.map +1 -0
- package/native/darwin-arm64/libspana_native.dylib +0 -0
- package/native/darwin-x64/libspana_native.dylib +0 -0
- package/native/linux-arm64/libspana_native.so +0 -0
- package/native/linux-x64/libspana_native.so +0 -0
- package/native/win32-x64/spana_native.dll +0 -0
- package/package.json +1 -1
- package/studio-dist/assets/index-CBFsOh-9.js +193 -0
- package/studio-dist/assets/index-DH_18EyL.css +1 -0
- package/studio-dist/index.html +2 -2
- package/dist/allure-RNMEYTXS.js.map +0 -1
- package/dist/app-D_UyZBsl.d.ts +0 -915
- package/dist/chunk-6B5Y75V4.js.map +0 -1
- package/dist/chunk-DTNK54C2.js +0 -127
- package/dist/chunk-DTNK54C2.js.map +0 -1
- package/dist/chunk-H27IBIGA.js.map +0 -1
- package/dist/chunk-JYFPZRCN.js.map +0 -1
- package/dist/chunk-OBCFACUW.js +0 -28
- package/dist/chunk-OBCFACUW.js.map +0 -1
- package/dist/chunk-S5JNNDXS.js.map +0 -1
- package/dist/chunk-T3EBOYLS.js.map +0 -1
- package/dist/chunk-T5CROOR7.js.map +0 -1
- package/dist/config-loader-NIDQGP3K.js +0 -9
- package/dist/doctor-command-WPEVZEZ4.js.map +0 -1
- package/dist/html-IKCTZH2U.js.map +0 -1
- package/dist/server-EBPYK3VE.js.map +0 -1
- package/dist/session-QRWH3SPW.js +0 -18
- package/dist/test-command-P5W7UD52.js.map +0 -1
- package/studio-dist/assets/index-C-Io44gy.js +0 -193
- package/studio-dist/assets/index-DfM9lK4p.css +0 -1
- /package/dist/{android-4NVTZMHL.js.map → android-6BOQTMM3.js.map} +0 -0
- /package/dist/{chunk-RURZVMZ7.js.map → chunk-NS2HLJO4.js.map} +0 -0
- /package/dist/{chunk-2IXXEXTL.js.map → chunk-PMXSU5MS.js.map} +0 -0
- /package/dist/{chunk-HYSTRWYN.js.map → chunk-QP4MDUBY.js.map} +0 -0
- /package/dist/{chunk-HCG4CJKR.js.map → chunk-SF7UYW4I.js.map} +0 -0
- /package/dist/{chunk-KNSAHEXI.js.map → chunk-WKVU24B6.js.map} +0 -0
- /package/dist/{config-loader-NIDQGP3K.js.map → config-loader-5FU45FXK.js.map} +0 -0
- /package/dist/{daemon-manager-FBISTX24.js.map → daemon-manager-DDYQITPD.js.map} +0 -0
- /package/dist/{discover-LHEBSUIP.js.map → discover-RLSKEBAX.js.map} +0 -0
- /package/dist/{installer-VUPFWP5X.js.map → installer-IYGMG7LS.js.map} +0 -0
- /package/dist/{ios-JPK43TFZ.js.map → ios-Y4TO5MBR.js.map} +0 -0
- /package/dist/{server-IGLBFEU7.js.map → server-4PEREPHY.js.map} +0 -0
- /package/dist/{session-QRWH3SPW.js.map → session-V4PYJXNB.js.map} +0 -0
- /package/dist/{studio-command-FLA5HKRK.js.map → studio-command-JOIFCOHC.js.map} +0 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
allocatePort,
|
|
3
3
|
releasePort
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-JPZCZHL4.js";
|
|
5
5
|
import {
|
|
6
6
|
adbShell,
|
|
7
7
|
findADB
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-2AFWVHQK.js";
|
|
9
9
|
|
|
10
10
|
// src/errors.ts
|
|
11
11
|
import { Schema } from "effect";
|
|
@@ -125,10 +125,135 @@ function buildEvaluateExpression(script, args = []) {
|
|
|
125
125
|
}
|
|
126
126
|
return script;
|
|
127
127
|
}
|
|
128
|
+
function serializeSelectorForDom(sel) {
|
|
129
|
+
if (sel instanceof RegExp) {
|
|
130
|
+
return { __spanaRegex: sel.source, flags: sel.flags };
|
|
131
|
+
}
|
|
132
|
+
if (Array.isArray(sel)) {
|
|
133
|
+
return sel.map((item) => serializeSelectorForDom(item));
|
|
134
|
+
}
|
|
135
|
+
if (sel && typeof sel === "object") {
|
|
136
|
+
const out = {};
|
|
137
|
+
for (const [k, v] of Object.entries(sel)) {
|
|
138
|
+
if (v !== void 0) {
|
|
139
|
+
out[k] = serializeSelectorForDom(v);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return out;
|
|
143
|
+
}
|
|
144
|
+
return sel;
|
|
145
|
+
}
|
|
128
146
|
var SHARED_DOM_TRAVERSAL_HELPERS = `
|
|
147
|
+
function matchSpec(actual, spec, exact) {
|
|
148
|
+
var str = String(actual || "");
|
|
149
|
+
if (spec && typeof spec === "object" && typeof spec.__spanaRegex === "string") {
|
|
150
|
+
try { return new RegExp(spec.__spanaRegex, spec.flags || "").test(str); } catch (e) { return false; }
|
|
151
|
+
}
|
|
152
|
+
var needle = String(spec == null ? "" : spec);
|
|
153
|
+
if (exact) return str.trim() === needle.trim();
|
|
154
|
+
return str.toLowerCase().indexOf(needle.toLowerCase()) !== -1;
|
|
155
|
+
}
|
|
156
|
+
function getImplicitRole(el) {
|
|
157
|
+
if (!el || !el.getAttribute) return "";
|
|
158
|
+
var explicit = (el.getAttribute("role") || "").trim().toLowerCase();
|
|
159
|
+
if (explicit) return explicit.split(/\\s+/)[0] || "";
|
|
160
|
+
var tag = el.tagName ? el.tagName.toUpperCase() : "";
|
|
161
|
+
if (tag === "BUTTON") return "button";
|
|
162
|
+
if (tag === "A") return el.hasAttribute("href") ? "link" : "";
|
|
163
|
+
if (tag === "TEXTAREA") return "textbox";
|
|
164
|
+
if (tag === "SELECT") return (el.hasAttribute("multiple") || Number(el.getAttribute("size") || 0) > 1) ? "listbox" : "combobox";
|
|
165
|
+
if (tag === "OPTION") return "option";
|
|
166
|
+
if (tag === "IMG") return el.getAttribute("alt") === "" ? "presentation" : "img";
|
|
167
|
+
if (tag === "DIALOG") return "dialog";
|
|
168
|
+
if (tag === "NAV") return "navigation";
|
|
169
|
+
if (tag === "MAIN") return "main";
|
|
170
|
+
if (tag === "HEADER") return "banner";
|
|
171
|
+
if (tag === "FOOTER") return "contentinfo";
|
|
172
|
+
if (tag === "ASIDE") return "complementary";
|
|
173
|
+
if (tag === "UL" || tag === "OL") return "list";
|
|
174
|
+
if (tag === "LI") return "listitem";
|
|
175
|
+
if (tag === "TABLE") return "table";
|
|
176
|
+
if (tag === "TR") return "row";
|
|
177
|
+
if (tag === "TD") return "cell";
|
|
178
|
+
if (tag === "TH") return "columnheader";
|
|
179
|
+
if (tag === "ARTICLE") return "article";
|
|
180
|
+
if (tag === "FORM") return "form";
|
|
181
|
+
if (tag === "PROGRESS") return "progressbar";
|
|
182
|
+
if (tag === "HR") return "separator";
|
|
183
|
+
if (tag === "SECTION") return (el.hasAttribute("aria-label") || el.hasAttribute("aria-labelledby")) ? "region" : "";
|
|
184
|
+
if (/^H[1-6]$/.test(tag)) return "heading";
|
|
185
|
+
if (tag === "INPUT") {
|
|
186
|
+
var t = (el.getAttribute("type") || "text").toLowerCase();
|
|
187
|
+
if (t === "button" || t === "submit" || t === "reset" || t === "image") return "button";
|
|
188
|
+
if (t === "checkbox") return "checkbox";
|
|
189
|
+
if (t === "radio") return "radio";
|
|
190
|
+
if (t === "search") return "searchbox";
|
|
191
|
+
if (t === "number") return "spinbutton";
|
|
192
|
+
if (t === "range") return "slider";
|
|
193
|
+
if (t === "hidden") return "";
|
|
194
|
+
return "textbox";
|
|
195
|
+
}
|
|
196
|
+
return "";
|
|
197
|
+
}
|
|
198
|
+
function getAccessibleName(el) {
|
|
199
|
+
if (!el) return "";
|
|
200
|
+
var doc = el.ownerDocument || document;
|
|
201
|
+
var labelledBy = el.getAttribute && el.getAttribute("aria-labelledby");
|
|
202
|
+
if (labelledBy) {
|
|
203
|
+
var parts = [];
|
|
204
|
+
var ids = labelledBy.trim().split(/\\s+/);
|
|
205
|
+
for (var i = 0; i < ids.length; i++) {
|
|
206
|
+
var ref = doc.getElementById ? doc.getElementById(ids[i]) : null;
|
|
207
|
+
if (ref) {
|
|
208
|
+
var rt = (ref.innerText || ref.textContent || "").trim();
|
|
209
|
+
if (rt) parts.push(rt);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
if (parts.length > 0) return parts.join(" ").replace(/\\s+/g, " ").trim();
|
|
213
|
+
}
|
|
214
|
+
var ariaLabel = el.getAttribute && el.getAttribute("aria-label");
|
|
215
|
+
if (ariaLabel && ariaLabel.trim()) return ariaLabel.trim();
|
|
216
|
+
var tag = el.tagName ? el.tagName.toUpperCase() : "";
|
|
217
|
+
if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") {
|
|
218
|
+
if (el.id && doc.querySelector) {
|
|
219
|
+
try {
|
|
220
|
+
var escId = typeof CSS !== "undefined" && CSS.escape ? CSS.escape(el.id) : el.id;
|
|
221
|
+
var forLbl = doc.querySelector('label[for="' + escId + '"]');
|
|
222
|
+
if (forLbl) {
|
|
223
|
+
var ft = (forLbl.innerText || forLbl.textContent || "").trim();
|
|
224
|
+
if (ft) return ft.replace(/\\s+/g, " ");
|
|
225
|
+
}
|
|
226
|
+
} catch (e) {}
|
|
227
|
+
}
|
|
228
|
+
if (el.closest) {
|
|
229
|
+
var wrapLbl = el.closest("label");
|
|
230
|
+
if (wrapLbl) {
|
|
231
|
+
var wt = (wrapLbl.innerText || wrapLbl.textContent || "").trim();
|
|
232
|
+
if (wt) return wt.replace(/\\s+/g, " ");
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
var itype = tag === "INPUT" ? (el.getAttribute("type") || "text").toLowerCase() : "";
|
|
236
|
+
if ((itype === "button" || itype === "submit" || itype === "reset") && el.value) {
|
|
237
|
+
return String(el.value).trim();
|
|
238
|
+
}
|
|
239
|
+
var ph = el.getAttribute && el.getAttribute("placeholder");
|
|
240
|
+
if (ph && ph.trim()) return ph.trim();
|
|
241
|
+
}
|
|
242
|
+
if (tag === "IMG") {
|
|
243
|
+
var alt = el.getAttribute && el.getAttribute("alt");
|
|
244
|
+
if (alt && alt.trim()) return alt.trim();
|
|
245
|
+
}
|
|
246
|
+
var title = el.getAttribute && el.getAttribute("title");
|
|
247
|
+
var txt = (el.innerText || el.textContent || "").replace(/\\s+/g, " ").trim();
|
|
248
|
+
if (txt) return txt;
|
|
249
|
+
return title ? title.trim() : "";
|
|
250
|
+
}
|
|
129
251
|
function collectRoots(root, offsetX, offsetY, inShadow, inIframe, out) {
|
|
130
252
|
if (!root) return;
|
|
131
253
|
out.push({ root: root, offsetX: offsetX, offsetY: offsetY, inShadow: inShadow, inIframe: inIframe });
|
|
254
|
+
if (root.shadowRoot) {
|
|
255
|
+
collectRoots(root.shadowRoot, offsetX, offsetY, true, inIframe, out);
|
|
256
|
+
}
|
|
132
257
|
var nodes = root.querySelectorAll ? root.querySelectorAll("*") : [];
|
|
133
258
|
for (var i = 0; i < nodes.length; i++) {
|
|
134
259
|
var el = nodes[i];
|
|
@@ -146,14 +271,16 @@ var SHARED_DOM_TRAVERSAL_HELPERS = `
|
|
|
146
271
|
}
|
|
147
272
|
}
|
|
148
273
|
}
|
|
149
|
-
function findTextInRoot(root, needle, ctx, pushHit) {
|
|
274
|
+
function findTextInRoot(root, needle, exact, ctx, pushHit) {
|
|
150
275
|
var doc = root.ownerDocument || (root.nodeType === 9 ? root : document);
|
|
151
276
|
if (doc && typeof doc.createTreeWalker === "function" && typeof NodeFilter !== "undefined") {
|
|
152
277
|
var walker = doc.createTreeWalker(root, NodeFilter.SHOW_TEXT);
|
|
153
278
|
var txtNode;
|
|
154
279
|
while ((txtNode = walker.nextNode())) {
|
|
155
|
-
var
|
|
156
|
-
|
|
280
|
+
var rawVal = (txtNode.nodeValue || "").trim();
|
|
281
|
+
var val = rawVal.toLowerCase();
|
|
282
|
+
var ok = exact ? rawVal === needle : (val && val.indexOf(needle.toLowerCase()) !== -1);
|
|
283
|
+
if (ok && txtNode.parentElement) {
|
|
157
284
|
pushHit(txtNode.parentElement, ctx);
|
|
158
285
|
}
|
|
159
286
|
}
|
|
@@ -161,8 +288,9 @@ var SHARED_DOM_TRAVERSAL_HELPERS = `
|
|
|
161
288
|
var inputs = root.querySelectorAll("input, button");
|
|
162
289
|
for (var ii = 0; ii < inputs.length; ii++) {
|
|
163
290
|
var inp = inputs[ii];
|
|
164
|
-
var
|
|
165
|
-
|
|
291
|
+
var rawInp = String(inp.value || "").trim();
|
|
292
|
+
var inpOk = exact ? rawInp === needle : (rawInp && rawInp.toLowerCase().indexOf(needle.toLowerCase()) !== -1);
|
|
293
|
+
if (inpOk) {
|
|
166
294
|
pushHit(inp, ctx);
|
|
167
295
|
}
|
|
168
296
|
}
|
|
@@ -176,14 +304,52 @@ var SHARED_DOM_TRAVERSAL_HELPERS = `
|
|
|
176
304
|
for (var c = 0; c < node.childNodes.length; c++) {
|
|
177
305
|
if (node.childNodes[c].nodeType === 3) directText += node.childNodes[c].textContent || "";
|
|
178
306
|
}
|
|
179
|
-
var trimmedDirect = directText.trim()
|
|
180
|
-
var inpVal = (node.tagName === "INPUT" || node.tagName === "BUTTON") ? String(node.value || "").
|
|
181
|
-
|
|
307
|
+
var trimmedDirect = directText.trim();
|
|
308
|
+
var inpVal = (node.tagName === "INPUT" || node.tagName === "BUTTON") ? String(node.value || "").trim() : "";
|
|
309
|
+
var directOk = exact ? trimmedDirect === needle : (trimmedDirect && trimmedDirect.toLowerCase().indexOf(needle.toLowerCase()) !== -1);
|
|
310
|
+
var inputOk = exact ? inpVal === needle : (inpVal && inpVal.toLowerCase().indexOf(needle.toLowerCase()) !== -1);
|
|
311
|
+
if (directOk || inputOk) {
|
|
182
312
|
pushHit(node, ctx);
|
|
183
313
|
}
|
|
184
314
|
}
|
|
185
315
|
}
|
|
186
|
-
function
|
|
316
|
+
function findRoleInRoot(root, roleLower, nameSpec, exact, ctx, pushHit) {
|
|
317
|
+
if (!root || !root.querySelectorAll) return;
|
|
318
|
+
var candidates = root.querySelectorAll("*");
|
|
319
|
+
for (var i = 0; i < candidates.length; i++) {
|
|
320
|
+
var el = candidates[i];
|
|
321
|
+
if (getImplicitRole(el) !== roleLower) continue;
|
|
322
|
+
if (nameSpec !== undefined && nameSpec !== null) {
|
|
323
|
+
var accName = getAccessibleName(el);
|
|
324
|
+
if (!matchSpec(accName, nameSpec, Boolean(exact))) continue;
|
|
325
|
+
}
|
|
326
|
+
pushHit(el, ctx);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
function applyModifiersAndSlice(hits, sel) {
|
|
330
|
+
if (!sel || typeof sel !== "object" || "point" in sel) return hits;
|
|
331
|
+
var filtered = hits;
|
|
332
|
+
if (sel.hasText !== undefined) {
|
|
333
|
+
filtered = filtered.filter(function(h) {
|
|
334
|
+
var txt = (h.el.innerText || h.el.textContent || h.el.value || getAccessibleName(h.el) || "");
|
|
335
|
+
return matchSpec(txt, sel.hasText, false);
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
if (sel.hasNotText !== undefined) {
|
|
339
|
+
filtered = filtered.filter(function(h) {
|
|
340
|
+
var txt = (h.el.innerText || h.el.textContent || h.el.value || getAccessibleName(h.el) || "");
|
|
341
|
+
return !matchSpec(txt, sel.hasNotText, false);
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
if (sel.first) return filtered.length > 0 ? [filtered[0]] : [];
|
|
345
|
+
if (sel.last) return filtered.length > 0 ? [filtered[filtered.length - 1]] : [];
|
|
346
|
+
if (typeof sel.nth === "number") {
|
|
347
|
+
var idx = sel.nth < 0 ? filtered.length + sel.nth : sel.nth;
|
|
348
|
+
return idx >= 0 && idx < filtered.length ? [filtered[idx]] : [];
|
|
349
|
+
}
|
|
350
|
+
return filtered;
|
|
351
|
+
}
|
|
352
|
+
function findInScope(sel, scopeRoot, baseOffsetX, baseOffsetY, baseInShadow, baseInIframe) {
|
|
187
353
|
var hits = [];
|
|
188
354
|
var seen = typeof Set !== "undefined" ? new Set() : null;
|
|
189
355
|
function pushHit(el, ctx) {
|
|
@@ -198,53 +364,123 @@ var SHARED_DOM_TRAVERSAL_HELPERS = `
|
|
|
198
364
|
if (atPt) pushHit(atPt, { offsetX: 0, offsetY: 0, inShadow: false, inIframe: false });
|
|
199
365
|
return hits;
|
|
200
366
|
}
|
|
367
|
+
// Frame scoping: find matching <iframe> first, then search inside its contentDocument
|
|
368
|
+
if (typeof sel === "object" && sel !== null && sel.frame) {
|
|
369
|
+
var frameHits = findInScope(sel.frame, scopeRoot, baseOffsetX, baseOffsetY, baseInShadow, baseInIframe);
|
|
370
|
+
var innerSel = Object.assign({}, sel);
|
|
371
|
+
delete innerSel.frame;
|
|
372
|
+
for (var fi = 0; fi < frameHits.length; fi++) {
|
|
373
|
+
var fEl = frameHits[fi].el;
|
|
374
|
+
if (fEl && fEl.tagName === "IFRAME") {
|
|
375
|
+
try {
|
|
376
|
+
var fDoc = fEl.contentDocument;
|
|
377
|
+
if (fDoc) {
|
|
378
|
+
var fRect = fEl.getBoundingClientRect();
|
|
379
|
+
var sub = findInScope(innerSel, fDoc, frameHits[fi].offsetX + fRect.left, frameHits[fi].offsetY + fRect.top, frameHits[fi].inShadow, true);
|
|
380
|
+
for (var si = 0; si < sub.length; si++) pushHit(sub[si].el, sub[si]);
|
|
381
|
+
}
|
|
382
|
+
} catch (e) {}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
return hits;
|
|
386
|
+
}
|
|
387
|
+
// Parent scoping: resolve 'within' first, then search inside each matched container
|
|
388
|
+
if (typeof sel === "object" && sel !== null && sel.within) {
|
|
389
|
+
var parentHits = findInScope(sel.within, scopeRoot, baseOffsetX, baseOffsetY, baseInShadow, baseInIframe);
|
|
390
|
+
var childSel = Object.assign({}, sel);
|
|
391
|
+
delete childSel.within;
|
|
392
|
+
delete childSel.hasText;
|
|
393
|
+
delete childSel.hasNotText;
|
|
394
|
+
delete childSel.first;
|
|
395
|
+
delete childSel.last;
|
|
396
|
+
delete childSel.nth;
|
|
397
|
+
var combined = [];
|
|
398
|
+
var cSeen = typeof Set !== "undefined" ? new Set() : null;
|
|
399
|
+
for (var pi = 0; pi < parentHits.length; pi++) {
|
|
400
|
+
var ph = parentHits[pi];
|
|
401
|
+
var subHits = findInScope(childSel, ph.el, ph.offsetX, ph.offsetY, ph.inShadow, ph.inIframe);
|
|
402
|
+
for (var ci = 0; ci < subHits.length; ci++) {
|
|
403
|
+
if (cSeen && cSeen.has(subHits[ci].el)) continue;
|
|
404
|
+
if (cSeen) cSeen.add(subHits[ci].el);
|
|
405
|
+
combined.push(subHits[ci]);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
return applyModifiersAndSlice(combined, sel);
|
|
409
|
+
}
|
|
410
|
+
|
|
201
411
|
var esc = function(v) {
|
|
202
412
|
return typeof CSS !== "undefined" && CSS.escape ? CSS.escape(v) : String(v).replace(/\\\\/g, "\\\\\\\\").replace(/"/g, '\\\\"');
|
|
203
413
|
};
|
|
204
|
-
var mainCtx = { root:
|
|
414
|
+
var mainCtx = { root: scopeRoot, offsetX: baseOffsetX, offsetY: baseOffsetY, inShadow: baseInShadow, inIframe: baseInIframe };
|
|
415
|
+
var hasModifiers = typeof sel === "object" && sel !== null && (sel.hasText !== undefined || sel.hasNotText !== undefined || sel.first || sel.last || typeof sel.nth === "number");
|
|
416
|
+
|
|
205
417
|
// O(1)-ish Light-DOM fast path: avoids scanning thousands of nodes with querySelectorAll("*")
|
|
206
|
-
//
|
|
207
|
-
if (
|
|
418
|
+
// unless Shadow DOM / iframe piercing is needed or no Light-DOM match exists.
|
|
419
|
+
if (scopeRoot && scopeRoot.querySelectorAll && !hasModifiers) {
|
|
208
420
|
if (typeof sel === "object" && sel !== null && "testID" in sel) {
|
|
209
421
|
var fastTid = esc(sel.testID);
|
|
210
|
-
var fastFound =
|
|
422
|
+
var fastFound = scopeRoot.querySelectorAll('[data-testid="' + fastTid + '"], [testID="' + fastTid + '"]');
|
|
211
423
|
if (fastFound.length > 0) {
|
|
212
|
-
for (var
|
|
424
|
+
for (var fi2 = 0; fi2 < fastFound.length; fi2++) pushHit(fastFound[fi2], mainCtx);
|
|
213
425
|
return hits;
|
|
214
426
|
}
|
|
427
|
+
} else if (typeof sel === "object" && sel !== null && "css" in sel) {
|
|
428
|
+
try {
|
|
429
|
+
var fastCss = scopeRoot.querySelectorAll(sel.css);
|
|
430
|
+
if (fastCss.length > 0) {
|
|
431
|
+
for (var fc = 0; fc < fastCss.length; fc++) pushHit(fastCss[fc], mainCtx);
|
|
432
|
+
return hits;
|
|
433
|
+
}
|
|
434
|
+
} catch (e) {}
|
|
215
435
|
} else if (typeof sel === "object" && sel !== null && "accessibilityLabel" in sel) {
|
|
216
436
|
var fastLbl = esc(sel.accessibilityLabel);
|
|
217
|
-
var fastFoundLbl =
|
|
437
|
+
var fastFoundLbl = scopeRoot.querySelectorAll('[aria-label="' + fastLbl + '"]');
|
|
218
438
|
if (fastFoundLbl.length > 0) {
|
|
219
439
|
for (var fj = 0; fj < fastFoundLbl.length; fj++) pushHit(fastFoundLbl[fj], mainCtx);
|
|
220
440
|
return hits;
|
|
221
441
|
}
|
|
442
|
+
} else if (typeof sel === "object" && sel !== null && "role" in sel) {
|
|
443
|
+
findRoleInRoot(scopeRoot, String(sel.role).toLowerCase(), sel.name, sel.exact, mainCtx, pushHit);
|
|
444
|
+
if (hits.length > 0) return hits;
|
|
222
445
|
} else if (typeof sel === "string" || (typeof sel === "object" && sel !== null && "text" in sel)) {
|
|
223
|
-
var fastNeedle =
|
|
224
|
-
|
|
446
|
+
var fastNeedle = typeof sel === "string" ? sel : sel.text;
|
|
447
|
+
var fastExact = typeof sel === "object" && sel !== null && Boolean(sel.exact);
|
|
448
|
+
findTextInRoot(scopeRoot, fastNeedle, fastExact, mainCtx, pushHit);
|
|
225
449
|
if (hits.length > 0) return hits;
|
|
226
450
|
}
|
|
227
451
|
}
|
|
452
|
+
|
|
228
453
|
var roots = [];
|
|
229
|
-
collectRoots(
|
|
230
|
-
for (var r =
|
|
454
|
+
collectRoots(scopeRoot, baseOffsetX, baseOffsetY, baseInShadow, baseInIframe, roots);
|
|
455
|
+
for (var r = 0; r < roots.length; r++) {
|
|
231
456
|
var ctx = roots[r];
|
|
232
457
|
var root = ctx.root;
|
|
233
|
-
if (!root.querySelectorAll) continue;
|
|
458
|
+
if (!root || !root.querySelectorAll) continue;
|
|
234
459
|
if (typeof sel === "object" && sel !== null && "testID" in sel) {
|
|
235
460
|
var tid = esc(sel.testID);
|
|
236
461
|
var found = root.querySelectorAll('[data-testid="' + tid + '"], [testID="' + tid + '"]');
|
|
237
462
|
for (var i = 0; i < found.length; i++) pushHit(found[i], ctx);
|
|
463
|
+
} else if (typeof sel === "object" && sel !== null && "css" in sel) {
|
|
464
|
+
try {
|
|
465
|
+
var foundCss = root.querySelectorAll(sel.css);
|
|
466
|
+
for (var ci2 = 0; ci2 < foundCss.length; ci2++) pushHit(foundCss[ci2], ctx);
|
|
467
|
+
} catch (e) {}
|
|
238
468
|
} else if (typeof sel === "object" && sel !== null && "accessibilityLabel" in sel) {
|
|
239
469
|
var lbl = esc(sel.accessibilityLabel);
|
|
240
470
|
var foundLbl = root.querySelectorAll('[aria-label="' + lbl + '"]');
|
|
241
471
|
for (var j = 0; j < foundLbl.length; j++) pushHit(foundLbl[j], ctx);
|
|
472
|
+
} else if (typeof sel === "object" && sel !== null && "role" in sel) {
|
|
473
|
+
findRoleInRoot(root, String(sel.role).toLowerCase(), sel.name, sel.exact, ctx, pushHit);
|
|
242
474
|
} else if (typeof sel === "string" || (typeof sel === "object" && sel !== null && "text" in sel)) {
|
|
243
|
-
var needle =
|
|
244
|
-
|
|
475
|
+
var needle = typeof sel === "string" ? sel : sel.text;
|
|
476
|
+
var isExact = typeof sel === "object" && sel !== null && Boolean(sel.exact);
|
|
477
|
+
findTextInRoot(root, needle, isExact, ctx, pushHit);
|
|
245
478
|
}
|
|
246
479
|
}
|
|
247
|
-
return hits;
|
|
480
|
+
return applyModifiersAndSlice(hits, sel);
|
|
481
|
+
}
|
|
482
|
+
function findAcrossRoots(sel) {
|
|
483
|
+
return findInScope(sel, document, 0, 0, false, false);
|
|
248
484
|
}
|
|
249
485
|
function isClickable(el) {
|
|
250
486
|
var tag = el.tagName;
|
|
@@ -339,6 +575,22 @@ var SHARED_DOM_TRAVERSAL_HELPERS = `
|
|
|
339
575
|
}
|
|
340
576
|
return false;
|
|
341
577
|
}
|
|
578
|
+
function hasActiveAnimation(el) {
|
|
579
|
+
var cur = el;
|
|
580
|
+
var depth = 0;
|
|
581
|
+
while (cur && depth++ < 8) {
|
|
582
|
+
if (typeof cur.getAnimations === "function") {
|
|
583
|
+
try {
|
|
584
|
+
var anims = cur.getAnimations();
|
|
585
|
+
for (var i = 0; i < anims.length; i++) {
|
|
586
|
+
if (anims[i] && anims[i].playState === "running") return true;
|
|
587
|
+
}
|
|
588
|
+
} catch (e) {}
|
|
589
|
+
}
|
|
590
|
+
cur = cur.parentElement;
|
|
591
|
+
}
|
|
592
|
+
return false;
|
|
593
|
+
}
|
|
342
594
|
function isVisible(el, rect) {
|
|
343
595
|
if (rect.width <= 0 || rect.height <= 0) return false;
|
|
344
596
|
var win = (el.ownerDocument && el.ownerDocument.defaultView) || window;
|
|
@@ -360,12 +612,16 @@ var SHARED_DOM_TRAVERSAL_HELPERS = `
|
|
|
360
612
|
? String(el.value ?? "")
|
|
361
613
|
: undefined;
|
|
362
614
|
var text = (el.innerText || el.textContent || "").trim() || undefined;
|
|
615
|
+
var accName = getAccessibleName(el) || undefined;
|
|
616
|
+
var role = getImplicitRole(el) || undefined;
|
|
363
617
|
return {
|
|
364
618
|
id: el.getAttribute("data-testid") || el.getAttribute("testID") || undefined,
|
|
365
619
|
tag: tag,
|
|
620
|
+
role: role,
|
|
366
621
|
text: text,
|
|
367
622
|
value: val,
|
|
368
623
|
accessibilityLabel: el.getAttribute("aria-label") || undefined,
|
|
624
|
+
accessibleName: accName,
|
|
369
625
|
rect: { x: rect.x + hit.offsetX, y: rect.y + hit.offsetY, width: rect.width, height: rect.height },
|
|
370
626
|
scrollX: window.scrollX || window.pageXOffset || 0,
|
|
371
627
|
scrollY: window.scrollY || window.pageYOffset || 0,
|
|
@@ -383,14 +639,14 @@ var SHARED_DOM_TRAVERSAL_HELPERS = `
|
|
|
383
639
|
}
|
|
384
640
|
`;
|
|
385
641
|
function buildDomQueryScript(selector) {
|
|
386
|
-
const serialized = JSON.stringify(selector);
|
|
642
|
+
const serialized = JSON.stringify(serializeSelectorForDom(selector));
|
|
387
643
|
return `(function(sel) {
|
|
388
644
|
${SHARED_DOM_TRAVERSAL_HELPERS}
|
|
389
645
|
return findAcrossRoots(sel).map(toMatch);
|
|
390
646
|
})(${serialized})`;
|
|
391
647
|
}
|
|
392
648
|
function buildDomScrollIntoViewScript(selector) {
|
|
393
|
-
const serialized = JSON.stringify(selector);
|
|
649
|
+
const serialized = JSON.stringify(serializeSelectorForDom(selector));
|
|
394
650
|
return `(function(sel) {
|
|
395
651
|
${SHARED_DOM_TRAVERSAL_HELPERS}
|
|
396
652
|
var hits = findAcrossRoots(sel);
|
|
@@ -404,7 +660,7 @@ function buildDomScrollIntoViewScript(selector) {
|
|
|
404
660
|
})(${serialized})`;
|
|
405
661
|
}
|
|
406
662
|
function buildDomTapScript(selector) {
|
|
407
|
-
const serialized = JSON.stringify(selector);
|
|
663
|
+
const serialized = JSON.stringify(serializeSelectorForDom(selector));
|
|
408
664
|
return `(function(sel) {
|
|
409
665
|
${SHARED_DOM_TRAVERSAL_HELPERS}
|
|
410
666
|
var hits = findAcrossRoots(sel);
|
|
@@ -429,18 +685,18 @@ function buildDomTapScript(selector) {
|
|
|
429
685
|
})(${serialized})`;
|
|
430
686
|
}
|
|
431
687
|
function buildDomWaitForSelectorScript(selector, opts = {}) {
|
|
432
|
-
const serialized = JSON.stringify(selector);
|
|
688
|
+
const serialized = JSON.stringify(serializeSelectorForDom(selector));
|
|
433
689
|
const timeoutMs = Math.max(10, Math.round(opts.timeoutMs ?? 5e3));
|
|
434
690
|
const forAction = Boolean(opts.forAction);
|
|
435
691
|
const failFastWhenIdle = Boolean(opts.failFastWhenIdle);
|
|
436
692
|
const idleQuietMs = Math.max(50, Math.round(opts.idleQuietMs ?? 250));
|
|
437
|
-
const stableFrames = opts.stableFrames !== void 0 ? Math.max(0, Math.round(opts.stableFrames)) : forAction ? 1 : 0;
|
|
693
|
+
const stableFrames = opts.stableFrames !== void 0 ? Math.max(0, Math.round(opts.stableFrames)) : forAction ? -1 : 0;
|
|
438
694
|
const checkHitTest = opts.checkHitTest !== void 0 ? Boolean(opts.checkHitTest) : forAction;
|
|
439
695
|
const waitForAppReady = opts.waitForAppReady !== void 0 ? Boolean(opts.waitForAppReady) : true;
|
|
440
696
|
return `(function(sel, timeoutMs, forAction, failFastWhenIdle, idleQuietMs, reqStableFrames, checkHitTest, waitForAppReady) {
|
|
441
697
|
${SHARED_DOM_TRAVERSAL_HELPERS}
|
|
442
698
|
var instantAnim = Boolean(typeof document !== "undefined" && document.getElementById && document.getElementById("__spana_instant_anim"));
|
|
443
|
-
var
|
|
699
|
+
var explicitStableFrames = instantAnim ? 0 : reqStableFrames;
|
|
444
700
|
|
|
445
701
|
function findCandidates() {
|
|
446
702
|
if (waitForAppReady && !isAppReady()) return null;
|
|
@@ -461,20 +717,28 @@ function buildDomWaitForSelectorScript(selector, opts = {}) {
|
|
|
461
717
|
if (!ready) return null;
|
|
462
718
|
if (!forAction) return ready.map(function(r) { return r.match; });
|
|
463
719
|
var target = ready[ready.length - 1];
|
|
464
|
-
ensureInViewport(target.hit);
|
|
720
|
+
var didScroll = ensureInViewport(target.hit);
|
|
465
721
|
if (checkHitTest && !isHitTestClear(target.hit)) return null;
|
|
466
722
|
var updated = toMatch(target.hit);
|
|
467
723
|
if (!updated.visible || !updated.enabled) return null;
|
|
468
|
-
return { hits: ready, target: target, match: updated };
|
|
724
|
+
return { hits: ready, target: target, match: updated, didScroll: didScroll };
|
|
469
725
|
}
|
|
470
726
|
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
727
|
+
function neededStableFrames(candidate) {
|
|
728
|
+
if (!forAction || typeof requestAnimationFrame !== "function") return 0;
|
|
729
|
+
if (explicitStableFrames >= 0) return explicitStableFrames;
|
|
730
|
+
// Smart auto stability: 0 rAF wait on static, unobstructed elements;
|
|
731
|
+
// wait 2 frames if CSS animations/transitions are running or 1 frame right after scroll.
|
|
732
|
+
if (hasActiveAnimation(candidate.target.hit.el)) return 2;
|
|
733
|
+
if (candidate.didScroll) return 1;
|
|
734
|
+
return 0;
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
// Fast synchronous exit when target is already actionable and needs 0 stability frames
|
|
738
|
+
var imm = checkActionableNow();
|
|
739
|
+
if (imm) {
|
|
740
|
+
if (!forAction) return imm;
|
|
741
|
+
if (neededStableFrames(imm) <= 0) return [imm.match];
|
|
478
742
|
}
|
|
479
743
|
|
|
480
744
|
return new Promise(function(resolve) {
|
|
@@ -518,14 +782,15 @@ function buildDomWaitForSelectorScript(selector, opts = {}) {
|
|
|
518
782
|
|
|
519
783
|
function verifyStability(candidate) {
|
|
520
784
|
if (done || checkingStability) return;
|
|
521
|
-
|
|
785
|
+
var framesToWait = neededStableFrames(candidate);
|
|
786
|
+
if (!forAction || framesToWait <= 0 || typeof requestAnimationFrame !== "function") {
|
|
522
787
|
finish(forAction ? [candidate.match] : candidate);
|
|
523
788
|
return;
|
|
524
789
|
}
|
|
525
790
|
checkingStability = true;
|
|
526
791
|
var el = candidate.target.hit.el;
|
|
527
792
|
var lastRect = candidate.match.rect;
|
|
528
|
-
var remainingFrames =
|
|
793
|
+
var remainingFrames = framesToWait;
|
|
529
794
|
|
|
530
795
|
function step() {
|
|
531
796
|
if (done) return;
|
|
@@ -553,7 +818,7 @@ function buildDomWaitForSelectorScript(selector, opts = {}) {
|
|
|
553
818
|
return;
|
|
554
819
|
}
|
|
555
820
|
} else {
|
|
556
|
-
remainingFrames =
|
|
821
|
+
remainingFrames = framesToWait;
|
|
557
822
|
lastRect = cur.rect;
|
|
558
823
|
}
|
|
559
824
|
rafId = requestAnimationFrame(step);
|
|
@@ -610,7 +875,7 @@ function buildDomWaitForSelectorScript(selector, opts = {}) {
|
|
|
610
875
|
})(${serialized}, ${timeoutMs}, ${forAction}, ${failFastWhenIdle}, ${idleQuietMs}, ${stableFrames}, ${checkHitTest}, ${waitForAppReady})`;
|
|
611
876
|
}
|
|
612
877
|
function buildDomWaitForHiddenScript(selector, opts = {}) {
|
|
613
|
-
const serialized = JSON.stringify(selector);
|
|
878
|
+
const serialized = JSON.stringify(serializeSelectorForDom(selector));
|
|
614
879
|
const timeoutMs = Math.max(10, Math.round(opts.timeoutMs ?? 5e3));
|
|
615
880
|
return `(function(sel, timeoutMs) {
|
|
616
881
|
${SHARED_DOM_TRAVERSAL_HELPERS}
|
|
@@ -664,24 +929,54 @@ function buildDomWaitForHiddenScript(selector, opts = {}) {
|
|
|
664
929
|
})(${serialized}, ${timeoutMs})`;
|
|
665
930
|
}
|
|
666
931
|
function buildDomWaitForMatchScript(selector, opts) {
|
|
667
|
-
const serialized = JSON.stringify(selector);
|
|
932
|
+
const serialized = JSON.stringify(serializeSelectorForDom(selector));
|
|
668
933
|
const timeoutMs = Math.max(10, Math.round(opts.timeoutMs ?? 5e3));
|
|
669
934
|
const kind = JSON.stringify(opts.kind);
|
|
670
935
|
const expected = JSON.stringify(opts.expected ?? null);
|
|
936
|
+
const expectedCount = JSON.stringify(opts.expectedCount ?? null);
|
|
671
937
|
const attributeName = JSON.stringify(opts.attributeName ?? null);
|
|
672
938
|
const patternSource = JSON.stringify(opts.patternSource ?? null);
|
|
673
939
|
const patternFlags = JSON.stringify(opts.patternFlags ?? "");
|
|
674
|
-
return `(function(sel, timeoutMs, kind, expected, attributeName, patternSource, patternFlags) {
|
|
940
|
+
return `(function(sel, timeoutMs, kind, expected, expectedCount, attributeName, patternSource, patternFlags) {
|
|
675
941
|
${SHARED_DOM_TRAVERSAL_HELPERS}
|
|
676
942
|
var lastActual = undefined;
|
|
677
943
|
var regex = patternSource !== null ? new RegExp(patternSource, patternFlags) : null;
|
|
678
944
|
|
|
679
945
|
function evaluateMatch() {
|
|
946
|
+
if (kind === "url") {
|
|
947
|
+
var href = String(window.location.href || "");
|
|
948
|
+
lastActual = href;
|
|
949
|
+
if (regex) {
|
|
950
|
+
if (regex.test(href)) return { matched: true, actual: href };
|
|
951
|
+
} else if (expected !== null && (href === expected || href.indexOf(String(expected)) !== -1)) {
|
|
952
|
+
return { matched: true, actual: href };
|
|
953
|
+
}
|
|
954
|
+
return null;
|
|
955
|
+
}
|
|
680
956
|
var hits = findAcrossRoots(sel);
|
|
957
|
+
if (kind === "count") {
|
|
958
|
+
var visibleCount = 0;
|
|
959
|
+
for (var ci = 0; ci < hits.length; ci++) {
|
|
960
|
+
if (toMatch(hits[ci]).visible) visibleCount += 1;
|
|
961
|
+
}
|
|
962
|
+
lastActual = String(visibleCount);
|
|
963
|
+
if (visibleCount === expectedCount) return { matched: true, actual: String(visibleCount) };
|
|
964
|
+
return null;
|
|
965
|
+
}
|
|
681
966
|
for (var i = hits.length - 1; i >= 0; i--) {
|
|
682
967
|
var m = toMatch(hits[i]);
|
|
683
968
|
if (!m.visible) continue;
|
|
684
|
-
if (kind === "
|
|
969
|
+
if (kind === "focused") {
|
|
970
|
+
var isFoc = Boolean(m.focused);
|
|
971
|
+
lastActual = isFoc ? "focused" : "not focused";
|
|
972
|
+
if (isFoc) return { matched: true, actual: "focused" };
|
|
973
|
+
} else if (kind === "accessibleName") {
|
|
974
|
+
var acc = m.accessibleName || "";
|
|
975
|
+
lastActual = acc;
|
|
976
|
+
if (regex ? regex.test(acc) : (expected === null ? acc.length > 0 : acc === expected)) {
|
|
977
|
+
return { matched: true, actual: acc };
|
|
978
|
+
}
|
|
979
|
+
} else if (kind === "text") {
|
|
685
980
|
lastActual = m.text;
|
|
686
981
|
if (m.text === expected) return { matched: true, actual: m.text };
|
|
687
982
|
} else if (kind === "containsText") {
|
|
@@ -736,6 +1031,11 @@ function buildDomWaitForMatchScript(selector, opts) {
|
|
|
736
1031
|
if (typeof document !== "undefined") {
|
|
737
1032
|
document.removeEventListener("input", onChange, true);
|
|
738
1033
|
document.removeEventListener("change", onChange, true);
|
|
1034
|
+
document.removeEventListener("focusin", onChange, true);
|
|
1035
|
+
}
|
|
1036
|
+
if (typeof window !== "undefined") {
|
|
1037
|
+
window.removeEventListener("popstate", onChange);
|
|
1038
|
+
window.removeEventListener("hashchange", onChange);
|
|
739
1039
|
}
|
|
740
1040
|
resolve(res);
|
|
741
1041
|
}
|
|
@@ -756,11 +1056,16 @@ function buildDomWaitForMatchScript(selector, opts) {
|
|
|
756
1056
|
finish(finalRes || { matched: false, actual: lastActual });
|
|
757
1057
|
}, timeoutMs);
|
|
758
1058
|
|
|
759
|
-
fallbackInterval = setInterval(onChange,
|
|
1059
|
+
fallbackInterval = setInterval(onChange, kind === "url" ? 50 : 100);
|
|
760
1060
|
|
|
761
1061
|
if (typeof document !== "undefined") {
|
|
762
1062
|
document.addEventListener("input", onChange, true);
|
|
763
1063
|
document.addEventListener("change", onChange, true);
|
|
1064
|
+
document.addEventListener("focusin", onChange, true);
|
|
1065
|
+
}
|
|
1066
|
+
if (typeof window !== "undefined") {
|
|
1067
|
+
window.addEventListener("popstate", onChange);
|
|
1068
|
+
window.addEventListener("hashchange", onChange);
|
|
764
1069
|
}
|
|
765
1070
|
|
|
766
1071
|
if (typeof MutationObserver !== "undefined") {
|
|
@@ -776,18 +1081,21 @@ function buildDomWaitForMatchScript(selector, opts) {
|
|
|
776
1081
|
}
|
|
777
1082
|
}
|
|
778
1083
|
});
|
|
779
|
-
})(${serialized}, ${timeoutMs}, ${kind}, ${expected}, ${attributeName}, ${patternSource}, ${patternFlags})`;
|
|
1084
|
+
})(${serialized}, ${timeoutMs}, ${kind}, ${expected}, ${expectedCount}, ${attributeName}, ${patternSource}, ${patternFlags})`;
|
|
780
1085
|
}
|
|
781
1086
|
function buildDomFillScript(selector, value, opts = {}) {
|
|
782
|
-
const serializedSel = JSON.stringify(selector);
|
|
1087
|
+
const serializedSel = JSON.stringify(serializeSelectorForDom(selector));
|
|
783
1088
|
const serializedVal = JSON.stringify(value);
|
|
784
1089
|
const timeoutMs = Math.max(10, Math.round(opts.timeoutMs ?? 5e3));
|
|
785
1090
|
const checkHitTest = opts.checkHitTest !== void 0 ? Boolean(opts.checkHitTest) : true;
|
|
786
1091
|
return `(function(sel, val, timeoutMs, checkHitTest) {
|
|
787
1092
|
${SHARED_DOM_TRAVERSAL_HELPERS}
|
|
788
|
-
function
|
|
1093
|
+
function writeValue(el) {
|
|
789
1094
|
if (typeof el.focus === "function") { try { el.focus(); } catch (e) {} }
|
|
790
1095
|
var tag = el.tagName;
|
|
1096
|
+
// Rich-text contenteditable editors (TipTap/ProseMirror/Lexical/Slate) require native keyboard input;
|
|
1097
|
+
// return false so coordinator falls back cleanly to real tap + SelectAll + Input.insertText.
|
|
1098
|
+
if (el.isContentEditable) return false;
|
|
791
1099
|
if (tag === "INPUT" || tag === "TEXTAREA") {
|
|
792
1100
|
var proto = tag === "TEXTAREA"
|
|
793
1101
|
? (window.HTMLTextAreaElement && window.HTMLTextAreaElement.prototype)
|
|
@@ -798,10 +1106,12 @@ function buildDomFillScript(selector, value, opts = {}) {
|
|
|
798
1106
|
} else {
|
|
799
1107
|
el.value = val;
|
|
800
1108
|
}
|
|
1109
|
+
// Reset React's internal _valueTracker so synthetic controlled onChange always fires
|
|
1110
|
+
if (el._valueTracker && typeof el._valueTracker.setValue === "function") {
|
|
1111
|
+
try { el._valueTracker.setValue(val === "" ? " " : ""); } catch (e) {}
|
|
1112
|
+
}
|
|
801
1113
|
} else if (tag === "SELECT") {
|
|
802
1114
|
el.value = val;
|
|
803
|
-
} else if (el.isContentEditable) {
|
|
804
|
-
el.textContent = val;
|
|
805
1115
|
} else {
|
|
806
1116
|
el.value = val;
|
|
807
1117
|
}
|
|
@@ -811,8 +1121,8 @@ function buildDomFillScript(selector, value, opts = {}) {
|
|
|
811
1121
|
return true;
|
|
812
1122
|
}
|
|
813
1123
|
|
|
814
|
-
function
|
|
815
|
-
if (!isAppReady()) return
|
|
1124
|
+
function findEditableNow() {
|
|
1125
|
+
if (!isAppReady()) return null;
|
|
816
1126
|
var hits = findAcrossRoots(sel);
|
|
817
1127
|
for (var i = hits.length - 1; i >= 0; i--) {
|
|
818
1128
|
var h = hits[i];
|
|
@@ -820,12 +1130,38 @@ function buildDomFillScript(selector, value, opts = {}) {
|
|
|
820
1130
|
if (!m.visible || !m.enabled) continue;
|
|
821
1131
|
ensureInViewport(h);
|
|
822
1132
|
if (checkHitTest && !isHitTestClear(h)) continue;
|
|
823
|
-
return
|
|
1133
|
+
return h.el;
|
|
824
1134
|
}
|
|
825
|
-
return
|
|
1135
|
+
return null;
|
|
826
1136
|
}
|
|
827
1137
|
|
|
828
|
-
|
|
1138
|
+
function verifyAndRetryFill(attemptsLeft) {
|
|
1139
|
+
var el = findEditableNow();
|
|
1140
|
+
if (!el) return Promise.resolve(false);
|
|
1141
|
+
if (el.isContentEditable) return Promise.resolve(false);
|
|
1142
|
+
if (!writeValue(el)) return Promise.resolve(false);
|
|
1143
|
+
return new Promise(function(resolve) {
|
|
1144
|
+
// Let React/Vue microtask + single paint flush settle, then verify value survived remount/re-render
|
|
1145
|
+
setTimeout(function() {
|
|
1146
|
+
var latest = findEditableNow() || el;
|
|
1147
|
+
if (latest && latest.isConnected && String(latest.value == null ? "" : latest.value) === val) {
|
|
1148
|
+
resolve(true);
|
|
1149
|
+
return;
|
|
1150
|
+
}
|
|
1151
|
+
if (attemptsLeft > 1) {
|
|
1152
|
+
verifyAndRetryFill(attemptsLeft - 1).then(resolve);
|
|
1153
|
+
} else {
|
|
1154
|
+
resolve(false);
|
|
1155
|
+
}
|
|
1156
|
+
}, 12);
|
|
1157
|
+
});
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
var immEl = findEditableNow();
|
|
1161
|
+
if (immEl) {
|
|
1162
|
+
if (immEl.isContentEditable) return false;
|
|
1163
|
+
return verifyAndRetryFill(3);
|
|
1164
|
+
}
|
|
829
1165
|
|
|
830
1166
|
return new Promise(function(resolve) {
|
|
831
1167
|
var done = false;
|
|
@@ -833,6 +1169,7 @@ function buildDomFillScript(selector, value, opts = {}) {
|
|
|
833
1169
|
var timeoutTimer = null;
|
|
834
1170
|
var fallbackInterval = null;
|
|
835
1171
|
var scheduled = false;
|
|
1172
|
+
var filling = false;
|
|
836
1173
|
|
|
837
1174
|
function finish(ok) {
|
|
838
1175
|
if (done) return;
|
|
@@ -844,16 +1181,25 @@ function buildDomFillScript(selector, value, opts = {}) {
|
|
|
844
1181
|
}
|
|
845
1182
|
|
|
846
1183
|
function onChange() {
|
|
847
|
-
if (done || scheduled) return;
|
|
1184
|
+
if (done || scheduled || filling) return;
|
|
848
1185
|
scheduled = true;
|
|
849
1186
|
Promise.resolve().then(function() {
|
|
850
1187
|
scheduled = false;
|
|
851
|
-
if (
|
|
1188
|
+
if (done || filling) return;
|
|
1189
|
+
var target = findEditableNow();
|
|
1190
|
+
if (!target) return;
|
|
1191
|
+
if (target.isContentEditable) { finish(false); return; }
|
|
1192
|
+
filling = true;
|
|
1193
|
+
verifyAndRetryFill(3).then(function(ok) { finish(ok); });
|
|
852
1194
|
});
|
|
853
1195
|
}
|
|
854
1196
|
|
|
855
1197
|
timeoutTimer = setTimeout(function() {
|
|
856
|
-
|
|
1198
|
+
if (filling) return;
|
|
1199
|
+
var target = findEditableNow();
|
|
1200
|
+
if (!target || target.isContentEditable) { finish(false); return; }
|
|
1201
|
+
filling = true;
|
|
1202
|
+
verifyAndRetryFill(2).then(function(ok) { finish(ok); });
|
|
857
1203
|
}, timeoutMs);
|
|
858
1204
|
|
|
859
1205
|
fallbackInterval = setInterval(onChange, 40);
|
|
@@ -873,6 +1219,526 @@ function buildDomFillScript(selector, value, opts = {}) {
|
|
|
873
1219
|
});
|
|
874
1220
|
})(${serializedSel}, ${serializedVal}, ${timeoutMs}, ${checkHitTest})`;
|
|
875
1221
|
}
|
|
1222
|
+
var SPANA_RUNTIME_MISSING_SENTINEL = "__SPANA_RT_MISSING__";
|
|
1223
|
+
var SPANA_INJECTED_RUNTIME_SCRIPT = `(function() {
|
|
1224
|
+
if (typeof window === "undefined" || window.__spanaRt) return true;
|
|
1225
|
+
${SHARED_DOM_TRAVERSAL_HELPERS}
|
|
1226
|
+
|
|
1227
|
+
function query(sel) {
|
|
1228
|
+
return findAcrossRoots(sel).map(toMatch);
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
function scrollIntoView(sel) {
|
|
1232
|
+
var hits = findAcrossRoots(sel);
|
|
1233
|
+
if (hits.length === 0) return null;
|
|
1234
|
+
var hit = hits[hits.length - 1];
|
|
1235
|
+
if (typeof hit.el.scrollIntoView === "function") {
|
|
1236
|
+
try { hit.el.scrollIntoView({ block: "center", inline: "center", behavior: "instant" }); }
|
|
1237
|
+
catch (e) { try { hit.el.scrollIntoView(true); } catch (e2) {} }
|
|
1238
|
+
}
|
|
1239
|
+
return toMatch(hit);
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1242
|
+
function tap(sel) {
|
|
1243
|
+
var hits = findAcrossRoots(sel);
|
|
1244
|
+
if (hits.length === 0) return false;
|
|
1245
|
+
var hit = hits[hits.length - 1];
|
|
1246
|
+
var el = hit.el;
|
|
1247
|
+
if (typeof el.scrollIntoView === "function") {
|
|
1248
|
+
try { el.scrollIntoView({ block: "center", inline: "center", behavior: "instant" }); } catch (e) {}
|
|
1249
|
+
}
|
|
1250
|
+
var rect = el.getBoundingClientRect();
|
|
1251
|
+
var cx = rect.left + rect.width / 2;
|
|
1252
|
+
var cy = rect.top + rect.height / 2;
|
|
1253
|
+
var init = { bubbles: true, cancelable: true, composed: true, clientX: cx, clientY: cy };
|
|
1254
|
+
try { el.dispatchEvent(new PointerEvent("pointerdown", init)); } catch (e) {}
|
|
1255
|
+
try { el.dispatchEvent(new MouseEvent("mousedown", init)); } catch (e) {}
|
|
1256
|
+
if (typeof el.focus === "function") { try { el.focus(); } catch (e) {} }
|
|
1257
|
+
try { el.dispatchEvent(new PointerEvent("pointerup", init)); } catch (e) {}
|
|
1258
|
+
try { el.dispatchEvent(new MouseEvent("mouseup", init)); } catch (e) {}
|
|
1259
|
+
if (typeof el.click === "function") { el.click(); }
|
|
1260
|
+
else { el.dispatchEvent(new MouseEvent("click", init)); }
|
|
1261
|
+
return true;
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
function waitForSelector(sel, opts) {
|
|
1265
|
+
opts = opts || {};
|
|
1266
|
+
var timeoutMs = Math.max(10, Math.round(opts.timeoutMs != null ? opts.timeoutMs : 5000));
|
|
1267
|
+
var forAction = Boolean(opts.forAction);
|
|
1268
|
+
var failFastWhenIdle = Boolean(opts.failFastWhenIdle);
|
|
1269
|
+
var idleQuietMs = Math.max(50, Math.round(opts.idleQuietMs != null ? opts.idleQuietMs : 250));
|
|
1270
|
+
var reqStableFrames = opts.stableFrames !== undefined ? Math.max(0, Math.round(opts.stableFrames)) : (forAction ? -1 : 0);
|
|
1271
|
+
var checkHitTest = opts.checkHitTest !== undefined ? Boolean(opts.checkHitTest) : forAction;
|
|
1272
|
+
var waitForAppReady = opts.waitForAppReady !== undefined ? Boolean(opts.waitForAppReady) : true;
|
|
1273
|
+
var instantAnim = Boolean(typeof document !== "undefined" && document.getElementById && document.getElementById("__spana_instant_anim"));
|
|
1274
|
+
var explicitStableFrames = instantAnim ? 0 : reqStableFrames;
|
|
1275
|
+
|
|
1276
|
+
function findCandidates() {
|
|
1277
|
+
if (waitForAppReady && !isAppReady()) return null;
|
|
1278
|
+
var rawHits = findAcrossRoots(sel);
|
|
1279
|
+
var ready = [];
|
|
1280
|
+
for (var i = 0; i < rawHits.length; i++) {
|
|
1281
|
+
var h = rawHits[i];
|
|
1282
|
+
var m = toMatch(h);
|
|
1283
|
+
if (!m.visible) continue;
|
|
1284
|
+
if (forAction && !m.enabled) continue;
|
|
1285
|
+
ready.push({ hit: h, match: m });
|
|
1286
|
+
}
|
|
1287
|
+
return ready.length > 0 ? ready : null;
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
function checkActionableNow() {
|
|
1291
|
+
var ready = findCandidates();
|
|
1292
|
+
if (!ready) return null;
|
|
1293
|
+
if (!forAction) return ready.map(function(r) { return r.match; });
|
|
1294
|
+
var target = ready[ready.length - 1];
|
|
1295
|
+
var didScroll = ensureInViewport(target.hit);
|
|
1296
|
+
if (checkHitTest && !isHitTestClear(target.hit)) return null;
|
|
1297
|
+
var updated = toMatch(target.hit);
|
|
1298
|
+
if (!updated.visible || !updated.enabled) return null;
|
|
1299
|
+
return { hits: ready, target: target, match: updated, didScroll: didScroll };
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
function neededStableFrames(candidate) {
|
|
1303
|
+
if (!forAction || typeof requestAnimationFrame !== "function") return 0;
|
|
1304
|
+
if (explicitStableFrames >= 0) return explicitStableFrames;
|
|
1305
|
+
if (hasActiveAnimation(candidate.target.hit.el)) return 2;
|
|
1306
|
+
if (candidate.didScroll) return 1;
|
|
1307
|
+
return 0;
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1310
|
+
var imm = checkActionableNow();
|
|
1311
|
+
if (imm) {
|
|
1312
|
+
if (!forAction) return imm;
|
|
1313
|
+
if (neededStableFrames(imm) <= 0) return [imm.match];
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1316
|
+
return new Promise(function(resolve) {
|
|
1317
|
+
var done = false;
|
|
1318
|
+
var observer = null;
|
|
1319
|
+
var timeoutTimer = null;
|
|
1320
|
+
var fallbackInterval = null;
|
|
1321
|
+
var idleTimer = null;
|
|
1322
|
+
var rafId = null;
|
|
1323
|
+
var checkingStability = false;
|
|
1324
|
+
|
|
1325
|
+
function finish(result) {
|
|
1326
|
+
if (done) return;
|
|
1327
|
+
done = true;
|
|
1328
|
+
if (observer) { try { observer.disconnect(); } catch (e) {} }
|
|
1329
|
+
if (timeoutTimer) clearTimeout(timeoutTimer);
|
|
1330
|
+
if (fallbackInterval) clearInterval(fallbackInterval);
|
|
1331
|
+
if (idleTimer) clearTimeout(idleTimer);
|
|
1332
|
+
if (rafId !== null && typeof cancelAnimationFrame === "function") {
|
|
1333
|
+
try { cancelAnimationFrame(rafId); } catch (e) {}
|
|
1334
|
+
}
|
|
1335
|
+
resolve(result);
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1338
|
+
function armIdleTimer() {
|
|
1339
|
+
if (!failFastWhenIdle) return;
|
|
1340
|
+
if (idleTimer) clearTimeout(idleTimer);
|
|
1341
|
+
idleTimer = setTimeout(function() {
|
|
1342
|
+
if (document.readyState === "complete" && (!waitForAppReady || isAppReady())) {
|
|
1343
|
+
var hit = checkActionableNow();
|
|
1344
|
+
finish(hit ? (forAction ? [hit.match] : hit) : []);
|
|
1345
|
+
} else {
|
|
1346
|
+
armIdleTimer();
|
|
1347
|
+
}
|
|
1348
|
+
}, idleQuietMs);
|
|
1349
|
+
}
|
|
1350
|
+
|
|
1351
|
+
function verifyStability(candidate) {
|
|
1352
|
+
if (done || checkingStability) return;
|
|
1353
|
+
var framesToWait = neededStableFrames(candidate);
|
|
1354
|
+
if (!forAction || framesToWait <= 0 || typeof requestAnimationFrame !== "function") {
|
|
1355
|
+
finish(forAction ? [candidate.match] : candidate);
|
|
1356
|
+
return;
|
|
1357
|
+
}
|
|
1358
|
+
checkingStability = true;
|
|
1359
|
+
var el = candidate.target.hit.el;
|
|
1360
|
+
var lastRect = candidate.match.rect;
|
|
1361
|
+
var remainingFrames = framesToWait;
|
|
1362
|
+
|
|
1363
|
+
function step() {
|
|
1364
|
+
if (done) return;
|
|
1365
|
+
if (!el.isConnected) { checkingStability = false; return; }
|
|
1366
|
+
if (checkHitTest && !isHitTestClear(candidate.target.hit)) { checkingStability = false; return; }
|
|
1367
|
+
var cur = toMatch(candidate.target.hit);
|
|
1368
|
+
if (!cur.visible || !cur.enabled) { checkingStability = false; return; }
|
|
1369
|
+
var dx = Math.abs(cur.rect.x - lastRect.x);
|
|
1370
|
+
var dy = Math.abs(cur.rect.y - lastRect.y);
|
|
1371
|
+
var dw = Math.abs(cur.rect.width - lastRect.width);
|
|
1372
|
+
var dh = Math.abs(cur.rect.height - lastRect.height);
|
|
1373
|
+
if (dx <= 1 && dy <= 1 && dw <= 1 && dh <= 1) {
|
|
1374
|
+
remainingFrames -= 1;
|
|
1375
|
+
if (remainingFrames <= 0) { finish([cur]); return; }
|
|
1376
|
+
} else {
|
|
1377
|
+
remainingFrames = framesToWait;
|
|
1378
|
+
lastRect = cur.rect;
|
|
1379
|
+
}
|
|
1380
|
+
rafId = requestAnimationFrame(step);
|
|
1381
|
+
}
|
|
1382
|
+
rafId = requestAnimationFrame(step);
|
|
1383
|
+
}
|
|
1384
|
+
|
|
1385
|
+
function attempt() {
|
|
1386
|
+
if (done || checkingStability) return;
|
|
1387
|
+
var hit = checkActionableNow();
|
|
1388
|
+
if (hit) {
|
|
1389
|
+
if (forAction) verifyStability(hit);
|
|
1390
|
+
else finish(hit);
|
|
1391
|
+
return;
|
|
1392
|
+
}
|
|
1393
|
+
armIdleTimer();
|
|
1394
|
+
}
|
|
1395
|
+
|
|
1396
|
+
var scheduled = false;
|
|
1397
|
+
function scheduleAttempt() {
|
|
1398
|
+
if (done || scheduled || checkingStability) return;
|
|
1399
|
+
scheduled = true;
|
|
1400
|
+
Promise.resolve().then(function() { scheduled = false; attempt(); });
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1403
|
+
timeoutTimer = setTimeout(function() {
|
|
1404
|
+
var finalHit = checkActionableNow();
|
|
1405
|
+
finish(finalHit ? (forAction ? [finalHit.match] : finalHit) : []);
|
|
1406
|
+
}, timeoutMs);
|
|
1407
|
+
fallbackInterval = setInterval(attempt, forAction ? 40 : 120);
|
|
1408
|
+
if (typeof MutationObserver !== "undefined") {
|
|
1409
|
+
var root = document.documentElement || document.body || document;
|
|
1410
|
+
if (root) {
|
|
1411
|
+
observer = new MutationObserver(scheduleAttempt);
|
|
1412
|
+
observer.observe(root, { childList: true, subtree: true, attributes: true, characterData: true });
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
attempt();
|
|
1416
|
+
});
|
|
1417
|
+
}
|
|
1418
|
+
|
|
1419
|
+
function waitForHidden(sel, opts) {
|
|
1420
|
+
opts = opts || {};
|
|
1421
|
+
var timeoutMs = Math.max(10, Math.round(opts.timeoutMs != null ? opts.timeoutMs : 5000));
|
|
1422
|
+
function isHiddenNow() {
|
|
1423
|
+
var hits = findAcrossRoots(sel);
|
|
1424
|
+
for (var i = 0; i < hits.length; i++) {
|
|
1425
|
+
if (toMatch(hits[i]).visible) return false;
|
|
1426
|
+
}
|
|
1427
|
+
return true;
|
|
1428
|
+
}
|
|
1429
|
+
if (isHiddenNow()) return true;
|
|
1430
|
+
return new Promise(function(resolve) {
|
|
1431
|
+
var done = false;
|
|
1432
|
+
var observer = null;
|
|
1433
|
+
var timeoutTimer = null;
|
|
1434
|
+
var fallbackInterval = null;
|
|
1435
|
+
function finish(val) {
|
|
1436
|
+
if (done) return;
|
|
1437
|
+
done = true;
|
|
1438
|
+
if (observer) { try { observer.disconnect(); } catch (e) {} }
|
|
1439
|
+
if (timeoutTimer) clearTimeout(timeoutTimer);
|
|
1440
|
+
if (fallbackInterval) clearInterval(fallbackInterval);
|
|
1441
|
+
resolve(val);
|
|
1442
|
+
}
|
|
1443
|
+
function onChange() { if (isHiddenNow()) finish(true); }
|
|
1444
|
+
timeoutTimer = setTimeout(function() { finish(isHiddenNow()); }, timeoutMs);
|
|
1445
|
+
fallbackInterval = setInterval(onChange, 120);
|
|
1446
|
+
if (typeof MutationObserver !== "undefined") {
|
|
1447
|
+
var root = document.documentElement || document.body || document;
|
|
1448
|
+
if (root) {
|
|
1449
|
+
observer = new MutationObserver(onChange);
|
|
1450
|
+
observer.observe(root, { childList: true, subtree: true, attributes: true, characterData: true });
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
});
|
|
1454
|
+
}
|
|
1455
|
+
|
|
1456
|
+
function waitForMatch(sel, opts) {
|
|
1457
|
+
opts = opts || {};
|
|
1458
|
+
var timeoutMs = Math.max(10, Math.round(opts.timeoutMs != null ? opts.timeoutMs : 5000));
|
|
1459
|
+
var kind = opts.kind;
|
|
1460
|
+
var expected = opts.expected !== undefined ? opts.expected : null;
|
|
1461
|
+
var expectedCount = opts.expectedCount !== undefined ? opts.expectedCount : null;
|
|
1462
|
+
var attributeName = opts.attributeName !== undefined ? opts.attributeName : null;
|
|
1463
|
+
var patternSource = opts.patternSource !== undefined ? opts.patternSource : null;
|
|
1464
|
+
var patternFlags = opts.patternFlags || "";
|
|
1465
|
+
var lastActual = undefined;
|
|
1466
|
+
var regex = patternSource !== null ? new RegExp(patternSource, patternFlags) : null;
|
|
1467
|
+
|
|
1468
|
+
function evaluateMatch() {
|
|
1469
|
+
if (kind === "url") {
|
|
1470
|
+
var href = typeof window !== "undefined" && window.location ? String(window.location.href || "") : "";
|
|
1471
|
+
lastActual = href;
|
|
1472
|
+
if (regex) {
|
|
1473
|
+
if (regex.test(href)) return { matched: true, actual: href };
|
|
1474
|
+
} else if (expected !== null) {
|
|
1475
|
+
if (href === expected || href.indexOf(String(expected)) !== -1) {
|
|
1476
|
+
return { matched: true, actual: href };
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
return null;
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
var hits = findAcrossRoots(sel);
|
|
1483
|
+
|
|
1484
|
+
if (kind === "count") {
|
|
1485
|
+
var visibleCount = 0;
|
|
1486
|
+
for (var ci = 0; ci < hits.length; ci++) {
|
|
1487
|
+
if (toMatch(hits[ci]).visible) visibleCount++;
|
|
1488
|
+
}
|
|
1489
|
+
lastActual = String(visibleCount);
|
|
1490
|
+
if (expectedCount !== null && visibleCount === expectedCount) {
|
|
1491
|
+
return { matched: true, actual: String(visibleCount) };
|
|
1492
|
+
}
|
|
1493
|
+
return null;
|
|
1494
|
+
}
|
|
1495
|
+
|
|
1496
|
+
for (var i = hits.length - 1; i >= 0; i--) {
|
|
1497
|
+
var m = toMatch(hits[i]);
|
|
1498
|
+
if (!m.visible) continue;
|
|
1499
|
+
if (kind === "text") {
|
|
1500
|
+
lastActual = m.text;
|
|
1501
|
+
if (m.text === expected) return { matched: true, actual: m.text };
|
|
1502
|
+
} else if (kind === "containsText") {
|
|
1503
|
+
var actual = m.text || "";
|
|
1504
|
+
lastActual = m.text;
|
|
1505
|
+
if (expected !== null && actual.toLowerCase().indexOf(String(expected).toLowerCase()) !== -1) {
|
|
1506
|
+
return { matched: true, actual: m.text };
|
|
1507
|
+
}
|
|
1508
|
+
} else if (kind === "matchesText") {
|
|
1509
|
+
var actualRe = m.text || "";
|
|
1510
|
+
lastActual = m.text;
|
|
1511
|
+
if (regex && regex.test(actualRe)) return { matched: true, actual: m.text };
|
|
1512
|
+
} else if (kind === "value") {
|
|
1513
|
+
var val = m.value !== undefined ? m.value : "";
|
|
1514
|
+
lastActual = val;
|
|
1515
|
+
if (val === expected) return { matched: true, actual: val };
|
|
1516
|
+
} else if (kind === "attribute" && attributeName !== null) {
|
|
1517
|
+
var attrVal = m.attributes ? m.attributes[attributeName] : undefined;
|
|
1518
|
+
lastActual = attrVal;
|
|
1519
|
+
if (expected === null ? attrVal !== undefined : attrVal === expected) {
|
|
1520
|
+
return { matched: true, actual: attrVal };
|
|
1521
|
+
}
|
|
1522
|
+
} else if (kind === "accessibilityLabel") {
|
|
1523
|
+
var lbl = m.accessibilityLabel;
|
|
1524
|
+
lastActual = lbl;
|
|
1525
|
+
if (expected === null ? (lbl !== undefined && lbl.length > 0) : lbl === expected) {
|
|
1526
|
+
return { matched: true, actual: lbl };
|
|
1527
|
+
}
|
|
1528
|
+
} else if (kind === "accessibleName") {
|
|
1529
|
+
var accName = m.accessibleName || m.accessibilityLabel || m.text || "";
|
|
1530
|
+
lastActual = accName;
|
|
1531
|
+
if (regex) {
|
|
1532
|
+
if (regex.test(accName)) return { matched: true, actual: accName };
|
|
1533
|
+
} else if (expected === null ? accName.length > 0 : accName.trim() === String(expected).trim()) {
|
|
1534
|
+
return { matched: true, actual: accName };
|
|
1535
|
+
}
|
|
1536
|
+
} else if (kind === "focused") {
|
|
1537
|
+
lastActual = m.focused ? "focused" : "not focused";
|
|
1538
|
+
if (m.focused) return { matched: true, actual: "focused" };
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
return null;
|
|
1542
|
+
}
|
|
1543
|
+
|
|
1544
|
+
var immediate = evaluateMatch();
|
|
1545
|
+
if (immediate) return immediate;
|
|
1546
|
+
|
|
1547
|
+
return new Promise(function(resolve) {
|
|
1548
|
+
var done = false;
|
|
1549
|
+
var observer = null;
|
|
1550
|
+
var timeoutTimer = null;
|
|
1551
|
+
var fallbackInterval = null;
|
|
1552
|
+
var scheduled = false;
|
|
1553
|
+
function finish(res) {
|
|
1554
|
+
if (done) return;
|
|
1555
|
+
done = true;
|
|
1556
|
+
if (observer) { try { observer.disconnect(); } catch (e) {} }
|
|
1557
|
+
if (timeoutTimer) clearTimeout(timeoutTimer);
|
|
1558
|
+
if (fallbackInterval) clearInterval(fallbackInterval);
|
|
1559
|
+
if (typeof document !== "undefined") {
|
|
1560
|
+
document.removeEventListener("input", onChange, true);
|
|
1561
|
+
document.removeEventListener("change", onChange, true);
|
|
1562
|
+
document.removeEventListener("focusin", onChange, true);
|
|
1563
|
+
document.removeEventListener("focusout", onChange, true);
|
|
1564
|
+
}
|
|
1565
|
+
if (typeof window !== "undefined") {
|
|
1566
|
+
window.removeEventListener("popstate", onChange);
|
|
1567
|
+
window.removeEventListener("hashchange", onChange);
|
|
1568
|
+
}
|
|
1569
|
+
resolve(res);
|
|
1570
|
+
}
|
|
1571
|
+
function onChange() {
|
|
1572
|
+
if (done || scheduled) return;
|
|
1573
|
+
scheduled = true;
|
|
1574
|
+
Promise.resolve().then(function() {
|
|
1575
|
+
scheduled = false;
|
|
1576
|
+
if (done) return;
|
|
1577
|
+
var res = evaluateMatch();
|
|
1578
|
+
if (res) finish(res);
|
|
1579
|
+
});
|
|
1580
|
+
}
|
|
1581
|
+
timeoutTimer = setTimeout(function() {
|
|
1582
|
+
var finalRes = evaluateMatch();
|
|
1583
|
+
finish(finalRes || { matched: false, actual: lastActual });
|
|
1584
|
+
}, timeoutMs);
|
|
1585
|
+
fallbackInterval = setInterval(onChange, kind === "url" ? 50 : 120);
|
|
1586
|
+
if (typeof document !== "undefined") {
|
|
1587
|
+
document.addEventListener("input", onChange, true);
|
|
1588
|
+
document.addEventListener("change", onChange, true);
|
|
1589
|
+
document.addEventListener("focusin", onChange, true);
|
|
1590
|
+
document.addEventListener("focusout", onChange, true);
|
|
1591
|
+
}
|
|
1592
|
+
if (typeof window !== "undefined") {
|
|
1593
|
+
window.addEventListener("popstate", onChange);
|
|
1594
|
+
window.addEventListener("hashchange", onChange);
|
|
1595
|
+
}
|
|
1596
|
+
if (typeof MutationObserver !== "undefined") {
|
|
1597
|
+
var root = document.documentElement || document.body || document;
|
|
1598
|
+
if (root) {
|
|
1599
|
+
observer = new MutationObserver(onChange);
|
|
1600
|
+
observer.observe(root, { childList: true, subtree: true, attributes: true, characterData: true });
|
|
1601
|
+
}
|
|
1602
|
+
}
|
|
1603
|
+
});
|
|
1604
|
+
}
|
|
1605
|
+
|
|
1606
|
+
function fill(sel, val, opts) {
|
|
1607
|
+
opts = opts || {};
|
|
1608
|
+
var timeoutMs = Math.max(10, Math.round(opts.timeoutMs != null ? opts.timeoutMs : 5000));
|
|
1609
|
+
var checkHitTest = opts.checkHitTest !== undefined ? Boolean(opts.checkHitTest) : true;
|
|
1610
|
+
function writeValue(el) {
|
|
1611
|
+
if (el.isContentEditable) return false;
|
|
1612
|
+
if (typeof el.focus === "function") { try { el.focus(); } catch (e) {} }
|
|
1613
|
+
var tag = el.tagName;
|
|
1614
|
+
if (tag === "INPUT" || tag === "TEXTAREA") {
|
|
1615
|
+
var win = (el.ownerDocument && el.ownerDocument.defaultView) || window;
|
|
1616
|
+
var proto = tag === "TEXTAREA"
|
|
1617
|
+
? (win.HTMLTextAreaElement && win.HTMLTextAreaElement.prototype)
|
|
1618
|
+
: (win.HTMLInputElement && win.HTMLInputElement.prototype);
|
|
1619
|
+
var desc = proto ? Object.getOwnPropertyDescriptor(proto, "value") : null;
|
|
1620
|
+
if (desc && typeof desc.set === "function") desc.set.call(el, val);
|
|
1621
|
+
else el.value = val;
|
|
1622
|
+
if (el._valueTracker && typeof el._valueTracker.setValue === "function") {
|
|
1623
|
+
try { el._valueTracker.setValue(val === "" ? " " : ""); } catch (e) {}
|
|
1624
|
+
}
|
|
1625
|
+
} else if (tag === "SELECT") {
|
|
1626
|
+
el.value = val;
|
|
1627
|
+
} else {
|
|
1628
|
+
el.value = val;
|
|
1629
|
+
}
|
|
1630
|
+
try { el.dispatchEvent(new InputEvent("input", { bubbles: true, cancelable: true, data: val, inputType: "insertText" })); }
|
|
1631
|
+
catch (e) { el.dispatchEvent(new Event("input", { bubbles: true, cancelable: true })); }
|
|
1632
|
+
el.dispatchEvent(new Event("change", { bubbles: true, cancelable: true }));
|
|
1633
|
+
return true;
|
|
1634
|
+
}
|
|
1635
|
+
function findEditableNow() {
|
|
1636
|
+
if (!isAppReady()) return null;
|
|
1637
|
+
var hits = findAcrossRoots(sel);
|
|
1638
|
+
for (var i = hits.length - 1; i >= 0; i--) {
|
|
1639
|
+
var h = hits[i];
|
|
1640
|
+
var m = toMatch(h);
|
|
1641
|
+
if (!m.visible || !m.enabled) continue;
|
|
1642
|
+
ensureInViewport(h);
|
|
1643
|
+
if (checkHitTest && !isHitTestClear(h)) continue;
|
|
1644
|
+
return h.el;
|
|
1645
|
+
}
|
|
1646
|
+
return null;
|
|
1647
|
+
}
|
|
1648
|
+
function verifyAndRetryFill(attemptsLeft) {
|
|
1649
|
+
var el = findEditableNow();
|
|
1650
|
+
if (!el || el.isContentEditable) return Promise.resolve(false);
|
|
1651
|
+
if (!writeValue(el)) return Promise.resolve(false);
|
|
1652
|
+
return new Promise(function(resolve) {
|
|
1653
|
+
setTimeout(function() {
|
|
1654
|
+
var latest = findEditableNow() || el;
|
|
1655
|
+
if (latest && latest.isConnected && String(latest.value == null ? "" : latest.value) === val) {
|
|
1656
|
+
resolve(true);
|
|
1657
|
+
return;
|
|
1658
|
+
}
|
|
1659
|
+
if (attemptsLeft > 1) {
|
|
1660
|
+
verifyAndRetryFill(attemptsLeft - 1).then(resolve);
|
|
1661
|
+
} else {
|
|
1662
|
+
resolve(false);
|
|
1663
|
+
}
|
|
1664
|
+
}, 12);
|
|
1665
|
+
});
|
|
1666
|
+
}
|
|
1667
|
+
var immEl = findEditableNow();
|
|
1668
|
+
if (immEl) {
|
|
1669
|
+
if (immEl.isContentEditable) return false;
|
|
1670
|
+
return verifyAndRetryFill(3);
|
|
1671
|
+
}
|
|
1672
|
+
return new Promise(function(resolve) {
|
|
1673
|
+
var done = false;
|
|
1674
|
+
var observer = null;
|
|
1675
|
+
var timeoutTimer = null;
|
|
1676
|
+
var fallbackInterval = null;
|
|
1677
|
+
var scheduled = false;
|
|
1678
|
+
var filling = false;
|
|
1679
|
+
function finish(ok) {
|
|
1680
|
+
if (done) return;
|
|
1681
|
+
done = true;
|
|
1682
|
+
if (observer) { try { observer.disconnect(); } catch (e) {} }
|
|
1683
|
+
if (timeoutTimer) clearTimeout(timeoutTimer);
|
|
1684
|
+
if (fallbackInterval) clearInterval(fallbackInterval);
|
|
1685
|
+
resolve(ok);
|
|
1686
|
+
}
|
|
1687
|
+
function onChange() {
|
|
1688
|
+
if (done || scheduled || filling) return;
|
|
1689
|
+
scheduled = true;
|
|
1690
|
+
Promise.resolve().then(function() {
|
|
1691
|
+
scheduled = false;
|
|
1692
|
+
if (done || filling) return;
|
|
1693
|
+
var target = findEditableNow();
|
|
1694
|
+
if (!target) return;
|
|
1695
|
+
if (target.isContentEditable) { finish(false); return; }
|
|
1696
|
+
filling = true;
|
|
1697
|
+
verifyAndRetryFill(3).then(function(ok) { finish(ok); });
|
|
1698
|
+
});
|
|
1699
|
+
}
|
|
1700
|
+
timeoutTimer = setTimeout(function() {
|
|
1701
|
+
if (filling) return;
|
|
1702
|
+
var target = findEditableNow();
|
|
1703
|
+
if (!target || target.isContentEditable) { finish(false); return; }
|
|
1704
|
+
filling = true;
|
|
1705
|
+
verifyAndRetryFill(2).then(function(ok) { finish(ok); });
|
|
1706
|
+
}, timeoutMs);
|
|
1707
|
+
fallbackInterval = setInterval(onChange, 40);
|
|
1708
|
+
if (typeof MutationObserver !== "undefined") {
|
|
1709
|
+
var root = document.documentElement || document.body || document;
|
|
1710
|
+
if (root) {
|
|
1711
|
+
observer = new MutationObserver(onChange);
|
|
1712
|
+
observer.observe(root, { childList: true, subtree: true, attributes: true, characterData: true });
|
|
1713
|
+
}
|
|
1714
|
+
}
|
|
1715
|
+
});
|
|
1716
|
+
}
|
|
1717
|
+
|
|
1718
|
+
window.__spanaRt = {
|
|
1719
|
+
query: query,
|
|
1720
|
+
scrollIntoView: scrollIntoView,
|
|
1721
|
+
tap: tap,
|
|
1722
|
+
waitForSelector: waitForSelector,
|
|
1723
|
+
waitForHidden: waitForHidden,
|
|
1724
|
+
waitForMatch: waitForMatch,
|
|
1725
|
+
fill: fill
|
|
1726
|
+
};
|
|
1727
|
+
return true;
|
|
1728
|
+
})();`;
|
|
1729
|
+
function buildDomFindElementScript(selector) {
|
|
1730
|
+
const serialized = JSON.stringify(serializeSelectorForDom(selector));
|
|
1731
|
+
return `(function(sel) {
|
|
1732
|
+
${SHARED_DOM_TRAVERSAL_HELPERS}
|
|
1733
|
+
var hits = findAcrossRoots(sel);
|
|
1734
|
+
if (hits.length === 0) return null;
|
|
1735
|
+
return hits[hits.length - 1].el;
|
|
1736
|
+
})(${serialized})`;
|
|
1737
|
+
}
|
|
1738
|
+
function buildInjectedCallScript(method, ...args) {
|
|
1739
|
+
const serializedArgs = args.map((arg) => JSON.stringify(serializeSelectorForDom(arg))).join(",");
|
|
1740
|
+
return `window.__spanaRt?window.__spanaRt.${method}(${serializedArgs}):${JSON.stringify(SPANA_RUNTIME_MISSING_SENTINEL)}`;
|
|
1741
|
+
}
|
|
876
1742
|
|
|
877
1743
|
// src/core/target-matrix.ts
|
|
878
1744
|
var TARGET_CHANNEL_MATRIX = {
|
|
@@ -1197,6 +2063,25 @@ var CdpDomChannel = class {
|
|
|
1197
2063
|
getChildSessions() {
|
|
1198
2064
|
return Array.from(this.childSessions.values());
|
|
1199
2065
|
}
|
|
2066
|
+
useInjectedRuntime = false;
|
|
2067
|
+
enableInjectedRuntime(enabled = true) {
|
|
2068
|
+
this.useInjectedRuntime = enabled;
|
|
2069
|
+
}
|
|
2070
|
+
async invokeDom(sessionId, method, args, fallbackScript) {
|
|
2071
|
+
if (!this.useInjectedRuntime) {
|
|
2072
|
+
return this.evaluateOnSession(sessionId, fallbackScript());
|
|
2073
|
+
}
|
|
2074
|
+
const callExpr = buildInjectedCallScript(method, ...args);
|
|
2075
|
+
const res = await this.evaluateOnSession(
|
|
2076
|
+
sessionId,
|
|
2077
|
+
callExpr
|
|
2078
|
+
);
|
|
2079
|
+
if (res !== SPANA_RUNTIME_MISSING_SENTINEL) {
|
|
2080
|
+
return res;
|
|
2081
|
+
}
|
|
2082
|
+
await this.evaluateOnSession(sessionId, SPANA_INJECTED_RUNTIME_SCRIPT);
|
|
2083
|
+
return this.evaluateOnSession(sessionId, callExpr);
|
|
2084
|
+
}
|
|
1200
2085
|
setFrameOffsetResolver(resolver) {
|
|
1201
2086
|
this.frameOffsetResolver = resolver;
|
|
1202
2087
|
}
|
|
@@ -1283,14 +2168,21 @@ var CdpDomChannel = class {
|
|
|
1283
2168
|
}));
|
|
1284
2169
|
}
|
|
1285
2170
|
async query(selector) {
|
|
1286
|
-
const
|
|
1287
|
-
const result = await this.
|
|
2171
|
+
const fallback = () => buildDomQueryScript(selector);
|
|
2172
|
+
const result = await this.invokeDom(
|
|
2173
|
+
void 0,
|
|
2174
|
+
"query",
|
|
2175
|
+
[selector],
|
|
2176
|
+
fallback
|
|
2177
|
+
);
|
|
1288
2178
|
if (Array.isArray(result) && result.length > 0) return result;
|
|
1289
2179
|
if (this.childSessions.size === 0) return [];
|
|
1290
2180
|
for (const child of this.childSessions.values()) {
|
|
1291
|
-
const childRes = await this.
|
|
2181
|
+
const childRes = await this.invokeDom(
|
|
1292
2182
|
child.sessionId,
|
|
1293
|
-
|
|
2183
|
+
"query",
|
|
2184
|
+
[selector],
|
|
2185
|
+
fallback
|
|
1294
2186
|
).catch(() => []);
|
|
1295
2187
|
if (Array.isArray(childRes) && childRes.length > 0) {
|
|
1296
2188
|
return this.applyChildOffset(childRes, child);
|
|
@@ -1299,22 +2191,33 @@ var CdpDomChannel = class {
|
|
|
1299
2191
|
return [];
|
|
1300
2192
|
}
|
|
1301
2193
|
async waitForSelector(selector, opts) {
|
|
2194
|
+
const fallback = () => buildDomWaitForSelectorScript(selector, opts);
|
|
1302
2195
|
if (this.childSessions.size === 0) {
|
|
1303
|
-
const result = await this.
|
|
1304
|
-
|
|
2196
|
+
const result = await this.invokeDom(
|
|
2197
|
+
void 0,
|
|
2198
|
+
"waitForSelector",
|
|
2199
|
+
[selector, opts ?? {}],
|
|
2200
|
+
fallback
|
|
1305
2201
|
);
|
|
1306
2202
|
return Array.isArray(result) ? result : [];
|
|
1307
2203
|
}
|
|
1308
2204
|
const immediate = await this.query(selector);
|
|
1309
2205
|
const filtered = immediate.filter((m) => m.visible && (!opts?.forAction || m.enabled));
|
|
1310
2206
|
if (filtered.length > 0 && !opts?.forAction) return filtered;
|
|
1311
|
-
const script = buildDomWaitForSelectorScript(selector, opts);
|
|
1312
2207
|
const racers = [
|
|
1313
|
-
this.
|
|
2208
|
+
this.invokeDom(
|
|
2209
|
+
void 0,
|
|
2210
|
+
"waitForSelector",
|
|
2211
|
+
[selector, opts ?? {}],
|
|
2212
|
+
fallback
|
|
2213
|
+
).catch(() => []),
|
|
1314
2214
|
...Array.from(this.childSessions.values()).map(async (child) => {
|
|
1315
|
-
const res = await this.
|
|
1316
|
-
|
|
1317
|
-
|
|
2215
|
+
const res = await this.invokeDom(
|
|
2216
|
+
child.sessionId,
|
|
2217
|
+
"waitForSelector",
|
|
2218
|
+
[selector, opts ?? {}],
|
|
2219
|
+
fallback
|
|
2220
|
+
).catch(() => []);
|
|
1318
2221
|
return Array.isArray(res) && res.length > 0 ? this.applyChildOffset(res, child) : [];
|
|
1319
2222
|
})
|
|
1320
2223
|
];
|
|
@@ -1339,26 +2242,40 @@ var CdpDomChannel = class {
|
|
|
1339
2242
|
});
|
|
1340
2243
|
}
|
|
1341
2244
|
async waitForHidden(selector, opts) {
|
|
1342
|
-
const
|
|
1343
|
-
const mainHidden = Boolean(
|
|
2245
|
+
const fallback = () => buildDomWaitForHiddenScript(selector, opts);
|
|
2246
|
+
const mainHidden = Boolean(
|
|
2247
|
+
await this.invokeDom(void 0, "waitForHidden", [selector, opts ?? {}], fallback)
|
|
2248
|
+
);
|
|
1344
2249
|
if (!mainHidden || this.childSessions.size === 0) return mainHidden;
|
|
1345
2250
|
for (const child of this.childSessions.values()) {
|
|
1346
2251
|
const ok = Boolean(
|
|
1347
|
-
await this.
|
|
2252
|
+
await this.invokeDom(
|
|
2253
|
+
child.sessionId,
|
|
2254
|
+
"waitForHidden",
|
|
2255
|
+
[selector, opts ?? {}],
|
|
2256
|
+
fallback
|
|
2257
|
+
).catch(() => true)
|
|
1348
2258
|
);
|
|
1349
2259
|
if (!ok) return false;
|
|
1350
2260
|
}
|
|
1351
2261
|
return true;
|
|
1352
2262
|
}
|
|
1353
2263
|
async waitForMatch(selector, opts) {
|
|
1354
|
-
const
|
|
1355
|
-
const result = await this.
|
|
2264
|
+
const fallback = () => buildDomWaitForMatchScript(selector, opts);
|
|
2265
|
+
const result = await this.invokeDom(
|
|
2266
|
+
void 0,
|
|
2267
|
+
"waitForMatch",
|
|
2268
|
+
[selector, opts],
|
|
2269
|
+
fallback
|
|
2270
|
+
);
|
|
1356
2271
|
if (result && typeof result === "object" && result.matched) return result;
|
|
1357
2272
|
if (this.childSessions.size > 0) {
|
|
1358
2273
|
for (const child of this.childSessions.values()) {
|
|
1359
|
-
const childRes = await this.
|
|
2274
|
+
const childRes = await this.invokeDom(
|
|
1360
2275
|
child.sessionId,
|
|
1361
|
-
|
|
2276
|
+
"waitForMatch",
|
|
2277
|
+
[selector, opts],
|
|
2278
|
+
fallback
|
|
1362
2279
|
).catch(() => ({ matched: false }));
|
|
1363
2280
|
if (childRes?.matched) return childRes;
|
|
1364
2281
|
}
|
|
@@ -1366,38 +2283,56 @@ var CdpDomChannel = class {
|
|
|
1366
2283
|
return result && typeof result === "object" ? result : { matched: false };
|
|
1367
2284
|
}
|
|
1368
2285
|
async fillDom(selector, value, opts) {
|
|
1369
|
-
const
|
|
1370
|
-
const mainFilled = Boolean(
|
|
2286
|
+
const fallback = () => buildDomFillScript(selector, value, opts);
|
|
2287
|
+
const mainFilled = Boolean(
|
|
2288
|
+
await this.invokeDom(void 0, "fill", [selector, value, opts ?? {}], fallback)
|
|
2289
|
+
);
|
|
1371
2290
|
if (mainFilled || this.childSessions.size === 0) return mainFilled;
|
|
1372
2291
|
for (const child of this.childSessions.values()) {
|
|
1373
2292
|
const ok = Boolean(
|
|
1374
|
-
await this.
|
|
2293
|
+
await this.invokeDom(
|
|
2294
|
+
child.sessionId,
|
|
2295
|
+
"fill",
|
|
2296
|
+
[selector, value, opts ?? {}],
|
|
2297
|
+
fallback
|
|
2298
|
+
).catch(() => false)
|
|
1375
2299
|
);
|
|
1376
2300
|
if (ok) return true;
|
|
1377
2301
|
}
|
|
1378
2302
|
return false;
|
|
1379
2303
|
}
|
|
1380
2304
|
async tapDom(selector) {
|
|
1381
|
-
const
|
|
1382
|
-
const mainTapped = Boolean(
|
|
2305
|
+
const fallback = () => buildDomTapScript(selector);
|
|
2306
|
+
const mainTapped = Boolean(
|
|
2307
|
+
await this.invokeDom(void 0, "tap", [selector], fallback)
|
|
2308
|
+
);
|
|
1383
2309
|
if (mainTapped || this.childSessions.size === 0) return mainTapped;
|
|
1384
2310
|
for (const child of this.childSessions.values()) {
|
|
1385
2311
|
const ok = Boolean(
|
|
1386
|
-
await this.
|
|
2312
|
+
await this.invokeDom(child.sessionId, "tap", [selector], fallback).catch(
|
|
2313
|
+
() => false
|
|
2314
|
+
)
|
|
1387
2315
|
);
|
|
1388
2316
|
if (ok) return true;
|
|
1389
2317
|
}
|
|
1390
2318
|
return false;
|
|
1391
2319
|
}
|
|
1392
2320
|
async scrollIntoView(selector) {
|
|
1393
|
-
const
|
|
1394
|
-
const result = await this.
|
|
2321
|
+
const fallback = () => buildDomScrollIntoViewScript(selector);
|
|
2322
|
+
const result = await this.invokeDom(
|
|
2323
|
+
void 0,
|
|
2324
|
+
"scrollIntoView",
|
|
2325
|
+
[selector],
|
|
2326
|
+
fallback
|
|
2327
|
+
);
|
|
1395
2328
|
if (result) return result;
|
|
1396
2329
|
if (this.childSessions.size > 0) {
|
|
1397
2330
|
for (const child of this.childSessions.values()) {
|
|
1398
|
-
const childRes = await this.
|
|
2331
|
+
const childRes = await this.invokeDom(
|
|
1399
2332
|
child.sessionId,
|
|
1400
|
-
|
|
2333
|
+
"scrollIntoView",
|
|
2334
|
+
[selector],
|
|
2335
|
+
fallback
|
|
1401
2336
|
).catch(() => null);
|
|
1402
2337
|
if (childRes) {
|
|
1403
2338
|
const adjusted = await this.applyChildOffset([childRes], child);
|
|
@@ -1432,7 +2367,7 @@ function createCdpDomChannel(options) {
|
|
|
1432
2367
|
}
|
|
1433
2368
|
|
|
1434
2369
|
// src/channels/android-cdp.ts
|
|
1435
|
-
import {
|
|
2370
|
+
import { execFileSync } from "child_process";
|
|
1436
2371
|
function parseAndroidWebViewSockets(procNetUnixOutput) {
|
|
1437
2372
|
const seen = /* @__PURE__ */ new Set();
|
|
1438
2373
|
const sockets = [];
|
|
@@ -1481,13 +2416,13 @@ var AndroidWebViewCdpChannel = class {
|
|
|
1481
2416
|
}
|
|
1482
2417
|
execAdb(args) {
|
|
1483
2418
|
if (this.options.runAdb) {
|
|
1484
|
-
return this.options.runAdb(args);
|
|
2419
|
+
return this.options.runAdb(args.join(" "));
|
|
1485
2420
|
}
|
|
1486
2421
|
const adb = findADB();
|
|
1487
2422
|
if (!adb) {
|
|
1488
2423
|
throw new Error("adb not found on PATH or ANDROID_HOME");
|
|
1489
2424
|
}
|
|
1490
|
-
return
|
|
2425
|
+
return execFileSync(adb, args, { encoding: "utf-8" });
|
|
1491
2426
|
}
|
|
1492
2427
|
isConnected() {
|
|
1493
2428
|
return this.cdp?.isConnected() ?? false;
|
|
@@ -1521,7 +2456,13 @@ var AndroidWebViewCdpChannel = class {
|
|
|
1521
2456
|
this.forwardedPort = port;
|
|
1522
2457
|
this.activeSocketName = socketName;
|
|
1523
2458
|
try {
|
|
1524
|
-
this.execAdb(
|
|
2459
|
+
this.execAdb([
|
|
2460
|
+
"-s",
|
|
2461
|
+
this.options.serial,
|
|
2462
|
+
"forward",
|
|
2463
|
+
`tcp:${port}`,
|
|
2464
|
+
`localabstract:${socketName}`
|
|
2465
|
+
]);
|
|
1525
2466
|
this.cdp = new CdpDomChannel({
|
|
1526
2467
|
endpointUrl: `http://127.0.0.1:${port}`,
|
|
1527
2468
|
timeoutMs: this.options.timeoutMs,
|
|
@@ -1585,7 +2526,7 @@ var AndroidWebViewCdpChannel = class {
|
|
|
1585
2526
|
const port = this.forwardedPort;
|
|
1586
2527
|
this.forwardedPort = null;
|
|
1587
2528
|
try {
|
|
1588
|
-
this.execAdb(
|
|
2529
|
+
this.execAdb(["-s", this.options.serial, "forward", "--remove", `tcp:${port}`]);
|
|
1589
2530
|
} catch {
|
|
1590
2531
|
}
|
|
1591
2532
|
if (this.allocatedByUs) {
|
|
@@ -1601,7 +2542,7 @@ function createAndroidWebViewCdpChannel(options) {
|
|
|
1601
2542
|
}
|
|
1602
2543
|
|
|
1603
2544
|
// src/channels/apple-webinspector.ts
|
|
1604
|
-
import { execSync
|
|
2545
|
+
import { execSync } from "child_process";
|
|
1605
2546
|
import { randomUUID } from "crypto";
|
|
1606
2547
|
import { existsSync, readdirSync } from "fs";
|
|
1607
2548
|
import { createConnection } from "net";
|
|
@@ -1706,7 +2647,7 @@ function findSimulatorWebInspectorSocket(udid) {
|
|
|
1706
2647
|
if (existsSync(envSock)) return envSock;
|
|
1707
2648
|
}
|
|
1708
2649
|
try {
|
|
1709
|
-
const out =
|
|
2650
|
+
const out = execSync("launchctl getenv SIMULATOR_WEBINSPECTOR_SOCKET 2>/dev/null || true", {
|
|
1710
2651
|
encoding: "utf-8",
|
|
1711
2652
|
timeout: 2e3
|
|
1712
2653
|
}).trim();
|
|
@@ -1897,7 +2838,7 @@ var AppleWebInspectorClient = class {
|
|
|
1897
2838
|
};
|
|
1898
2839
|
|
|
1899
2840
|
// src/channels/webkit-inspector.ts
|
|
1900
|
-
import { execSync as
|
|
2841
|
+
import { execSync as execSync2, spawn } from "child_process";
|
|
1901
2842
|
var WS_OPEN2 = 1;
|
|
1902
2843
|
function defaultWebSocketFactory2(url) {
|
|
1903
2844
|
return new WebSocket(url);
|
|
@@ -1938,7 +2879,7 @@ function selectWebKitTarget(targets, bundleId) {
|
|
|
1938
2879
|
}
|
|
1939
2880
|
function isWebKitDebugProxyInstalled() {
|
|
1940
2881
|
try {
|
|
1941
|
-
|
|
2882
|
+
execSync2("which ios_webkit_debug_proxy", { stdio: "ignore" });
|
|
1942
2883
|
return true;
|
|
1943
2884
|
} catch {
|
|
1944
2885
|
return false;
|
|
@@ -3151,6 +4092,9 @@ export {
|
|
|
3151
4092
|
buildDomWaitForHiddenScript,
|
|
3152
4093
|
buildDomWaitForMatchScript,
|
|
3153
4094
|
buildDomFillScript,
|
|
4095
|
+
SPANA_INJECTED_RUNTIME_SCRIPT,
|
|
4096
|
+
buildDomFindElementScript,
|
|
4097
|
+
buildInjectedCallScript,
|
|
3154
4098
|
TARGET_CHANNEL_MATRIX,
|
|
3155
4099
|
resolveElectrobunEngine,
|
|
3156
4100
|
resolveTargetDescriptor,
|
|
@@ -3175,4 +4119,4 @@ export {
|
|
|
3175
4119
|
resolveElectrobunLaunchPlan,
|
|
3176
4120
|
makeElectrobunDriver
|
|
3177
4121
|
};
|
|
3178
|
-
//# sourceMappingURL=chunk-
|
|
4122
|
+
//# sourceMappingURL=chunk-SNL4X67N.js.map
|