btcp-browser-agent 0.1.0 → 0.1.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/package.json +8 -9
- package/packages/core/dist/actions.d.ts +97 -0
- package/packages/core/dist/actions.js +940 -0
- package/packages/core/dist/errors.d.ts +138 -0
- package/packages/core/dist/errors.js +157 -0
- package/packages/core/dist/index.d.ts +120 -0
- package/packages/core/dist/index.js +134 -0
- package/packages/core/dist/ref-map.d.ts +16 -0
- package/packages/core/dist/ref-map.js +91 -0
- package/packages/core/dist/snapshot.d.ts +37 -0
- package/packages/core/dist/snapshot.js +751 -0
- package/packages/core/dist/types.d.ts +396 -0
- package/packages/core/dist/types.js +7 -0
- package/packages/extension/dist/background.d.ts +227 -0
- package/packages/extension/dist/background.js +737 -0
- package/packages/extension/dist/content.d.ts +18 -0
- package/packages/extension/dist/content.js +149 -0
- package/packages/extension/dist/index.d.ts +228 -0
- package/packages/extension/dist/index.js +350 -0
- package/packages/extension/dist/session-manager.d.ts +87 -0
- package/packages/extension/dist/session-manager.js +322 -0
- package/packages/extension/{src/session-types.ts → dist/session-types.d.ts} +113 -144
- package/packages/extension/dist/session-types.js +5 -0
- package/packages/extension/dist/types.d.ts +88 -0
- package/packages/extension/dist/types.js +7 -0
- package/CLAUDE.md +0 -230
- package/SKILL.md +0 -143
- package/SNAPSHOT_IMPROVEMENTS.md +0 -302
- package/USAGE.md +0 -146
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/docs/browser-cli-design.md +0 -500
- package/examples/chrome-extension/CHANGELOG.md +0 -210
- package/examples/chrome-extension/DEBUG.md +0 -231
- package/examples/chrome-extension/ERROR_FIXED.md +0 -147
- package/examples/chrome-extension/QUICK_TEST.md +0 -189
- package/examples/chrome-extension/README.md +0 -149
- package/examples/chrome-extension/SESSION_ONLY_MODE.md +0 -305
- package/examples/chrome-extension/TEST_WITH_YOUR_TABS.md +0 -97
- package/examples/chrome-extension/build.js +0 -43
- package/examples/chrome-extension/manifest.json +0 -37
- package/examples/chrome-extension/package-lock.json +0 -1063
- package/examples/chrome-extension/package.json +0 -21
- package/examples/chrome-extension/popup.html +0 -195
- package/examples/chrome-extension/src/background.ts +0 -12
- package/examples/chrome-extension/src/content.ts +0 -7
- package/examples/chrome-extension/src/popup.ts +0 -303
- package/examples/chrome-extension/src/scenario-google-github.ts +0 -389
- package/examples/chrome-extension/test-page.html +0 -127
- package/examples/chrome-extension/tests/README.md +0 -206
- package/examples/chrome-extension/tests/scenario-google-to-github-star.ts +0 -380
- package/examples/chrome-extension/tsconfig.json +0 -14
- package/examples/snapshots/README.md +0 -207
- package/examples/snapshots/amazon-com-detail.html +0 -9528
- package/examples/snapshots/amazon-com-detail.snapshot.txt +0 -997
- package/examples/snapshots/convert-snapshots.ts +0 -97
- package/examples/snapshots/edition-cnn-com.html +0 -13292
- package/examples/snapshots/edition-cnn-com.snapshot.txt +0 -562
- package/examples/snapshots/github-com-microsoft-vscode.html +0 -2916
- package/examples/snapshots/github-com-microsoft-vscode.snapshot.txt +0 -455
- package/examples/snapshots/google-search.html +0 -20012
- package/examples/snapshots/google-search.snapshot.txt +0 -195
- package/examples/snapshots/metadata.json +0 -86
- package/examples/snapshots/npr-org-templates.html +0 -2031
- package/examples/snapshots/npr-org-templates.snapshot.txt +0 -224
- package/examples/snapshots/stackoverflow-com.html +0 -5216
- package/examples/snapshots/stackoverflow-com.snapshot.txt +0 -2404
- package/examples/snapshots/test-all-mode.html +0 -46
- package/examples/snapshots/test-all-mode.snapshot.txt +0 -5
- package/examples/snapshots/validate.test.ts +0 -296
- package/packages/cli/package.json +0 -42
- package/packages/cli/src/__tests__/cli.test.ts +0 -434
- package/packages/cli/src/__tests__/errors.test.ts +0 -226
- package/packages/cli/src/__tests__/executor.test.ts +0 -275
- package/packages/cli/src/__tests__/formatter.test.ts +0 -260
- package/packages/cli/src/__tests__/parser.test.ts +0 -288
- package/packages/cli/src/__tests__/suggestions.test.ts +0 -255
- package/packages/cli/src/commands/back.ts +0 -22
- package/packages/cli/src/commands/check.ts +0 -33
- package/packages/cli/src/commands/clear.ts +0 -33
- package/packages/cli/src/commands/click.ts +0 -32
- package/packages/cli/src/commands/closetab.ts +0 -31
- package/packages/cli/src/commands/eval.ts +0 -41
- package/packages/cli/src/commands/fill.ts +0 -30
- package/packages/cli/src/commands/focus.ts +0 -33
- package/packages/cli/src/commands/forward.ts +0 -22
- package/packages/cli/src/commands/goto.ts +0 -34
- package/packages/cli/src/commands/help.ts +0 -162
- package/packages/cli/src/commands/hover.ts +0 -34
- package/packages/cli/src/commands/index.ts +0 -129
- package/packages/cli/src/commands/newtab.ts +0 -35
- package/packages/cli/src/commands/press.ts +0 -40
- package/packages/cli/src/commands/reload.ts +0 -25
- package/packages/cli/src/commands/screenshot.ts +0 -27
- package/packages/cli/src/commands/scroll.ts +0 -64
- package/packages/cli/src/commands/select.ts +0 -35
- package/packages/cli/src/commands/snapshot.ts +0 -21
- package/packages/cli/src/commands/tab.ts +0 -32
- package/packages/cli/src/commands/tabs.ts +0 -26
- package/packages/cli/src/commands/text.ts +0 -27
- package/packages/cli/src/commands/title.ts +0 -17
- package/packages/cli/src/commands/type.ts +0 -38
- package/packages/cli/src/commands/uncheck.ts +0 -33
- package/packages/cli/src/commands/url.ts +0 -17
- package/packages/cli/src/commands/wait.ts +0 -54
- package/packages/cli/src/errors.ts +0 -164
- package/packages/cli/src/executor.ts +0 -68
- package/packages/cli/src/formatter.ts +0 -215
- package/packages/cli/src/index.ts +0 -257
- package/packages/cli/src/parser.ts +0 -195
- package/packages/cli/src/suggestions.ts +0 -207
- package/packages/cli/src/terminal/Terminal.ts +0 -365
- package/packages/cli/src/terminal/index.ts +0 -5
- package/packages/cli/src/types.ts +0 -155
- package/packages/cli/tsconfig.json +0 -20
- package/packages/core/package.json +0 -35
- package/packages/core/src/actions.ts +0 -1210
- package/packages/core/src/errors.ts +0 -296
- package/packages/core/src/index.test.ts +0 -638
- package/packages/core/src/index.ts +0 -220
- package/packages/core/src/ref-map.ts +0 -107
- package/packages/core/src/snapshot.ts +0 -873
- package/packages/core/src/types.ts +0 -536
- package/packages/core/tsconfig.json +0 -23
- package/packages/extension/README.md +0 -129
- package/packages/extension/package.json +0 -43
- package/packages/extension/src/background.ts +0 -888
- package/packages/extension/src/content.ts +0 -172
- package/packages/extension/src/index.ts +0 -579
- package/packages/extension/src/session-manager.ts +0 -385
- package/packages/extension/src/types.ts +0 -162
- package/packages/extension/tsconfig.json +0 -28
- package/src/index.ts +0 -64
- package/tsconfig.build.json +0 -12
- package/tsconfig.json +0 -26
- package/vitest.config.ts +0 -13
|
@@ -1,536 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @btcp/core - Type definitions
|
|
3
|
-
*
|
|
4
|
-
* Core types for DOM automation commands and responses.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
// Command types - what the core package can handle
|
|
8
|
-
export type CoreAction =
|
|
9
|
-
// Element interaction
|
|
10
|
-
| 'click'
|
|
11
|
-
| 'dblclick'
|
|
12
|
-
| 'type'
|
|
13
|
-
| 'fill'
|
|
14
|
-
| 'clear'
|
|
15
|
-
| 'check'
|
|
16
|
-
| 'uncheck'
|
|
17
|
-
| 'select'
|
|
18
|
-
| 'focus'
|
|
19
|
-
| 'blur'
|
|
20
|
-
| 'hover'
|
|
21
|
-
| 'scroll'
|
|
22
|
-
| 'scrollIntoView'
|
|
23
|
-
// DOM reading
|
|
24
|
-
| 'snapshot'
|
|
25
|
-
| 'querySelector'
|
|
26
|
-
| 'querySelectorAll'
|
|
27
|
-
| 'getText'
|
|
28
|
-
| 'getAttribute'
|
|
29
|
-
| 'getProperty'
|
|
30
|
-
| 'getBoundingBox'
|
|
31
|
-
| 'isVisible'
|
|
32
|
-
| 'isEnabled'
|
|
33
|
-
| 'isChecked'
|
|
34
|
-
// Keyboard/Mouse
|
|
35
|
-
| 'press'
|
|
36
|
-
| 'keyDown'
|
|
37
|
-
| 'keyUp'
|
|
38
|
-
// Utility
|
|
39
|
-
| 'wait'
|
|
40
|
-
| 'evaluate'
|
|
41
|
-
// Validation
|
|
42
|
-
| 'validateElement'
|
|
43
|
-
| 'validateRefs'
|
|
44
|
-
// Visualization
|
|
45
|
-
| 'highlight'
|
|
46
|
-
| 'clearHighlight';
|
|
47
|
-
|
|
48
|
-
// Base command structure
|
|
49
|
-
export interface BaseCommand {
|
|
50
|
-
id: string;
|
|
51
|
-
action: CoreAction;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// Element selector - supports CSS, ref, or semantic selectors
|
|
55
|
-
export type Selector = string;
|
|
56
|
-
|
|
57
|
-
// Command definitions
|
|
58
|
-
export interface ClickCommand extends BaseCommand {
|
|
59
|
-
action: 'click';
|
|
60
|
-
selector: Selector;
|
|
61
|
-
button?: 'left' | 'right' | 'middle';
|
|
62
|
-
clickCount?: number;
|
|
63
|
-
modifiers?: Modifier[];
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export interface DblClickCommand extends BaseCommand {
|
|
67
|
-
action: 'dblclick';
|
|
68
|
-
selector: Selector;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export interface TypeCommand extends BaseCommand {
|
|
72
|
-
action: 'type';
|
|
73
|
-
selector: Selector;
|
|
74
|
-
text: string;
|
|
75
|
-
delay?: number;
|
|
76
|
-
clear?: boolean;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export interface FillCommand extends BaseCommand {
|
|
80
|
-
action: 'fill';
|
|
81
|
-
selector: Selector;
|
|
82
|
-
value: string;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export interface ClearCommand extends BaseCommand {
|
|
86
|
-
action: 'clear';
|
|
87
|
-
selector: Selector;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export interface CheckCommand extends BaseCommand {
|
|
91
|
-
action: 'check';
|
|
92
|
-
selector: Selector;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export interface UncheckCommand extends BaseCommand {
|
|
96
|
-
action: 'uncheck';
|
|
97
|
-
selector: Selector;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export interface SelectCommand extends BaseCommand {
|
|
101
|
-
action: 'select';
|
|
102
|
-
selector: Selector;
|
|
103
|
-
values: string | string[];
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export interface FocusCommand extends BaseCommand {
|
|
107
|
-
action: 'focus';
|
|
108
|
-
selector: Selector;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export interface BlurCommand extends BaseCommand {
|
|
112
|
-
action: 'blur';
|
|
113
|
-
selector: Selector;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export interface HoverCommand extends BaseCommand {
|
|
117
|
-
action: 'hover';
|
|
118
|
-
selector: Selector;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export interface ScrollCommand extends BaseCommand {
|
|
122
|
-
action: 'scroll';
|
|
123
|
-
selector?: Selector;
|
|
124
|
-
x?: number;
|
|
125
|
-
y?: number;
|
|
126
|
-
direction?: 'up' | 'down' | 'left' | 'right';
|
|
127
|
-
amount?: number;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export interface ScrollIntoViewCommand extends BaseCommand {
|
|
131
|
-
action: 'scrollIntoView';
|
|
132
|
-
selector: Selector;
|
|
133
|
-
block?: 'start' | 'center' | 'end' | 'nearest';
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Grep options for filtering snapshot output (mirrors Unix grep flags)
|
|
138
|
-
*/
|
|
139
|
-
export interface GrepOptions {
|
|
140
|
-
/** Pattern to search for (regex by default) */
|
|
141
|
-
pattern: string;
|
|
142
|
-
/** Case-insensitive matching (grep -i) */
|
|
143
|
-
ignoreCase?: boolean;
|
|
144
|
-
/** Invert match - return non-matching lines (grep -v) */
|
|
145
|
-
invert?: boolean;
|
|
146
|
-
/** Treat pattern as fixed string, not regex (grep -F) */
|
|
147
|
-
fixedStrings?: boolean;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export interface SnapshotCommand extends BaseCommand {
|
|
151
|
-
action: 'snapshot';
|
|
152
|
-
selector?: Selector;
|
|
153
|
-
maxDepth?: number;
|
|
154
|
-
includeHidden?: boolean;
|
|
155
|
-
interactive?: boolean;
|
|
156
|
-
compact?: boolean;
|
|
157
|
-
minDepth?: number;
|
|
158
|
-
samplingStrategy?: 'importance' | 'balanced' | 'depth-first';
|
|
159
|
-
contentPreview?: boolean;
|
|
160
|
-
landmarks?: boolean;
|
|
161
|
-
incremental?: boolean;
|
|
162
|
-
baseSnapshot?: SnapshotData;
|
|
163
|
-
all?: boolean;
|
|
164
|
-
format?: 'tree' | 'html';
|
|
165
|
-
/** Filter output lines - simple string or full grep options */
|
|
166
|
-
grep?: string | GrepOptions;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
export interface QuerySelectorCommand extends BaseCommand {
|
|
170
|
-
action: 'querySelector';
|
|
171
|
-
selector: Selector;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
export interface QuerySelectorAllCommand extends BaseCommand {
|
|
175
|
-
action: 'querySelectorAll';
|
|
176
|
-
selector: Selector;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
export interface GetTextCommand extends BaseCommand {
|
|
180
|
-
action: 'getText';
|
|
181
|
-
selector: Selector;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
export interface GetAttributeCommand extends BaseCommand {
|
|
185
|
-
action: 'getAttribute';
|
|
186
|
-
selector: Selector;
|
|
187
|
-
attribute: string;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
export interface GetPropertyCommand extends BaseCommand {
|
|
191
|
-
action: 'getProperty';
|
|
192
|
-
selector: Selector;
|
|
193
|
-
property: string;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
export interface GetBoundingBoxCommand extends BaseCommand {
|
|
197
|
-
action: 'getBoundingBox';
|
|
198
|
-
selector: Selector;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
export interface IsVisibleCommand extends BaseCommand {
|
|
202
|
-
action: 'isVisible';
|
|
203
|
-
selector: Selector;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
export interface IsEnabledCommand extends BaseCommand {
|
|
207
|
-
action: 'isEnabled';
|
|
208
|
-
selector: Selector;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
export interface IsCheckedCommand extends BaseCommand {
|
|
212
|
-
action: 'isChecked';
|
|
213
|
-
selector: Selector;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
export interface PressCommand extends BaseCommand {
|
|
217
|
-
action: 'press';
|
|
218
|
-
key: string;
|
|
219
|
-
selector?: Selector;
|
|
220
|
-
modifiers?: Modifier[];
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
export interface KeyDownCommand extends BaseCommand {
|
|
224
|
-
action: 'keyDown';
|
|
225
|
-
key: string;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
export interface KeyUpCommand extends BaseCommand {
|
|
229
|
-
action: 'keyUp';
|
|
230
|
-
key: string;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
export interface WaitCommand extends BaseCommand {
|
|
234
|
-
action: 'wait';
|
|
235
|
-
selector?: Selector;
|
|
236
|
-
state?: 'visible' | 'hidden' | 'attached' | 'detached';
|
|
237
|
-
timeout?: number;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
export interface EvaluateCommand extends BaseCommand {
|
|
241
|
-
action: 'evaluate';
|
|
242
|
-
script: string;
|
|
243
|
-
args?: unknown[];
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* Validate element capabilities before attempting an action
|
|
248
|
-
*
|
|
249
|
-
* Allows AI agents to check element compatibility and get actionable feedback
|
|
250
|
-
* before executing commands that might fail.
|
|
251
|
-
*
|
|
252
|
-
* @example Pre-validate before typing
|
|
253
|
-
* ```typescript
|
|
254
|
-
* const validation = await agent.execute({
|
|
255
|
-
* id: 'v1',
|
|
256
|
-
* action: 'validateElement',
|
|
257
|
-
* selector: '#username',
|
|
258
|
-
* capabilities: ['editable']
|
|
259
|
-
* });
|
|
260
|
-
*
|
|
261
|
-
* if (validation.data.compatible) {
|
|
262
|
-
* await agent.execute({
|
|
263
|
-
* id: 'a1',
|
|
264
|
-
* action: 'type',
|
|
265
|
-
* selector: '#username',
|
|
266
|
-
* text: 'user@example.com'
|
|
267
|
-
* });
|
|
268
|
-
* } else {
|
|
269
|
-
* console.log(validation.data.suggestion);
|
|
270
|
-
* }
|
|
271
|
-
* ```
|
|
272
|
-
*/
|
|
273
|
-
export interface ValidateElementCommand extends BaseCommand {
|
|
274
|
-
action: 'validateElement';
|
|
275
|
-
|
|
276
|
-
/** Element selector to validate */
|
|
277
|
-
selector: Selector;
|
|
278
|
-
|
|
279
|
-
/** Expected element type (optional) */
|
|
280
|
-
expectedType?: 'input' | 'textarea' | 'button' | 'link' | 'select';
|
|
281
|
-
|
|
282
|
-
/** Required capabilities (optional) */
|
|
283
|
-
capabilities?: Array<'clickable' | 'editable' | 'checkable' | 'hoverable'>;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* Validate that refs are still valid
|
|
288
|
-
*
|
|
289
|
-
* Checks if refs from a previous snapshot are still valid or have expired.
|
|
290
|
-
* Helps AI agents avoid using stale refs.
|
|
291
|
-
*
|
|
292
|
-
* @example Check ref validity
|
|
293
|
-
* ```typescript
|
|
294
|
-
* const validation = await agent.execute({
|
|
295
|
-
* id: 'v1',
|
|
296
|
-
* action: 'validateRefs',
|
|
297
|
-
* refs: ['@ref:0', '@ref:1', '@ref:2']
|
|
298
|
-
* });
|
|
299
|
-
*
|
|
300
|
-
* // Use only valid refs
|
|
301
|
-
* for (const ref of validation.data.valid) {
|
|
302
|
-
* await agent.execute({ id: '...', action: 'click', selector: ref });
|
|
303
|
-
* }
|
|
304
|
-
*
|
|
305
|
-
* // Handle invalid refs
|
|
306
|
-
* if (validation.data.invalid.length > 0) {
|
|
307
|
-
* // Take new snapshot to get fresh refs
|
|
308
|
-
* await agent.execute({ id: '...', action: 'snapshot' });
|
|
309
|
-
* }
|
|
310
|
-
* ```
|
|
311
|
-
*/
|
|
312
|
-
export interface ValidateRefsCommand extends BaseCommand {
|
|
313
|
-
action: 'validateRefs';
|
|
314
|
-
|
|
315
|
-
/** List of refs to validate */
|
|
316
|
-
refs: string[];
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
/**
|
|
320
|
-
* Display visual overlay labels for interactive elements
|
|
321
|
-
*
|
|
322
|
-
* Shows reference numbers (@ref:0, @ref:1, etc.) as overlay labels
|
|
323
|
-
* positioned near each interactive element from the last snapshot.
|
|
324
|
-
* Labels persist until explicitly cleared.
|
|
325
|
-
*
|
|
326
|
-
* @example Highlight elements after snapshot
|
|
327
|
-
* ```typescript
|
|
328
|
-
* // Take a snapshot first
|
|
329
|
-
* await agent.execute({ id: 's1', action: 'snapshot' });
|
|
330
|
-
*
|
|
331
|
-
* // Show visual highlights
|
|
332
|
-
* await agent.execute({ id: 'h1', action: 'highlight' });
|
|
333
|
-
*
|
|
334
|
-
* // Labels now visible on page with @ref:0, @ref:1, etc.
|
|
335
|
-
* // Use the refs to interact with elements
|
|
336
|
-
* await agent.execute({ id: 'c1', action: 'click', selector: '@ref:5' });
|
|
337
|
-
*
|
|
338
|
-
* // Clear highlights when done
|
|
339
|
-
* await agent.execute({ id: 'ch1', action: 'clearHighlight' });
|
|
340
|
-
* ```
|
|
341
|
-
*/
|
|
342
|
-
export interface HighlightCommand extends BaseCommand {
|
|
343
|
-
action: 'highlight';
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
/**
|
|
347
|
-
* Remove visual overlay labels
|
|
348
|
-
*
|
|
349
|
-
* Clears all highlight overlays from the page.
|
|
350
|
-
*
|
|
351
|
-
* @example Clear highlights
|
|
352
|
-
* ```typescript
|
|
353
|
-
* await agent.execute({ id: 'ch1', action: 'clearHighlight' });
|
|
354
|
-
* ```
|
|
355
|
-
*/
|
|
356
|
-
export interface ClearHighlightCommand extends BaseCommand {
|
|
357
|
-
action: 'clearHighlight';
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
export type Modifier = 'Alt' | 'Control' | 'Meta' | 'Shift';
|
|
361
|
-
|
|
362
|
-
// Union of all commands
|
|
363
|
-
export type Command =
|
|
364
|
-
| ClickCommand
|
|
365
|
-
| DblClickCommand
|
|
366
|
-
| TypeCommand
|
|
367
|
-
| FillCommand
|
|
368
|
-
| ClearCommand
|
|
369
|
-
| CheckCommand
|
|
370
|
-
| UncheckCommand
|
|
371
|
-
| SelectCommand
|
|
372
|
-
| FocusCommand
|
|
373
|
-
| BlurCommand
|
|
374
|
-
| HoverCommand
|
|
375
|
-
| ScrollCommand
|
|
376
|
-
| ScrollIntoViewCommand
|
|
377
|
-
| SnapshotCommand
|
|
378
|
-
| QuerySelectorCommand
|
|
379
|
-
| QuerySelectorAllCommand
|
|
380
|
-
| GetTextCommand
|
|
381
|
-
| GetAttributeCommand
|
|
382
|
-
| GetPropertyCommand
|
|
383
|
-
| GetBoundingBoxCommand
|
|
384
|
-
| IsVisibleCommand
|
|
385
|
-
| IsEnabledCommand
|
|
386
|
-
| IsCheckedCommand
|
|
387
|
-
| PressCommand
|
|
388
|
-
| KeyDownCommand
|
|
389
|
-
| KeyUpCommand
|
|
390
|
-
| WaitCommand
|
|
391
|
-
| EvaluateCommand
|
|
392
|
-
| ValidateElementCommand
|
|
393
|
-
| ValidateRefsCommand
|
|
394
|
-
| HighlightCommand
|
|
395
|
-
| ClearHighlightCommand;
|
|
396
|
-
|
|
397
|
-
// Response types
|
|
398
|
-
export interface SuccessResponse<T = unknown> {
|
|
399
|
-
id: string;
|
|
400
|
-
success: true;
|
|
401
|
-
data: T;
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
/**
|
|
405
|
-
* Error response with structured data for AI agents
|
|
406
|
-
*
|
|
407
|
-
* Includes both human-readable error messages and machine-readable
|
|
408
|
-
* error codes, context, and recovery suggestions.
|
|
409
|
-
*/
|
|
410
|
-
export interface ErrorResponse {
|
|
411
|
-
id: string;
|
|
412
|
-
success: false;
|
|
413
|
-
|
|
414
|
-
/** Human-readable error message */
|
|
415
|
-
error: string;
|
|
416
|
-
|
|
417
|
-
/** Machine-readable error code (optional) */
|
|
418
|
-
errorCode?: string;
|
|
419
|
-
|
|
420
|
-
/** Structured error context (optional) */
|
|
421
|
-
errorContext?: {
|
|
422
|
-
selector?: string;
|
|
423
|
-
expectedType?: string;
|
|
424
|
-
actualType?: string;
|
|
425
|
-
elementState?: {
|
|
426
|
-
attached: boolean;
|
|
427
|
-
visible: boolean;
|
|
428
|
-
enabled: boolean;
|
|
429
|
-
};
|
|
430
|
-
availableActions?: string[];
|
|
431
|
-
similarSelectors?: Array<{
|
|
432
|
-
selector: string;
|
|
433
|
-
role: string;
|
|
434
|
-
name: string;
|
|
435
|
-
}>;
|
|
436
|
-
nearbyElements?: Array<{
|
|
437
|
-
ref: string;
|
|
438
|
-
role: string;
|
|
439
|
-
name: string;
|
|
440
|
-
}>;
|
|
441
|
-
[key: string]: any;
|
|
442
|
-
};
|
|
443
|
-
|
|
444
|
-
/** Actionable recovery suggestions (optional) */
|
|
445
|
-
suggestions?: string[];
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
export type Response<T = unknown> = SuccessResponse<T> | ErrorResponse;
|
|
449
|
-
|
|
450
|
-
/**
|
|
451
|
-
* Response data for validateElement command
|
|
452
|
-
*/
|
|
453
|
-
export interface ValidateElementResponse {
|
|
454
|
-
/** Whether element is compatible with requested capabilities */
|
|
455
|
-
compatible: boolean;
|
|
456
|
-
|
|
457
|
-
/** Actual element role/tag */
|
|
458
|
-
actualRole: string;
|
|
459
|
-
|
|
460
|
-
/** Actual element type (for inputs) */
|
|
461
|
-
actualType?: string;
|
|
462
|
-
|
|
463
|
-
/** Capabilities this element supports */
|
|
464
|
-
capabilities: string[];
|
|
465
|
-
|
|
466
|
-
/** Current element state */
|
|
467
|
-
state: {
|
|
468
|
-
visible: boolean;
|
|
469
|
-
enabled: boolean;
|
|
470
|
-
attached: boolean;
|
|
471
|
-
};
|
|
472
|
-
|
|
473
|
-
/** Suggestion if not compatible */
|
|
474
|
-
suggestion?: string;
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
/**
|
|
478
|
-
* Response data for validateRefs command
|
|
479
|
-
*/
|
|
480
|
-
export interface ValidateRefsResponse {
|
|
481
|
-
/** List of valid refs */
|
|
482
|
-
valid: string[];
|
|
483
|
-
|
|
484
|
-
/** List of invalid refs */
|
|
485
|
-
invalid: string[];
|
|
486
|
-
|
|
487
|
-
/** Reasons why each ref is invalid */
|
|
488
|
-
reasons: Record<string, string>;
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
// Snapshot data
|
|
492
|
-
export interface SnapshotNode {
|
|
493
|
-
role: string;
|
|
494
|
-
name?: string;
|
|
495
|
-
ref?: string;
|
|
496
|
-
value?: string;
|
|
497
|
-
checked?: boolean;
|
|
498
|
-
disabled?: boolean;
|
|
499
|
-
children?: SnapshotNode[];
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
export interface SnapshotData {
|
|
503
|
-
tree: string;
|
|
504
|
-
refs: Record<string, {
|
|
505
|
-
selector: string;
|
|
506
|
-
role: string;
|
|
507
|
-
name?: string;
|
|
508
|
-
bbox?: BoundingBox;
|
|
509
|
-
inViewport?: boolean;
|
|
510
|
-
importance?: 'primary' | 'secondary' | 'utility';
|
|
511
|
-
context?: string;
|
|
512
|
-
}>;
|
|
513
|
-
metadata?: {
|
|
514
|
-
totalInteractiveElements?: number;
|
|
515
|
-
capturedElements?: number;
|
|
516
|
-
quality?: 'high' | 'medium' | 'low';
|
|
517
|
-
depthLimited?: boolean;
|
|
518
|
-
warnings?: string[];
|
|
519
|
-
};
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
// Bounding box
|
|
523
|
-
export interface BoundingBox {
|
|
524
|
-
x: number;
|
|
525
|
-
y: number;
|
|
526
|
-
width: number;
|
|
527
|
-
height: number;
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
// Element reference map
|
|
531
|
-
export interface RefMap {
|
|
532
|
-
get(ref: string): Element | null;
|
|
533
|
-
set(ref: string, element: Element): void;
|
|
534
|
-
clear(): void;
|
|
535
|
-
generateRef(element: Element): string;
|
|
536
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2022",
|
|
4
|
-
"module": "ESNext",
|
|
5
|
-
"moduleResolution": "bundler",
|
|
6
|
-
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
|
7
|
-
"outDir": "dist",
|
|
8
|
-
"rootDir": "src",
|
|
9
|
-
"declaration": true,
|
|
10
|
-
"declarationMap": true,
|
|
11
|
-
"sourceMap": true,
|
|
12
|
-
"strict": true,
|
|
13
|
-
"noImplicitAny": true,
|
|
14
|
-
"strictNullChecks": true,
|
|
15
|
-
"noUnusedLocals": true,
|
|
16
|
-
"noUnusedParameters": true,
|
|
17
|
-
"esModuleInterop": true,
|
|
18
|
-
"skipLibCheck": true,
|
|
19
|
-
"forceConsistentCasingInFileNames": true
|
|
20
|
-
},
|
|
21
|
-
"include": ["src/**/*"],
|
|
22
|
-
"exclude": ["node_modules", "dist", "**/*.test.ts"]
|
|
23
|
-
}
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
# @btcp/extension
|
|
2
|
-
|
|
3
|
-
Chrome extension bridge for browser automation. Provides `BrowserAgent` for background scripts and integrates with `ContentAgent` from `@btcp/core`.
|
|
4
|
-
|
|
5
|
-
## Architecture
|
|
6
|
-
|
|
7
|
-
```
|
|
8
|
-
┌─────────────────────────────────────────────────────────────────┐
|
|
9
|
-
│ Background Script │
|
|
10
|
-
│ ┌─────────────────────────────────────────────────────────────┐│
|
|
11
|
-
│ │ BrowserAgent ││
|
|
12
|
-
│ │ - Tab management (create, close, switch, list) ││
|
|
13
|
-
│ │ - Navigation (goto, back, forward, reload) ││
|
|
14
|
-
│ │ - Screenshots (chrome.tabs.captureVisibleTab) ││
|
|
15
|
-
│ │ - Routes DOM commands → ContentAgent ││
|
|
16
|
-
│ └─────────────────────────────────────────────────────────────┘│
|
|
17
|
-
└─────────────────────────────────────────────────────────────────┘
|
|
18
|
-
│
|
|
19
|
-
chrome.tabs.sendMessage
|
|
20
|
-
▼
|
|
21
|
-
┌─────────────────────────────────────────────────────────────────┐
|
|
22
|
-
│ Content Script (Per Tab) │
|
|
23
|
-
│ ┌─────────────────────────────────────────────────────────────┐│
|
|
24
|
-
│ │ ContentAgent (from @btcp/core) ││
|
|
25
|
-
│ │ - DOM snapshot ││
|
|
26
|
-
│ │ - Element interaction (click, type, fill) ││
|
|
27
|
-
│ │ - DOM queries ││
|
|
28
|
-
│ └─────────────────────────────────────────────────────────────┘│
|
|
29
|
-
└─────────────────────────────────────────────────────────────────┘
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
## Installation
|
|
33
|
-
|
|
34
|
-
```bash
|
|
35
|
-
npm install @btcp/extension
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
## Usage
|
|
39
|
-
|
|
40
|
-
### Background Script
|
|
41
|
-
|
|
42
|
-
```typescript
|
|
43
|
-
import { BrowserAgent, setupMessageListener } from '@btcp/extension';
|
|
44
|
-
|
|
45
|
-
// Option 1: Set up automatic message routing
|
|
46
|
-
setupMessageListener();
|
|
47
|
-
|
|
48
|
-
// Option 2: Use BrowserAgent programmatically
|
|
49
|
-
const browser = new BrowserAgent();
|
|
50
|
-
|
|
51
|
-
// Tab management
|
|
52
|
-
await browser.newTab({ url: 'https://example.com' });
|
|
53
|
-
await browser.switchTab(tabId);
|
|
54
|
-
await browser.closeTab();
|
|
55
|
-
const tabs = await browser.listTabs();
|
|
56
|
-
|
|
57
|
-
// Navigation
|
|
58
|
-
await browser.navigate('https://example.com');
|
|
59
|
-
await browser.back();
|
|
60
|
-
await browser.forward();
|
|
61
|
-
await browser.reload();
|
|
62
|
-
|
|
63
|
-
// Screenshots
|
|
64
|
-
const screenshot = await browser.screenshot({ format: 'png' });
|
|
65
|
-
|
|
66
|
-
// Execute DOM commands (routes to ContentAgent)
|
|
67
|
-
await browser.execute({ id: '1', action: 'click', selector: '#submit' });
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
### Content Script
|
|
71
|
-
|
|
72
|
-
```typescript
|
|
73
|
-
import { createContentAgent } from '@btcp/core';
|
|
74
|
-
|
|
75
|
-
const agent = createContentAgent();
|
|
76
|
-
|
|
77
|
-
// Take a snapshot
|
|
78
|
-
const response = await agent.execute({ id: '1', action: 'snapshot' });
|
|
79
|
-
console.log(response.data.tree); // Accessibility tree
|
|
80
|
-
|
|
81
|
-
// Interact with elements
|
|
82
|
-
await agent.execute({ id: '2', action: 'click', selector: '@ref:5' });
|
|
83
|
-
await agent.execute({ id: '3', action: 'fill', selector: '@ref:3', value: 'Hello' });
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
### Popup / External Scripts
|
|
87
|
-
|
|
88
|
-
```typescript
|
|
89
|
-
import { createClient } from '@btcp/extension';
|
|
90
|
-
|
|
91
|
-
const client = createClient();
|
|
92
|
-
|
|
93
|
-
// All commands route through background script
|
|
94
|
-
await client.navigate('https://example.com');
|
|
95
|
-
const snapshot = await client.snapshot();
|
|
96
|
-
await client.click('@ref:5');
|
|
97
|
-
const screenshot = await client.screenshot();
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
## API
|
|
101
|
-
|
|
102
|
-
### BrowserAgent
|
|
103
|
-
|
|
104
|
-
| Method | Description |
|
|
105
|
-
|--------|-------------|
|
|
106
|
-
| `navigate(url, options?)` | Navigate to URL |
|
|
107
|
-
| `back()` | Go back in history |
|
|
108
|
-
| `forward()` | Go forward in history |
|
|
109
|
-
| `reload(options?)` | Reload page |
|
|
110
|
-
| `getUrl()` | Get current URL |
|
|
111
|
-
| `getTitle()` | Get page title |
|
|
112
|
-
| `screenshot(options?)` | Capture screenshot |
|
|
113
|
-
| `newTab(options?)` | Create new tab |
|
|
114
|
-
| `closeTab(tabId?)` | Close tab |
|
|
115
|
-
| `switchTab(tabId)` | Switch to tab |
|
|
116
|
-
| `listTabs()` | List all tabs |
|
|
117
|
-
| `execute(command)` | Execute any command |
|
|
118
|
-
|
|
119
|
-
### Exported Functions
|
|
120
|
-
|
|
121
|
-
| Function | Description |
|
|
122
|
-
|----------|-------------|
|
|
123
|
-
| `setupMessageListener()` | Set up background message routing |
|
|
124
|
-
| `getBrowserAgent()` | Get singleton BrowserAgent instance |
|
|
125
|
-
| `createClient()` | Create client for popup/external use |
|
|
126
|
-
|
|
127
|
-
## License
|
|
128
|
-
|
|
129
|
-
Apache-2.0
|