browser-pilot 0.0.1
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/LICENSE +21 -0
- package/README.md +539 -0
- package/dist/actions.cjs +277 -0
- package/dist/actions.d.cts +33 -0
- package/dist/actions.d.ts +33 -0
- package/dist/actions.mjs +8 -0
- package/dist/browser.cjs +2765 -0
- package/dist/browser.d.cts +71 -0
- package/dist/browser.d.ts +71 -0
- package/dist/browser.mjs +19 -0
- package/dist/cdp.cjs +279 -0
- package/dist/cdp.d.cts +230 -0
- package/dist/cdp.d.ts +230 -0
- package/dist/cdp.mjs +10 -0
- package/dist/chunk-BCOZUKWS.mjs +251 -0
- package/dist/chunk-FI55U7JS.mjs +2108 -0
- package/dist/chunk-R3PS4PCM.mjs +207 -0
- package/dist/chunk-YEHK2XY3.mjs +250 -0
- package/dist/chunk-ZIQA4JOT.mjs +226 -0
- package/dist/cli.cjs +3587 -0
- package/dist/cli.d.cts +23 -0
- package/dist/cli.d.ts +23 -0
- package/dist/cli.mjs +827 -0
- package/dist/client-7Nqka5MV.d.cts +53 -0
- package/dist/client-7Nqka5MV.d.ts +53 -0
- package/dist/index.cjs +3074 -0
- package/dist/index.d.cts +157 -0
- package/dist/index.d.ts +157 -0
- package/dist/index.mjs +64 -0
- package/dist/providers.cjs +238 -0
- package/dist/providers.d.cts +86 -0
- package/dist/providers.d.ts +86 -0
- package/dist/providers.mjs +16 -0
- package/dist/types-Cs89wle0.d.cts +925 -0
- package/dist/types-DL_-3BZk.d.ts +925 -0
- package/dist/types-D_uDqh0Z.d.cts +56 -0
- package/dist/types-D_uDqh0Z.d.ts +56 -0
- package/package.json +91 -0
package/dist/actions.cjs
ADDED
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/actions/index.ts
|
|
21
|
+
var actions_exports = {};
|
|
22
|
+
__export(actions_exports, {
|
|
23
|
+
BatchExecutor: () => BatchExecutor,
|
|
24
|
+
addBatchToPage: () => addBatchToPage
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(actions_exports);
|
|
27
|
+
|
|
28
|
+
// src/actions/executor.ts
|
|
29
|
+
var DEFAULT_TIMEOUT = 3e4;
|
|
30
|
+
var BatchExecutor = class {
|
|
31
|
+
page;
|
|
32
|
+
constructor(page) {
|
|
33
|
+
this.page = page;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Execute a batch of steps
|
|
37
|
+
*/
|
|
38
|
+
async execute(steps, options = {}) {
|
|
39
|
+
const { timeout = DEFAULT_TIMEOUT, onFail = "stop" } = options;
|
|
40
|
+
const results = [];
|
|
41
|
+
const startTime = Date.now();
|
|
42
|
+
for (let i = 0; i < steps.length; i++) {
|
|
43
|
+
const step = steps[i];
|
|
44
|
+
const stepStart = Date.now();
|
|
45
|
+
try {
|
|
46
|
+
const result = await this.executeStep(step, timeout);
|
|
47
|
+
results.push({
|
|
48
|
+
index: i,
|
|
49
|
+
action: step.action,
|
|
50
|
+
selector: step.selector,
|
|
51
|
+
selectorUsed: result.selectorUsed,
|
|
52
|
+
success: true,
|
|
53
|
+
durationMs: Date.now() - stepStart,
|
|
54
|
+
result: result.value,
|
|
55
|
+
text: result.text
|
|
56
|
+
});
|
|
57
|
+
} catch (error) {
|
|
58
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
59
|
+
results.push({
|
|
60
|
+
index: i,
|
|
61
|
+
action: step.action,
|
|
62
|
+
selector: step.selector,
|
|
63
|
+
success: false,
|
|
64
|
+
durationMs: Date.now() - stepStart,
|
|
65
|
+
error: errorMessage
|
|
66
|
+
});
|
|
67
|
+
if (onFail === "stop" && !step.optional) {
|
|
68
|
+
return {
|
|
69
|
+
success: false,
|
|
70
|
+
stoppedAtIndex: i,
|
|
71
|
+
steps: results,
|
|
72
|
+
totalDurationMs: Date.now() - startTime
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const allSuccess = results.every((r) => r.success || steps[r.index]?.optional);
|
|
78
|
+
return {
|
|
79
|
+
success: allSuccess,
|
|
80
|
+
steps: results,
|
|
81
|
+
totalDurationMs: Date.now() - startTime
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Execute a single step
|
|
86
|
+
*/
|
|
87
|
+
async executeStep(step, defaultTimeout) {
|
|
88
|
+
const timeout = step.timeout ?? defaultTimeout;
|
|
89
|
+
const optional = step.optional ?? false;
|
|
90
|
+
switch (step.action) {
|
|
91
|
+
case "goto": {
|
|
92
|
+
if (!step.url) throw new Error("goto requires url");
|
|
93
|
+
await this.page.goto(step.url, { timeout, optional });
|
|
94
|
+
return {};
|
|
95
|
+
}
|
|
96
|
+
case "click": {
|
|
97
|
+
if (!step.selector) throw new Error("click requires selector");
|
|
98
|
+
if (step.waitForNavigation) {
|
|
99
|
+
const navPromise = this.page.waitForNavigation({ timeout, optional });
|
|
100
|
+
await this.page.click(step.selector, { timeout, optional });
|
|
101
|
+
await navPromise;
|
|
102
|
+
} else {
|
|
103
|
+
await this.page.click(step.selector, { timeout, optional });
|
|
104
|
+
}
|
|
105
|
+
return { selectorUsed: this.getUsedSelector(step.selector) };
|
|
106
|
+
}
|
|
107
|
+
case "fill": {
|
|
108
|
+
if (!step.selector) throw new Error("fill requires selector");
|
|
109
|
+
if (typeof step.value !== "string") throw new Error("fill requires string value");
|
|
110
|
+
await this.page.fill(step.selector, step.value, {
|
|
111
|
+
timeout,
|
|
112
|
+
optional,
|
|
113
|
+
clear: step.clear ?? true
|
|
114
|
+
});
|
|
115
|
+
return { selectorUsed: this.getUsedSelector(step.selector) };
|
|
116
|
+
}
|
|
117
|
+
case "type": {
|
|
118
|
+
if (!step.selector) throw new Error("type requires selector");
|
|
119
|
+
if (typeof step.value !== "string") throw new Error("type requires string value");
|
|
120
|
+
await this.page.type(step.selector, step.value, {
|
|
121
|
+
timeout,
|
|
122
|
+
optional,
|
|
123
|
+
delay: step.delay ?? 50
|
|
124
|
+
});
|
|
125
|
+
return { selectorUsed: this.getUsedSelector(step.selector) };
|
|
126
|
+
}
|
|
127
|
+
case "select": {
|
|
128
|
+
if (step.trigger && step.option && typeof step.value === "string") {
|
|
129
|
+
await this.page.select(
|
|
130
|
+
{
|
|
131
|
+
trigger: step.trigger,
|
|
132
|
+
option: step.option,
|
|
133
|
+
value: step.value,
|
|
134
|
+
match: step.match
|
|
135
|
+
},
|
|
136
|
+
{ timeout, optional }
|
|
137
|
+
);
|
|
138
|
+
return { selectorUsed: this.getUsedSelector(step.trigger) };
|
|
139
|
+
}
|
|
140
|
+
if (!step.selector) throw new Error("select requires selector");
|
|
141
|
+
if (!step.value) throw new Error("select requires value");
|
|
142
|
+
await this.page.select(step.selector, step.value, { timeout, optional });
|
|
143
|
+
return { selectorUsed: this.getUsedSelector(step.selector) };
|
|
144
|
+
}
|
|
145
|
+
case "check": {
|
|
146
|
+
if (!step.selector) throw new Error("check requires selector");
|
|
147
|
+
await this.page.check(step.selector, { timeout, optional });
|
|
148
|
+
return { selectorUsed: this.getUsedSelector(step.selector) };
|
|
149
|
+
}
|
|
150
|
+
case "uncheck": {
|
|
151
|
+
if (!step.selector) throw new Error("uncheck requires selector");
|
|
152
|
+
await this.page.uncheck(step.selector, { timeout, optional });
|
|
153
|
+
return { selectorUsed: this.getUsedSelector(step.selector) };
|
|
154
|
+
}
|
|
155
|
+
case "submit": {
|
|
156
|
+
if (!step.selector) throw new Error("submit requires selector");
|
|
157
|
+
await this.page.submit(step.selector, {
|
|
158
|
+
timeout,
|
|
159
|
+
optional,
|
|
160
|
+
method: step.method ?? "enter+click"
|
|
161
|
+
});
|
|
162
|
+
return { selectorUsed: this.getUsedSelector(step.selector) };
|
|
163
|
+
}
|
|
164
|
+
case "press": {
|
|
165
|
+
if (!step.key) throw new Error("press requires key");
|
|
166
|
+
await this.page.press(step.key);
|
|
167
|
+
return {};
|
|
168
|
+
}
|
|
169
|
+
case "focus": {
|
|
170
|
+
if (!step.selector) throw new Error("focus requires selector");
|
|
171
|
+
await this.page.focus(step.selector, { timeout, optional });
|
|
172
|
+
return { selectorUsed: this.getUsedSelector(step.selector) };
|
|
173
|
+
}
|
|
174
|
+
case "hover": {
|
|
175
|
+
if (!step.selector) throw new Error("hover requires selector");
|
|
176
|
+
await this.page.hover(step.selector, { timeout, optional });
|
|
177
|
+
return { selectorUsed: this.getUsedSelector(step.selector) };
|
|
178
|
+
}
|
|
179
|
+
case "scroll": {
|
|
180
|
+
if (step.x !== void 0 || step.y !== void 0) {
|
|
181
|
+
await this.page.scroll("body", { x: step.x, y: step.y, timeout, optional });
|
|
182
|
+
return {};
|
|
183
|
+
}
|
|
184
|
+
if (!step.selector && (step.direction || step.amount !== void 0)) {
|
|
185
|
+
const amount = step.amount ?? 500;
|
|
186
|
+
const direction = step.direction ?? "down";
|
|
187
|
+
const deltaY = direction === "down" ? amount : direction === "up" ? -amount : 0;
|
|
188
|
+
const deltaX = direction === "right" ? amount : direction === "left" ? -amount : 0;
|
|
189
|
+
await this.page.evaluate(`window.scrollBy(${deltaX}, ${deltaY})`);
|
|
190
|
+
return {};
|
|
191
|
+
}
|
|
192
|
+
if (!step.selector) throw new Error("scroll requires selector, coordinates, or direction");
|
|
193
|
+
await this.page.scroll(step.selector, { timeout, optional });
|
|
194
|
+
return { selectorUsed: this.getUsedSelector(step.selector) };
|
|
195
|
+
}
|
|
196
|
+
case "wait": {
|
|
197
|
+
if (!step.selector && !step.waitFor) {
|
|
198
|
+
const delay = step.timeout ?? 1e3;
|
|
199
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
200
|
+
return {};
|
|
201
|
+
}
|
|
202
|
+
if (step.waitFor === "navigation") {
|
|
203
|
+
await this.page.waitForNavigation({ timeout, optional });
|
|
204
|
+
return {};
|
|
205
|
+
}
|
|
206
|
+
if (step.waitFor === "networkIdle") {
|
|
207
|
+
await this.page.waitForNetworkIdle({ timeout, optional });
|
|
208
|
+
return {};
|
|
209
|
+
}
|
|
210
|
+
if (!step.selector)
|
|
211
|
+
throw new Error(
|
|
212
|
+
"wait requires selector (or waitFor: navigation/networkIdle, or timeout for simple delay)"
|
|
213
|
+
);
|
|
214
|
+
await this.page.waitFor(step.selector, {
|
|
215
|
+
timeout,
|
|
216
|
+
optional,
|
|
217
|
+
state: step.waitFor ?? "visible"
|
|
218
|
+
});
|
|
219
|
+
return { selectorUsed: this.getUsedSelector(step.selector) };
|
|
220
|
+
}
|
|
221
|
+
case "snapshot": {
|
|
222
|
+
const snapshot = await this.page.snapshot();
|
|
223
|
+
return { value: snapshot };
|
|
224
|
+
}
|
|
225
|
+
case "screenshot": {
|
|
226
|
+
const data = await this.page.screenshot({
|
|
227
|
+
format: step.format,
|
|
228
|
+
quality: step.quality,
|
|
229
|
+
fullPage: step.fullPage
|
|
230
|
+
});
|
|
231
|
+
return { value: data };
|
|
232
|
+
}
|
|
233
|
+
case "evaluate": {
|
|
234
|
+
if (typeof step.value !== "string")
|
|
235
|
+
throw new Error("evaluate requires string value (expression)");
|
|
236
|
+
const result = await this.page.evaluate(step.value);
|
|
237
|
+
return { value: result };
|
|
238
|
+
}
|
|
239
|
+
case "text": {
|
|
240
|
+
const selector = Array.isArray(step.selector) ? step.selector[0] : step.selector;
|
|
241
|
+
const text = await this.page.text(selector);
|
|
242
|
+
return { text, selectorUsed: selector };
|
|
243
|
+
}
|
|
244
|
+
case "switchFrame": {
|
|
245
|
+
if (!step.selector) throw new Error("switchFrame requires selector");
|
|
246
|
+
await this.page.switchToFrame(step.selector, { timeout, optional });
|
|
247
|
+
return { selectorUsed: this.getUsedSelector(step.selector) };
|
|
248
|
+
}
|
|
249
|
+
case "switchToMain": {
|
|
250
|
+
await this.page.switchToMain();
|
|
251
|
+
return {};
|
|
252
|
+
}
|
|
253
|
+
default:
|
|
254
|
+
throw new Error(
|
|
255
|
+
`Unknown action: ${step.action}. Run 'bp actions' for available actions.`
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Get the first selector if multiple were provided
|
|
261
|
+
* (actual used selector tracking would need to be implemented in Page)
|
|
262
|
+
*/
|
|
263
|
+
getUsedSelector(selector) {
|
|
264
|
+
return Array.isArray(selector) ? selector[0] : selector;
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
function addBatchToPage(page) {
|
|
268
|
+
const executor = new BatchExecutor(page);
|
|
269
|
+
return Object.assign(page, {
|
|
270
|
+
batch: (steps, options) => executor.execute(steps, options)
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
274
|
+
0 && (module.exports = {
|
|
275
|
+
BatchExecutor,
|
|
276
|
+
addBatchToPage
|
|
277
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { P as Page, S as Step, B as BatchOptions, b as BatchResult } from './types-Cs89wle0.cjs';
|
|
2
|
+
export { A as ActionType, c as StepResult } from './types-Cs89wle0.cjs';
|
|
3
|
+
import './client-7Nqka5MV.cjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Batch action executor
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
declare class BatchExecutor {
|
|
10
|
+
private page;
|
|
11
|
+
constructor(page: Page);
|
|
12
|
+
/**
|
|
13
|
+
* Execute a batch of steps
|
|
14
|
+
*/
|
|
15
|
+
execute(steps: Step[], options?: BatchOptions): Promise<BatchResult>;
|
|
16
|
+
/**
|
|
17
|
+
* Execute a single step
|
|
18
|
+
*/
|
|
19
|
+
private executeStep;
|
|
20
|
+
/**
|
|
21
|
+
* Get the first selector if multiple were provided
|
|
22
|
+
* (actual used selector tracking would need to be implemented in Page)
|
|
23
|
+
*/
|
|
24
|
+
private getUsedSelector;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Add batch execution capability to Page class
|
|
28
|
+
*/
|
|
29
|
+
declare function addBatchToPage(page: Page): Page & {
|
|
30
|
+
batch: (steps: Step[], options?: BatchOptions) => Promise<BatchResult>;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export { BatchExecutor, BatchOptions, BatchResult, Step, addBatchToPage };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { P as Page, S as Step, B as BatchOptions, b as BatchResult } from './types-DL_-3BZk.js';
|
|
2
|
+
export { A as ActionType, c as StepResult } from './types-DL_-3BZk.js';
|
|
3
|
+
import './client-7Nqka5MV.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Batch action executor
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
declare class BatchExecutor {
|
|
10
|
+
private page;
|
|
11
|
+
constructor(page: Page);
|
|
12
|
+
/**
|
|
13
|
+
* Execute a batch of steps
|
|
14
|
+
*/
|
|
15
|
+
execute(steps: Step[], options?: BatchOptions): Promise<BatchResult>;
|
|
16
|
+
/**
|
|
17
|
+
* Execute a single step
|
|
18
|
+
*/
|
|
19
|
+
private executeStep;
|
|
20
|
+
/**
|
|
21
|
+
* Get the first selector if multiple were provided
|
|
22
|
+
* (actual used selector tracking would need to be implemented in Page)
|
|
23
|
+
*/
|
|
24
|
+
private getUsedSelector;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Add batch execution capability to Page class
|
|
28
|
+
*/
|
|
29
|
+
declare function addBatchToPage(page: Page): Page & {
|
|
30
|
+
batch: (steps: Step[], options?: BatchOptions) => Promise<BatchResult>;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export { BatchExecutor, BatchOptions, BatchResult, Step, addBatchToPage };
|