browser-pilot 0.0.16 → 0.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -0
- package/dist/actions.cjs +797 -69
- package/dist/actions.d.cts +101 -4
- package/dist/actions.d.ts +101 -4
- package/dist/actions.mjs +17 -1
- package/dist/{browser-ZCR6AA4D.mjs → browser-4ZHNAQR5.mjs} +2 -2
- package/dist/browser.cjs +1238 -72
- package/dist/browser.d.cts +229 -5
- package/dist/browser.d.ts +229 -5
- package/dist/browser.mjs +36 -4
- package/dist/{chunk-NNEHWWHL.mjs → chunk-FEEGNSHB.mjs} +584 -4
- package/dist/{chunk-TJ5B56NV.mjs → chunk-IRLHCVNH.mjs} +1 -1
- package/dist/chunk-MIJ7UIKB.mjs +96 -0
- package/dist/{chunk-6GBYX7C2.mjs → chunk-MRY3HRFJ.mjs} +799 -353
- package/dist/chunk-OIHU7OFY.mjs +91 -0
- package/dist/{chunk-V3VLBQAM.mjs → chunk-ZDODXEBD.mjs} +586 -69
- package/dist/cli.mjs +756 -174
- package/dist/combobox-RAKBA2BW.mjs +6 -0
- package/dist/index.cjs +1539 -71
- package/dist/index.d.cts +56 -5
- package/dist/index.d.ts +56 -5
- package/dist/index.mjs +189 -2
- package/dist/{page-IUUTJ3SW.mjs → page-SD64DY3F.mjs} +1 -1
- package/dist/{types-BzM-IfsL.d.ts → types-B_v62K7C.d.ts} +146 -2
- package/dist/{types-BflRmiDz.d.cts → types-Yuybzq53.d.cts} +146 -2
- package/dist/upload-E6MCC2OF.mjs +6 -0
- package/package.json +10 -3
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// src/browser/combobox.ts
|
|
2
|
+
var DEFAULT_LISTBOX_SELECTORS = [
|
|
3
|
+
'[role="listbox"]',
|
|
4
|
+
'[role="menu"]',
|
|
5
|
+
'[role="tree"]',
|
|
6
|
+
'ul[class*="dropdown"]',
|
|
7
|
+
'ul[class*="option"]',
|
|
8
|
+
'ul[class*="list"]',
|
|
9
|
+
'div[class*="dropdown"]',
|
|
10
|
+
'div[class*="menu"]'
|
|
11
|
+
];
|
|
12
|
+
var DEFAULT_OPTION_SELECTORS = [
|
|
13
|
+
'[role="option"]',
|
|
14
|
+
'[role="menuitem"]',
|
|
15
|
+
'[role="treeitem"]',
|
|
16
|
+
"li"
|
|
17
|
+
];
|
|
18
|
+
async function chooseOption(page, config) {
|
|
19
|
+
const {
|
|
20
|
+
trigger,
|
|
21
|
+
listbox,
|
|
22
|
+
optionSelector,
|
|
23
|
+
searchText,
|
|
24
|
+
value,
|
|
25
|
+
match = "contains",
|
|
26
|
+
timeout = 1e4
|
|
27
|
+
} = config;
|
|
28
|
+
try {
|
|
29
|
+
await page.click(trigger, { timeout });
|
|
30
|
+
const listboxSelectors = listbox ? Array.isArray(listbox) ? listbox : [listbox] : DEFAULT_LISTBOX_SELECTORS;
|
|
31
|
+
const listboxFound = await page.waitFor(listboxSelectors, {
|
|
32
|
+
timeout: Math.min(timeout, 3e3),
|
|
33
|
+
optional: true,
|
|
34
|
+
state: "visible"
|
|
35
|
+
});
|
|
36
|
+
if (!listboxFound) {
|
|
37
|
+
return {
|
|
38
|
+
success: false,
|
|
39
|
+
failedAt: "open",
|
|
40
|
+
error: "Listbox did not appear after clicking trigger"
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
if (searchText) {
|
|
44
|
+
try {
|
|
45
|
+
const triggerSel = Array.isArray(trigger) ? trigger[0] : trigger;
|
|
46
|
+
await page.type(triggerSel, searchText, {
|
|
47
|
+
delay: 30,
|
|
48
|
+
timeout: Math.min(timeout, 3e3)
|
|
49
|
+
});
|
|
50
|
+
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
51
|
+
} catch {
|
|
52
|
+
return { success: false, failedAt: "search", error: "Failed to type search text" };
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const optionSelectors = optionSelector ? [optionSelector] : DEFAULT_OPTION_SELECTORS;
|
|
56
|
+
const matchFn = match === "exact" ? "exact" : match === "startsWith" ? "startsWith" : "contains";
|
|
57
|
+
const clickedOption = await page.evaluate(`(() => {
|
|
58
|
+
const selectors = ${JSON.stringify(optionSelectors)};
|
|
59
|
+
const targetValue = ${JSON.stringify(value)};
|
|
60
|
+
const matchMode = ${JSON.stringify(matchFn)};
|
|
61
|
+
|
|
62
|
+
for (const sel of selectors) {
|
|
63
|
+
const options = document.querySelectorAll(sel);
|
|
64
|
+
for (const opt of options) {
|
|
65
|
+
const text = (opt.textContent || '').trim();
|
|
66
|
+
let matches = false;
|
|
67
|
+
if (matchMode === 'exact') matches = text === targetValue;
|
|
68
|
+
else if (matchMode === 'startsWith') matches = text.startsWith(targetValue);
|
|
69
|
+
else matches = text.includes(targetValue);
|
|
70
|
+
|
|
71
|
+
if (matches) {
|
|
72
|
+
opt.click();
|
|
73
|
+
return text;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return null;
|
|
78
|
+
})()`);
|
|
79
|
+
if (!clickedOption) {
|
|
80
|
+
return { success: false, failedAt: "select", error: `No option matching "${value}" found` };
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
success: true,
|
|
84
|
+
selectedText: String(clickedOption)
|
|
85
|
+
};
|
|
86
|
+
} catch (error) {
|
|
87
|
+
return {
|
|
88
|
+
success: false,
|
|
89
|
+
error: error instanceof Error ? error.message : String(error)
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export {
|
|
95
|
+
chooseOption
|
|
96
|
+
};
|