browser-pilot 0.0.7 → 0.0.9
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 +61 -1
- package/dist/actions.cjs +485 -9
- package/dist/actions.d.cts +24 -5
- package/dist/actions.d.ts +24 -5
- package/dist/actions.mjs +5 -3
- package/dist/browser.cjs +1761 -102
- package/dist/browser.d.cts +8 -4
- package/dist/browser.d.ts +8 -4
- package/dist/browser.mjs +6 -5
- package/dist/{chunk-PCNEJAJ7.mjs → chunk-7OSR2CAE.mjs} +1756 -46
- package/dist/chunk-KKW2SZLV.mjs +741 -0
- package/dist/cli.mjs +7576 -265
- package/dist/index.cjs +2434 -108
- package/dist/index.d.cts +142 -6
- package/dist/index.d.ts +142 -6
- package/dist/index.mjs +360 -13
- package/dist/providers.d.cts +2 -2
- package/dist/providers.d.ts +2 -2
- package/dist/{types-D_uDqh0Z.d.cts → types--wXNHUwt.d.cts} +1 -1
- package/dist/{types-D_uDqh0Z.d.ts → types--wXNHUwt.d.ts} +1 -1
- package/dist/{types-TVlTA7nH.d.cts → types-CYw-7vx1.d.cts} +280 -3
- package/dist/{types-CbdmaocU.d.ts → types-DOGsEYQa.d.ts} +280 -3
- package/package.json +3 -3
- package/dist/chunk-6RB3GKQP.mjs +0 -251
- package/dist/chunk-ZIQA4JOT.mjs +0 -226
- package/dist/cli.cjs +0 -4792
- package/dist/cli.d.cts +0 -25
- package/dist/cli.d.ts +0 -25
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "browser-pilot",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "Lightweight CDP-based browser automation for Node.js, Bun, and Cloudflare Workers",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -34,8 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"./cli": {
|
|
36
36
|
"types": "./dist/cli.d.ts",
|
|
37
|
-
"import": "./dist/cli.mjs"
|
|
38
|
-
"require": "./dist/cli.cjs"
|
|
37
|
+
"import": "./dist/cli.mjs"
|
|
39
38
|
}
|
|
40
39
|
},
|
|
41
40
|
"bin": {
|
|
@@ -62,6 +61,7 @@
|
|
|
62
61
|
"check": "bun run typecheck && bun run lint",
|
|
63
62
|
"prepublishOnly": "bun run build",
|
|
64
63
|
"bp": "bun ./src/cli/index.ts",
|
|
64
|
+
"dev:bp": "bun ./src/cli/index.ts",
|
|
65
65
|
"browser-pilot": "bun ./src/cli/index.ts",
|
|
66
66
|
"fixtures:serve": "bun tests/fixtures/server.ts"
|
|
67
67
|
},
|
package/dist/chunk-6RB3GKQP.mjs
DELETED
|
@@ -1,251 +0,0 @@
|
|
|
1
|
-
// src/actions/executor.ts
|
|
2
|
-
var DEFAULT_TIMEOUT = 3e4;
|
|
3
|
-
var BatchExecutor = class {
|
|
4
|
-
page;
|
|
5
|
-
constructor(page) {
|
|
6
|
-
this.page = page;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Execute a batch of steps
|
|
10
|
-
*/
|
|
11
|
-
async execute(steps, options = {}) {
|
|
12
|
-
const { timeout = DEFAULT_TIMEOUT, onFail = "stop" } = options;
|
|
13
|
-
const results = [];
|
|
14
|
-
const startTime = Date.now();
|
|
15
|
-
for (let i = 0; i < steps.length; i++) {
|
|
16
|
-
const step = steps[i];
|
|
17
|
-
const stepStart = Date.now();
|
|
18
|
-
try {
|
|
19
|
-
const result = await this.executeStep(step, timeout);
|
|
20
|
-
results.push({
|
|
21
|
-
index: i,
|
|
22
|
-
action: step.action,
|
|
23
|
-
selector: step.selector,
|
|
24
|
-
selectorUsed: result.selectorUsed,
|
|
25
|
-
success: true,
|
|
26
|
-
durationMs: Date.now() - stepStart,
|
|
27
|
-
result: result.value,
|
|
28
|
-
text: result.text
|
|
29
|
-
});
|
|
30
|
-
} catch (error) {
|
|
31
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
32
|
-
results.push({
|
|
33
|
-
index: i,
|
|
34
|
-
action: step.action,
|
|
35
|
-
selector: step.selector,
|
|
36
|
-
success: false,
|
|
37
|
-
durationMs: Date.now() - stepStart,
|
|
38
|
-
error: errorMessage
|
|
39
|
-
});
|
|
40
|
-
if (onFail === "stop" && !step.optional) {
|
|
41
|
-
return {
|
|
42
|
-
success: false,
|
|
43
|
-
stoppedAtIndex: i,
|
|
44
|
-
steps: results,
|
|
45
|
-
totalDurationMs: Date.now() - startTime
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
const allSuccess = results.every((r) => r.success || steps[r.index]?.optional);
|
|
51
|
-
return {
|
|
52
|
-
success: allSuccess,
|
|
53
|
-
steps: results,
|
|
54
|
-
totalDurationMs: Date.now() - startTime
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Execute a single step
|
|
59
|
-
*/
|
|
60
|
-
async executeStep(step, defaultTimeout) {
|
|
61
|
-
const timeout = step.timeout ?? defaultTimeout;
|
|
62
|
-
const optional = step.optional ?? false;
|
|
63
|
-
switch (step.action) {
|
|
64
|
-
case "goto": {
|
|
65
|
-
if (!step.url) throw new Error("goto requires url");
|
|
66
|
-
await this.page.goto(step.url, { timeout, optional });
|
|
67
|
-
return {};
|
|
68
|
-
}
|
|
69
|
-
case "click": {
|
|
70
|
-
if (!step.selector) throw new Error("click requires selector");
|
|
71
|
-
if (step.waitForNavigation) {
|
|
72
|
-
const navPromise = this.page.waitForNavigation({ timeout, optional });
|
|
73
|
-
await this.page.click(step.selector, { timeout, optional });
|
|
74
|
-
await navPromise;
|
|
75
|
-
} else {
|
|
76
|
-
await this.page.click(step.selector, { timeout, optional });
|
|
77
|
-
}
|
|
78
|
-
return { selectorUsed: this.getUsedSelector(step.selector) };
|
|
79
|
-
}
|
|
80
|
-
case "fill": {
|
|
81
|
-
if (!step.selector) throw new Error("fill requires selector");
|
|
82
|
-
if (typeof step.value !== "string") throw new Error("fill requires string value");
|
|
83
|
-
await this.page.fill(step.selector, step.value, {
|
|
84
|
-
timeout,
|
|
85
|
-
optional,
|
|
86
|
-
clear: step.clear ?? true,
|
|
87
|
-
blur: step.blur
|
|
88
|
-
});
|
|
89
|
-
return { selectorUsed: this.getUsedSelector(step.selector) };
|
|
90
|
-
}
|
|
91
|
-
case "type": {
|
|
92
|
-
if (!step.selector) throw new Error("type requires selector");
|
|
93
|
-
if (typeof step.value !== "string") throw new Error("type requires string value");
|
|
94
|
-
await this.page.type(step.selector, step.value, {
|
|
95
|
-
timeout,
|
|
96
|
-
optional,
|
|
97
|
-
delay: step.delay ?? 50
|
|
98
|
-
});
|
|
99
|
-
return { selectorUsed: this.getUsedSelector(step.selector) };
|
|
100
|
-
}
|
|
101
|
-
case "select": {
|
|
102
|
-
if (step.trigger && step.option && typeof step.value === "string") {
|
|
103
|
-
await this.page.select(
|
|
104
|
-
{
|
|
105
|
-
trigger: step.trigger,
|
|
106
|
-
option: step.option,
|
|
107
|
-
value: step.value,
|
|
108
|
-
match: step.match
|
|
109
|
-
},
|
|
110
|
-
{ timeout, optional }
|
|
111
|
-
);
|
|
112
|
-
return { selectorUsed: this.getUsedSelector(step.trigger) };
|
|
113
|
-
}
|
|
114
|
-
if (!step.selector) throw new Error("select requires selector");
|
|
115
|
-
if (!step.value) throw new Error("select requires value");
|
|
116
|
-
await this.page.select(step.selector, step.value, { timeout, optional });
|
|
117
|
-
return { selectorUsed: this.getUsedSelector(step.selector) };
|
|
118
|
-
}
|
|
119
|
-
case "check": {
|
|
120
|
-
if (!step.selector) throw new Error("check requires selector");
|
|
121
|
-
await this.page.check(step.selector, { timeout, optional });
|
|
122
|
-
return { selectorUsed: this.getUsedSelector(step.selector) };
|
|
123
|
-
}
|
|
124
|
-
case "uncheck": {
|
|
125
|
-
if (!step.selector) throw new Error("uncheck requires selector");
|
|
126
|
-
await this.page.uncheck(step.selector, { timeout, optional });
|
|
127
|
-
return { selectorUsed: this.getUsedSelector(step.selector) };
|
|
128
|
-
}
|
|
129
|
-
case "submit": {
|
|
130
|
-
if (!step.selector) throw new Error("submit requires selector");
|
|
131
|
-
await this.page.submit(step.selector, {
|
|
132
|
-
timeout,
|
|
133
|
-
optional,
|
|
134
|
-
method: step.method ?? "enter+click"
|
|
135
|
-
});
|
|
136
|
-
return { selectorUsed: this.getUsedSelector(step.selector) };
|
|
137
|
-
}
|
|
138
|
-
case "press": {
|
|
139
|
-
if (!step.key) throw new Error("press requires key");
|
|
140
|
-
await this.page.press(step.key);
|
|
141
|
-
return {};
|
|
142
|
-
}
|
|
143
|
-
case "focus": {
|
|
144
|
-
if (!step.selector) throw new Error("focus requires selector");
|
|
145
|
-
await this.page.focus(step.selector, { timeout, optional });
|
|
146
|
-
return { selectorUsed: this.getUsedSelector(step.selector) };
|
|
147
|
-
}
|
|
148
|
-
case "hover": {
|
|
149
|
-
if (!step.selector) throw new Error("hover requires selector");
|
|
150
|
-
await this.page.hover(step.selector, { timeout, optional });
|
|
151
|
-
return { selectorUsed: this.getUsedSelector(step.selector) };
|
|
152
|
-
}
|
|
153
|
-
case "scroll": {
|
|
154
|
-
if (step.x !== void 0 || step.y !== void 0) {
|
|
155
|
-
await this.page.scroll("body", { x: step.x, y: step.y, timeout, optional });
|
|
156
|
-
return {};
|
|
157
|
-
}
|
|
158
|
-
if (!step.selector && (step.direction || step.amount !== void 0)) {
|
|
159
|
-
const amount = step.amount ?? 500;
|
|
160
|
-
const direction = step.direction ?? "down";
|
|
161
|
-
const deltaY = direction === "down" ? amount : direction === "up" ? -amount : 0;
|
|
162
|
-
const deltaX = direction === "right" ? amount : direction === "left" ? -amount : 0;
|
|
163
|
-
await this.page.evaluate(`window.scrollBy(${deltaX}, ${deltaY})`);
|
|
164
|
-
return {};
|
|
165
|
-
}
|
|
166
|
-
if (!step.selector) throw new Error("scroll requires selector, coordinates, or direction");
|
|
167
|
-
await this.page.scroll(step.selector, { timeout, optional });
|
|
168
|
-
return { selectorUsed: this.getUsedSelector(step.selector) };
|
|
169
|
-
}
|
|
170
|
-
case "wait": {
|
|
171
|
-
if (!step.selector && !step.waitFor) {
|
|
172
|
-
const delay = step.timeout ?? 1e3;
|
|
173
|
-
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
174
|
-
return {};
|
|
175
|
-
}
|
|
176
|
-
if (step.waitFor === "navigation") {
|
|
177
|
-
await this.page.waitForNavigation({ timeout, optional });
|
|
178
|
-
return {};
|
|
179
|
-
}
|
|
180
|
-
if (step.waitFor === "networkIdle") {
|
|
181
|
-
await this.page.waitForNetworkIdle({ timeout, optional });
|
|
182
|
-
return {};
|
|
183
|
-
}
|
|
184
|
-
if (!step.selector)
|
|
185
|
-
throw new Error(
|
|
186
|
-
"wait requires selector (or waitFor: navigation/networkIdle, or timeout for simple delay)"
|
|
187
|
-
);
|
|
188
|
-
await this.page.waitFor(step.selector, {
|
|
189
|
-
timeout,
|
|
190
|
-
optional,
|
|
191
|
-
state: step.waitFor ?? "visible"
|
|
192
|
-
});
|
|
193
|
-
return { selectorUsed: this.getUsedSelector(step.selector) };
|
|
194
|
-
}
|
|
195
|
-
case "snapshot": {
|
|
196
|
-
const snapshot = await this.page.snapshot();
|
|
197
|
-
return { value: snapshot };
|
|
198
|
-
}
|
|
199
|
-
case "screenshot": {
|
|
200
|
-
const data = await this.page.screenshot({
|
|
201
|
-
format: step.format,
|
|
202
|
-
quality: step.quality,
|
|
203
|
-
fullPage: step.fullPage
|
|
204
|
-
});
|
|
205
|
-
return { value: data };
|
|
206
|
-
}
|
|
207
|
-
case "evaluate": {
|
|
208
|
-
if (typeof step.value !== "string")
|
|
209
|
-
throw new Error("evaluate requires string value (expression)");
|
|
210
|
-
const result = await this.page.evaluate(step.value);
|
|
211
|
-
return { value: result };
|
|
212
|
-
}
|
|
213
|
-
case "text": {
|
|
214
|
-
const selector = Array.isArray(step.selector) ? step.selector[0] : step.selector;
|
|
215
|
-
const text = await this.page.text(selector);
|
|
216
|
-
return { text, selectorUsed: selector };
|
|
217
|
-
}
|
|
218
|
-
case "switchFrame": {
|
|
219
|
-
if (!step.selector) throw new Error("switchFrame requires selector");
|
|
220
|
-
await this.page.switchToFrame(step.selector, { timeout, optional });
|
|
221
|
-
return { selectorUsed: this.getUsedSelector(step.selector) };
|
|
222
|
-
}
|
|
223
|
-
case "switchToMain": {
|
|
224
|
-
await this.page.switchToMain();
|
|
225
|
-
return {};
|
|
226
|
-
}
|
|
227
|
-
default:
|
|
228
|
-
throw new Error(
|
|
229
|
-
`Unknown action: ${step.action}. Run 'bp actions' for available actions.`
|
|
230
|
-
);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
/**
|
|
234
|
-
* Get the first selector if multiple were provided
|
|
235
|
-
* (actual used selector tracking would need to be implemented in Page)
|
|
236
|
-
*/
|
|
237
|
-
getUsedSelector(selector) {
|
|
238
|
-
return Array.isArray(selector) ? selector[0] : selector;
|
|
239
|
-
}
|
|
240
|
-
};
|
|
241
|
-
function addBatchToPage(page) {
|
|
242
|
-
const executor = new BatchExecutor(page);
|
|
243
|
-
return Object.assign(page, {
|
|
244
|
-
batch: (steps, options) => executor.execute(steps, options)
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
export {
|
|
249
|
-
BatchExecutor,
|
|
250
|
-
addBatchToPage
|
|
251
|
-
};
|
package/dist/chunk-ZIQA4JOT.mjs
DELETED
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
// src/emulation/devices.ts
|
|
2
|
-
var devices = {
|
|
3
|
-
"iPhone 14": {
|
|
4
|
-
name: "iPhone 14",
|
|
5
|
-
viewport: {
|
|
6
|
-
width: 390,
|
|
7
|
-
height: 844,
|
|
8
|
-
deviceScaleFactor: 3,
|
|
9
|
-
isMobile: true,
|
|
10
|
-
hasTouch: true
|
|
11
|
-
},
|
|
12
|
-
userAgent: {
|
|
13
|
-
userAgent: "Mozilla/5.0 (iPhone; CPU iPhone OS 16_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Mobile/15E148 Safari/604.1",
|
|
14
|
-
platform: "iPhone",
|
|
15
|
-
userAgentMetadata: {
|
|
16
|
-
mobile: true,
|
|
17
|
-
platform: "iOS",
|
|
18
|
-
platformVersion: "16.0"
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
"iPhone 14 Pro Max": {
|
|
23
|
-
name: "iPhone 14 Pro Max",
|
|
24
|
-
viewport: {
|
|
25
|
-
width: 430,
|
|
26
|
-
height: 932,
|
|
27
|
-
deviceScaleFactor: 3,
|
|
28
|
-
isMobile: true,
|
|
29
|
-
hasTouch: true
|
|
30
|
-
},
|
|
31
|
-
userAgent: {
|
|
32
|
-
userAgent: "Mozilla/5.0 (iPhone; CPU iPhone OS 16_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Mobile/15E148 Safari/604.1",
|
|
33
|
-
platform: "iPhone"
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
"Pixel 7": {
|
|
37
|
-
name: "Pixel 7",
|
|
38
|
-
viewport: {
|
|
39
|
-
width: 412,
|
|
40
|
-
height: 915,
|
|
41
|
-
deviceScaleFactor: 2.625,
|
|
42
|
-
isMobile: true,
|
|
43
|
-
hasTouch: true
|
|
44
|
-
},
|
|
45
|
-
userAgent: {
|
|
46
|
-
userAgent: "Mozilla/5.0 (Linux; Android 13; Pixel 7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36",
|
|
47
|
-
platform: "Linux armv8l",
|
|
48
|
-
userAgentMetadata: {
|
|
49
|
-
mobile: true,
|
|
50
|
-
platform: "Android",
|
|
51
|
-
platformVersion: "13",
|
|
52
|
-
model: "Pixel 7"
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
"iPad Pro 11": {
|
|
57
|
-
name: "iPad Pro 11",
|
|
58
|
-
viewport: {
|
|
59
|
-
width: 834,
|
|
60
|
-
height: 1194,
|
|
61
|
-
deviceScaleFactor: 2,
|
|
62
|
-
isMobile: true,
|
|
63
|
-
hasTouch: true
|
|
64
|
-
},
|
|
65
|
-
userAgent: {
|
|
66
|
-
userAgent: "Mozilla/5.0 (iPad; CPU OS 16_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Mobile/15E148 Safari/604.1",
|
|
67
|
-
platform: "iPad"
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
"Desktop Chrome": {
|
|
71
|
-
name: "Desktop Chrome",
|
|
72
|
-
viewport: {
|
|
73
|
-
width: 1920,
|
|
74
|
-
height: 1080,
|
|
75
|
-
deviceScaleFactor: 1,
|
|
76
|
-
isMobile: false,
|
|
77
|
-
hasTouch: false
|
|
78
|
-
},
|
|
79
|
-
userAgent: {
|
|
80
|
-
userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
|
|
81
|
-
platform: "Win32",
|
|
82
|
-
userAgentMetadata: {
|
|
83
|
-
brands: [
|
|
84
|
-
{ brand: "Not_A Brand", version: "8" },
|
|
85
|
-
{ brand: "Chromium", version: "120" },
|
|
86
|
-
{ brand: "Google Chrome", version: "120" }
|
|
87
|
-
],
|
|
88
|
-
platform: "Windows",
|
|
89
|
-
platformVersion: "10.0.0",
|
|
90
|
-
architecture: "x86",
|
|
91
|
-
bitness: "64",
|
|
92
|
-
mobile: false
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
"Desktop Firefox": {
|
|
97
|
-
name: "Desktop Firefox",
|
|
98
|
-
viewport: {
|
|
99
|
-
width: 1920,
|
|
100
|
-
height: 1080,
|
|
101
|
-
deviceScaleFactor: 1,
|
|
102
|
-
isMobile: false,
|
|
103
|
-
hasTouch: false
|
|
104
|
-
},
|
|
105
|
-
userAgent: {
|
|
106
|
-
userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:121.0) Gecko/20100101 Firefox/121.0",
|
|
107
|
-
platform: "Win32"
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
// src/trace/tracer.ts
|
|
113
|
-
var LEVEL_ORDER = {
|
|
114
|
-
debug: 0,
|
|
115
|
-
info: 1,
|
|
116
|
-
warn: 2,
|
|
117
|
-
error: 3
|
|
118
|
-
};
|
|
119
|
-
var Tracer = class _Tracer {
|
|
120
|
-
options;
|
|
121
|
-
constructor(options = {}) {
|
|
122
|
-
this.options = {
|
|
123
|
-
enabled: options.enabled ?? false,
|
|
124
|
-
output: options.output ?? "console",
|
|
125
|
-
callback: options.callback,
|
|
126
|
-
level: options.level ?? "info",
|
|
127
|
-
includeTimings: options.includeTimings ?? true
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Emit a trace event
|
|
132
|
-
*/
|
|
133
|
-
emit(event) {
|
|
134
|
-
if (!this.options.enabled) return;
|
|
135
|
-
if (LEVEL_ORDER[event.level] < LEVEL_ORDER[this.options.level]) {
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
const fullEvent = {
|
|
139
|
-
...event,
|
|
140
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
141
|
-
};
|
|
142
|
-
switch (this.options.output) {
|
|
143
|
-
case "console":
|
|
144
|
-
this.logToConsole(fullEvent);
|
|
145
|
-
break;
|
|
146
|
-
case "callback":
|
|
147
|
-
this.options.callback?.(fullEvent);
|
|
148
|
-
break;
|
|
149
|
-
case "silent":
|
|
150
|
-
break;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Log event to console
|
|
155
|
-
*/
|
|
156
|
-
logToConsole(event) {
|
|
157
|
-
const { level, category, action, selectorUsed, success, durationMs, error } = event;
|
|
158
|
-
const icon = success === true ? "\u2713" : success === false ? "\u2717" : "\u25CB";
|
|
159
|
-
const timing = this.options.includeTimings && durationMs !== void 0 ? ` (${durationMs}ms)` : "";
|
|
160
|
-
const selector = selectorUsed ? ` ${selectorUsed}` : "";
|
|
161
|
-
const errorStr = error ? ` - ${error}` : "";
|
|
162
|
-
const message = `[${level.toUpperCase()}] [${category}] ${icon} ${action}${selector}${timing}${errorStr}`;
|
|
163
|
-
switch (level) {
|
|
164
|
-
case "debug":
|
|
165
|
-
console.debug(message);
|
|
166
|
-
break;
|
|
167
|
-
case "info":
|
|
168
|
-
console.info(message);
|
|
169
|
-
break;
|
|
170
|
-
case "warn":
|
|
171
|
-
console.warn(message);
|
|
172
|
-
break;
|
|
173
|
-
case "error":
|
|
174
|
-
console.error(message);
|
|
175
|
-
break;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Create a child tracer with modified options
|
|
180
|
-
*/
|
|
181
|
-
child(options) {
|
|
182
|
-
return new _Tracer({ ...this.options, ...options });
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* Enable tracing
|
|
186
|
-
*/
|
|
187
|
-
enable() {
|
|
188
|
-
this.options.enabled = true;
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* Disable tracing
|
|
192
|
-
*/
|
|
193
|
-
disable() {
|
|
194
|
-
this.options.enabled = false;
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Check if tracing is enabled
|
|
198
|
-
*/
|
|
199
|
-
get isEnabled() {
|
|
200
|
-
return this.options.enabled;
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
var globalTracer = null;
|
|
204
|
-
function getTracer() {
|
|
205
|
-
if (!globalTracer) {
|
|
206
|
-
globalTracer = new Tracer({ enabled: false });
|
|
207
|
-
}
|
|
208
|
-
return globalTracer;
|
|
209
|
-
}
|
|
210
|
-
function enableTracing(options = {}) {
|
|
211
|
-
globalTracer = new Tracer({ ...options, enabled: true });
|
|
212
|
-
return globalTracer;
|
|
213
|
-
}
|
|
214
|
-
function disableTracing() {
|
|
215
|
-
if (globalTracer) {
|
|
216
|
-
globalTracer.disable();
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
export {
|
|
221
|
-
devices,
|
|
222
|
-
Tracer,
|
|
223
|
-
getTracer,
|
|
224
|
-
enableTracing,
|
|
225
|
-
disableTracing
|
|
226
|
-
};
|