btcp-browser-agent 0.1.0 → 0.1.2
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,579 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @btcp/extension
|
|
3
|
-
*
|
|
4
|
-
* Chrome extension bridge for browser automation.
|
|
5
|
-
*
|
|
6
|
-
* Architecture:
|
|
7
|
-
* - BackgroundAgent: Runs in background script, manages tabs/navigation/screenshots
|
|
8
|
-
* - ContentAgent: Runs in content scripts, handles DOM operations (from @btcp/core)
|
|
9
|
-
* - Client: API for sending commands from popup or external scripts
|
|
10
|
-
*
|
|
11
|
-
* @example Background script setup:
|
|
12
|
-
* ```typescript
|
|
13
|
-
* import { BackgroundAgent, setupMessageListener } from '@btcp/extension';
|
|
14
|
-
*
|
|
15
|
-
* // Set up message routing
|
|
16
|
-
* setupMessageListener();
|
|
17
|
-
*
|
|
18
|
-
* // Or use BackgroundAgent directly
|
|
19
|
-
* const agent = new BackgroundAgent();
|
|
20
|
-
* await agent.navigate('https://example.com');
|
|
21
|
-
* await agent.screenshot();
|
|
22
|
-
* ```
|
|
23
|
-
*
|
|
24
|
-
* @example Content script setup:
|
|
25
|
-
* ```typescript
|
|
26
|
-
* import { createContentAgent } from '@btcp/core';
|
|
27
|
-
*
|
|
28
|
-
* const agent = createContentAgent();
|
|
29
|
-
* await agent.execute({ id: '1', action: 'snapshot' });
|
|
30
|
-
* ```
|
|
31
|
-
*
|
|
32
|
-
* @example Popup/external usage:
|
|
33
|
-
* ```typescript
|
|
34
|
-
* import { createClient } from '@btcp/extension';
|
|
35
|
-
*
|
|
36
|
-
* const client = createClient();
|
|
37
|
-
* await client.navigate('https://example.com');
|
|
38
|
-
* const snapshot = await client.snapshot();
|
|
39
|
-
* await client.click('@ref:5');
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
|
|
43
|
-
import type {
|
|
44
|
-
Command,
|
|
45
|
-
ExtensionMessage,
|
|
46
|
-
ExtensionResponse,
|
|
47
|
-
Response,
|
|
48
|
-
TabInfo,
|
|
49
|
-
} from './types.js';
|
|
50
|
-
import type { GroupColor } from './session-types.js';
|
|
51
|
-
|
|
52
|
-
// Import for local use (and re-export below)
|
|
53
|
-
import {
|
|
54
|
-
BackgroundAgent as _BackgroundAgent,
|
|
55
|
-
getBackgroundAgent as _getBackgroundAgent,
|
|
56
|
-
setupMessageListener as _setupMessageListener,
|
|
57
|
-
BrowserAgent as _BrowserAgent,
|
|
58
|
-
getBrowserAgent as _getBrowserAgent,
|
|
59
|
-
} from './background.js';
|
|
60
|
-
|
|
61
|
-
export * from './types.js';
|
|
62
|
-
|
|
63
|
-
// Re-export BackgroundAgent for background script usage
|
|
64
|
-
export {
|
|
65
|
-
_BackgroundAgent as BackgroundAgent,
|
|
66
|
-
_getBackgroundAgent as getBackgroundAgent,
|
|
67
|
-
_setupMessageListener as setupMessageListener,
|
|
68
|
-
// Deprecated aliases for backwards compatibility
|
|
69
|
-
_BrowserAgent as BrowserAgent,
|
|
70
|
-
_getBrowserAgent as getBrowserAgent,
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
// Re-export ContentAgent for content script usage
|
|
74
|
-
export { createContentAgent, type ContentAgent } from '@btcp/core';
|
|
75
|
-
|
|
76
|
-
// Re-export core types
|
|
77
|
-
export type {
|
|
78
|
-
SnapshotData,
|
|
79
|
-
BoundingBox,
|
|
80
|
-
Modifier,
|
|
81
|
-
} from '@btcp/core';
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Client for sending commands to the extension background script
|
|
85
|
-
*/
|
|
86
|
-
export interface Client {
|
|
87
|
-
/**
|
|
88
|
-
* Execute a raw command
|
|
89
|
-
*/
|
|
90
|
-
execute(command: Command): Promise<Response>;
|
|
91
|
-
|
|
92
|
-
// --- Navigation ---
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Navigate to a URL
|
|
96
|
-
*/
|
|
97
|
-
navigate(url: string, options?: { waitUntil?: 'load' | 'domcontentloaded' }): Promise<Response>;
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Go back in history
|
|
101
|
-
*/
|
|
102
|
-
back(): Promise<Response>;
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Go forward in history
|
|
106
|
-
*/
|
|
107
|
-
forward(): Promise<Response>;
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Reload the page
|
|
111
|
-
*/
|
|
112
|
-
reload(options?: { bypassCache?: boolean }): Promise<Response>;
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Get the current URL
|
|
116
|
-
*/
|
|
117
|
-
getUrl(): Promise<string>;
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Get the page title
|
|
121
|
-
*/
|
|
122
|
-
getTitle(): Promise<string>;
|
|
123
|
-
|
|
124
|
-
// --- DOM ---
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Take a snapshot of the page
|
|
128
|
-
*/
|
|
129
|
-
snapshot(options?: {
|
|
130
|
-
selector?: string;
|
|
131
|
-
maxDepth?: number;
|
|
132
|
-
interactive?: boolean;
|
|
133
|
-
compact?: boolean;
|
|
134
|
-
format?: 'tree' | 'html';
|
|
135
|
-
}): Promise<string>;
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Click an element
|
|
139
|
-
*/
|
|
140
|
-
click(selector: string, options?: { button?: 'left' | 'right' | 'middle' }): Promise<Response>;
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Type text into an element
|
|
144
|
-
*/
|
|
145
|
-
type(selector: string, text: string, options?: { delay?: number; clear?: boolean }): Promise<Response>;
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Fill an input with a value
|
|
149
|
-
*/
|
|
150
|
-
fill(selector: string, value: string): Promise<Response>;
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Get text content of an element
|
|
154
|
-
*/
|
|
155
|
-
getText(selector: string): Promise<string | null>;
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Check if element is visible
|
|
159
|
-
*/
|
|
160
|
-
isVisible(selector: string): Promise<boolean>;
|
|
161
|
-
|
|
162
|
-
// --- Tabs ---
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Take a screenshot
|
|
166
|
-
*/
|
|
167
|
-
screenshot(options?: { format?: 'png' | 'jpeg'; quality?: number }): Promise<string>;
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Open a new tab
|
|
171
|
-
*/
|
|
172
|
-
tabNew(options?: { url?: string; active?: boolean }): Promise<{ tabId: number; url?: string }>;
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Close a tab
|
|
176
|
-
*/
|
|
177
|
-
tabClose(tabId?: number): Promise<Response>;
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Switch to a tab
|
|
181
|
-
*/
|
|
182
|
-
tabSwitch(tabId: number): Promise<Response>;
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* List all tabs
|
|
186
|
-
*/
|
|
187
|
-
tabList(): Promise<TabInfo[]>;
|
|
188
|
-
|
|
189
|
-
// --- Tab Groups & Sessions ---
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* Create a new tab group
|
|
193
|
-
*/
|
|
194
|
-
groupCreate(options?: {
|
|
195
|
-
tabIds?: number[];
|
|
196
|
-
title?: string;
|
|
197
|
-
color?: string;
|
|
198
|
-
collapsed?: boolean;
|
|
199
|
-
}): Promise<{ group: import('./session-types.js').GroupInfo }>;
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* Update a tab group
|
|
203
|
-
*/
|
|
204
|
-
groupUpdate(
|
|
205
|
-
groupId: number,
|
|
206
|
-
options: { title?: string; color?: string; collapsed?: boolean }
|
|
207
|
-
): Promise<{ group: import('./session-types.js').GroupInfo }>;
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* Delete a tab group (closes all tabs)
|
|
211
|
-
*/
|
|
212
|
-
groupDelete(groupId: number): Promise<Response>;
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* List all tab groups
|
|
216
|
-
*/
|
|
217
|
-
groupList(): Promise<import('./session-types.js').GroupInfo[]>;
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* Add tabs to a group
|
|
221
|
-
*/
|
|
222
|
-
groupAddTabs(groupId: number, tabIds: number[]): Promise<Response>;
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* Remove tabs from their group
|
|
226
|
-
*/
|
|
227
|
-
groupRemoveTabs(tabIds: number[]): Promise<Response>;
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* Get a specific tab group
|
|
231
|
-
*/
|
|
232
|
-
groupGet(groupId: number): Promise<{ group: import('./session-types.js').GroupInfo }>;
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* Get current active session
|
|
236
|
-
*/
|
|
237
|
-
sessionGetCurrent(): Promise<{ session: import('./session-types.js').SessionInfo | null }>;
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* Initialize popup (triggers session reconnection check)
|
|
241
|
-
*/
|
|
242
|
-
popupInitialize(): Promise<{ initialized: boolean; reconnected: boolean }>;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
let commandIdCounter = 0;
|
|
246
|
-
|
|
247
|
-
function generateCommandId(): string {
|
|
248
|
-
return `cmd_${Date.now()}_${commandIdCounter++}`;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* Check if we're running in a background/service worker context
|
|
253
|
-
*/
|
|
254
|
-
function isBackgroundContext(): boolean {
|
|
255
|
-
// In Manifest V3, background scripts run as service workers
|
|
256
|
-
return typeof ServiceWorkerGlobalScope !== 'undefined' && self instanceof ServiceWorkerGlobalScope;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Create a client for communicating with the extension
|
|
261
|
-
*
|
|
262
|
-
* This function works in both popup/content scripts and background scripts:
|
|
263
|
-
* - In popup/content scripts: Uses chrome.runtime.sendMessage to communicate with background
|
|
264
|
-
* - In background scripts: Uses BackgroundAgent directly for better performance
|
|
265
|
-
*
|
|
266
|
-
* @example Popup usage:
|
|
267
|
-
* ```typescript
|
|
268
|
-
* import { createClient } from '@btcp/browser-agent/extension';
|
|
269
|
-
* const client = createClient();
|
|
270
|
-
* await client.navigate('https://example.com');
|
|
271
|
-
* ```
|
|
272
|
-
*
|
|
273
|
-
* @example Background script usage:
|
|
274
|
-
* ```typescript
|
|
275
|
-
* import { createClient } from '@btcp/browser-agent/extension';
|
|
276
|
-
* const client = createClient();
|
|
277
|
-
* // Works the same way - commands go directly to BackgroundAgent
|
|
278
|
-
* await client.navigate('https://example.com');
|
|
279
|
-
* ```
|
|
280
|
-
*/
|
|
281
|
-
export function createClient(): Client {
|
|
282
|
-
// Detect if we're in background context
|
|
283
|
-
const inBackground = isBackgroundContext();
|
|
284
|
-
|
|
285
|
-
// Lazily get the background agent to avoid circular dependency issues
|
|
286
|
-
let bgAgent: _BackgroundAgent | null = null;
|
|
287
|
-
|
|
288
|
-
function getAgent(): _BackgroundAgent {
|
|
289
|
-
if (!bgAgent) {
|
|
290
|
-
// Use the singleton getter from background.js
|
|
291
|
-
bgAgent = _getBackgroundAgent();
|
|
292
|
-
}
|
|
293
|
-
return bgAgent;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
async function sendCommand(command: Command): Promise<Response> {
|
|
297
|
-
// In background context, use BackgroundAgent directly
|
|
298
|
-
if (inBackground) {
|
|
299
|
-
return getAgent().execute(command);
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
// In popup/content context, use message passing
|
|
303
|
-
return new Promise((resolve) => {
|
|
304
|
-
chrome.runtime.sendMessage(
|
|
305
|
-
{ type: 'btcp:command', command } satisfies ExtensionMessage,
|
|
306
|
-
(response) => {
|
|
307
|
-
if (chrome.runtime.lastError) {
|
|
308
|
-
resolve({
|
|
309
|
-
id: command.id,
|
|
310
|
-
success: false,
|
|
311
|
-
error: chrome.runtime.lastError.message || 'Unknown error',
|
|
312
|
-
});
|
|
313
|
-
} else {
|
|
314
|
-
const resp = response as ExtensionResponse;
|
|
315
|
-
if (resp.type === 'btcp:response') {
|
|
316
|
-
resolve(resp.response);
|
|
317
|
-
} else {
|
|
318
|
-
// Unexpected pong response
|
|
319
|
-
resolve({
|
|
320
|
-
id: command.id,
|
|
321
|
-
success: false,
|
|
322
|
-
error: 'Unexpected response type',
|
|
323
|
-
});
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
);
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
function assertSuccess(response: Response): asserts response is Response & { success: true } {
|
|
332
|
-
if (!response.success) {
|
|
333
|
-
throw new Error(response.error);
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
return {
|
|
338
|
-
execute: sendCommand,
|
|
339
|
-
|
|
340
|
-
// Navigation
|
|
341
|
-
async navigate(url, options) {
|
|
342
|
-
return sendCommand({
|
|
343
|
-
id: generateCommandId(),
|
|
344
|
-
action: 'navigate',
|
|
345
|
-
url,
|
|
346
|
-
waitUntil: options?.waitUntil,
|
|
347
|
-
});
|
|
348
|
-
},
|
|
349
|
-
|
|
350
|
-
async back() {
|
|
351
|
-
return sendCommand({ id: generateCommandId(), action: 'back' });
|
|
352
|
-
},
|
|
353
|
-
|
|
354
|
-
async forward() {
|
|
355
|
-
return sendCommand({ id: generateCommandId(), action: 'forward' });
|
|
356
|
-
},
|
|
357
|
-
|
|
358
|
-
async reload(options) {
|
|
359
|
-
return sendCommand({
|
|
360
|
-
id: generateCommandId(),
|
|
361
|
-
action: 'reload',
|
|
362
|
-
bypassCache: options?.bypassCache,
|
|
363
|
-
});
|
|
364
|
-
},
|
|
365
|
-
|
|
366
|
-
async getUrl() {
|
|
367
|
-
const response = await sendCommand({ id: generateCommandId(), action: 'getUrl' });
|
|
368
|
-
assertSuccess(response);
|
|
369
|
-
return (response.data as { url: string }).url;
|
|
370
|
-
},
|
|
371
|
-
|
|
372
|
-
async getTitle() {
|
|
373
|
-
const response = await sendCommand({ id: generateCommandId(), action: 'getTitle' });
|
|
374
|
-
assertSuccess(response);
|
|
375
|
-
return (response.data as { title: string }).title;
|
|
376
|
-
},
|
|
377
|
-
|
|
378
|
-
// DOM
|
|
379
|
-
async snapshot(options) {
|
|
380
|
-
const response = await sendCommand({
|
|
381
|
-
id: generateCommandId(),
|
|
382
|
-
action: 'snapshot',
|
|
383
|
-
selector: options?.selector,
|
|
384
|
-
maxDepth: options?.maxDepth,
|
|
385
|
-
interactive: options?.interactive,
|
|
386
|
-
compact: options?.compact,
|
|
387
|
-
format: options?.format,
|
|
388
|
-
});
|
|
389
|
-
assertSuccess(response);
|
|
390
|
-
return response.data as string;
|
|
391
|
-
},
|
|
392
|
-
|
|
393
|
-
async click(selector, options) {
|
|
394
|
-
return sendCommand({
|
|
395
|
-
id: generateCommandId(),
|
|
396
|
-
action: 'click',
|
|
397
|
-
selector,
|
|
398
|
-
button: options?.button,
|
|
399
|
-
});
|
|
400
|
-
},
|
|
401
|
-
|
|
402
|
-
async type(selector, text, options) {
|
|
403
|
-
return sendCommand({
|
|
404
|
-
id: generateCommandId(),
|
|
405
|
-
action: 'type',
|
|
406
|
-
selector,
|
|
407
|
-
text,
|
|
408
|
-
delay: options?.delay,
|
|
409
|
-
clear: options?.clear,
|
|
410
|
-
});
|
|
411
|
-
},
|
|
412
|
-
|
|
413
|
-
async fill(selector, value) {
|
|
414
|
-
return sendCommand({
|
|
415
|
-
id: generateCommandId(),
|
|
416
|
-
action: 'fill',
|
|
417
|
-
selector,
|
|
418
|
-
value,
|
|
419
|
-
});
|
|
420
|
-
},
|
|
421
|
-
|
|
422
|
-
async getText(selector) {
|
|
423
|
-
const response = await sendCommand({
|
|
424
|
-
id: generateCommandId(),
|
|
425
|
-
action: 'getText',
|
|
426
|
-
selector,
|
|
427
|
-
});
|
|
428
|
-
assertSuccess(response);
|
|
429
|
-
return (response.data as { text: string | null }).text;
|
|
430
|
-
},
|
|
431
|
-
|
|
432
|
-
async isVisible(selector) {
|
|
433
|
-
const response = await sendCommand({
|
|
434
|
-
id: generateCommandId(),
|
|
435
|
-
action: 'isVisible',
|
|
436
|
-
selector,
|
|
437
|
-
});
|
|
438
|
-
assertSuccess(response);
|
|
439
|
-
return (response.data as { visible: boolean }).visible;
|
|
440
|
-
},
|
|
441
|
-
|
|
442
|
-
// Tabs
|
|
443
|
-
async screenshot(options) {
|
|
444
|
-
const response = await sendCommand({
|
|
445
|
-
id: generateCommandId(),
|
|
446
|
-
action: 'screenshot',
|
|
447
|
-
format: options?.format,
|
|
448
|
-
quality: options?.quality,
|
|
449
|
-
});
|
|
450
|
-
assertSuccess(response);
|
|
451
|
-
return (response.data as { screenshot: string }).screenshot;
|
|
452
|
-
},
|
|
453
|
-
|
|
454
|
-
async tabNew(options) {
|
|
455
|
-
const response = await sendCommand({
|
|
456
|
-
id: generateCommandId(),
|
|
457
|
-
action: 'tabNew',
|
|
458
|
-
url: options?.url,
|
|
459
|
-
active: options?.active,
|
|
460
|
-
});
|
|
461
|
-
assertSuccess(response);
|
|
462
|
-
return response.data as { tabId: number; url?: string };
|
|
463
|
-
},
|
|
464
|
-
|
|
465
|
-
async tabClose(tabId) {
|
|
466
|
-
return sendCommand({
|
|
467
|
-
id: generateCommandId(),
|
|
468
|
-
action: 'tabClose',
|
|
469
|
-
tabId,
|
|
470
|
-
});
|
|
471
|
-
},
|
|
472
|
-
|
|
473
|
-
async tabSwitch(tabId) {
|
|
474
|
-
return sendCommand({
|
|
475
|
-
id: generateCommandId(),
|
|
476
|
-
action: 'tabSwitch',
|
|
477
|
-
tabId,
|
|
478
|
-
});
|
|
479
|
-
},
|
|
480
|
-
|
|
481
|
-
async tabList() {
|
|
482
|
-
const response = await sendCommand({
|
|
483
|
-
id: generateCommandId(),
|
|
484
|
-
action: 'tabList',
|
|
485
|
-
});
|
|
486
|
-
assertSuccess(response);
|
|
487
|
-
return (response.data as { tabs: TabInfo[] }).tabs;
|
|
488
|
-
},
|
|
489
|
-
|
|
490
|
-
// Tab Groups & Sessions
|
|
491
|
-
async groupCreate(options) {
|
|
492
|
-
const response = await sendCommand({
|
|
493
|
-
id: generateCommandId(),
|
|
494
|
-
action: 'groupCreate',
|
|
495
|
-
tabIds: options?.tabIds,
|
|
496
|
-
title: options?.title,
|
|
497
|
-
color: options?.color as GroupColor | undefined,
|
|
498
|
-
collapsed: options?.collapsed,
|
|
499
|
-
});
|
|
500
|
-
assertSuccess(response);
|
|
501
|
-
return response.data as { group: import('./session-types.js').GroupInfo };
|
|
502
|
-
},
|
|
503
|
-
|
|
504
|
-
async groupUpdate(groupId, options) {
|
|
505
|
-
const response = await sendCommand({
|
|
506
|
-
id: generateCommandId(),
|
|
507
|
-
action: 'groupUpdate',
|
|
508
|
-
groupId,
|
|
509
|
-
title: options.title,
|
|
510
|
-
color: options.color as GroupColor | undefined,
|
|
511
|
-
collapsed: options.collapsed,
|
|
512
|
-
});
|
|
513
|
-
assertSuccess(response);
|
|
514
|
-
return response.data as { group: import('./session-types.js').GroupInfo };
|
|
515
|
-
},
|
|
516
|
-
|
|
517
|
-
async groupDelete(groupId) {
|
|
518
|
-
return sendCommand({
|
|
519
|
-
id: generateCommandId(),
|
|
520
|
-
action: 'groupDelete',
|
|
521
|
-
groupId,
|
|
522
|
-
} as any);
|
|
523
|
-
},
|
|
524
|
-
|
|
525
|
-
async groupList() {
|
|
526
|
-
const response = await sendCommand({
|
|
527
|
-
id: generateCommandId(),
|
|
528
|
-
action: 'groupList',
|
|
529
|
-
} as any);
|
|
530
|
-
assertSuccess(response);
|
|
531
|
-
return (response.data as { groups: import('./session-types.js').GroupInfo[] }).groups;
|
|
532
|
-
},
|
|
533
|
-
|
|
534
|
-
async groupAddTabs(groupId, tabIds) {
|
|
535
|
-
return sendCommand({
|
|
536
|
-
id: generateCommandId(),
|
|
537
|
-
action: 'groupAddTabs',
|
|
538
|
-
groupId,
|
|
539
|
-
tabIds,
|
|
540
|
-
} as any);
|
|
541
|
-
},
|
|
542
|
-
|
|
543
|
-
async groupRemoveTabs(tabIds) {
|
|
544
|
-
return sendCommand({
|
|
545
|
-
id: generateCommandId(),
|
|
546
|
-
action: 'groupRemoveTabs',
|
|
547
|
-
tabIds,
|
|
548
|
-
} as any);
|
|
549
|
-
},
|
|
550
|
-
|
|
551
|
-
async groupGet(groupId) {
|
|
552
|
-
const response = await sendCommand({
|
|
553
|
-
id: generateCommandId(),
|
|
554
|
-
action: 'groupGet',
|
|
555
|
-
groupId,
|
|
556
|
-
} as any);
|
|
557
|
-
assertSuccess(response);
|
|
558
|
-
return response.data as { group: import('./session-types.js').GroupInfo };
|
|
559
|
-
},
|
|
560
|
-
|
|
561
|
-
async sessionGetCurrent() {
|
|
562
|
-
const response = await sendCommand({
|
|
563
|
-
id: generateCommandId(),
|
|
564
|
-
action: 'sessionGetCurrent',
|
|
565
|
-
} as any);
|
|
566
|
-
assertSuccess(response);
|
|
567
|
-
return response.data as { session: import('./session-types.js').SessionInfo | null };
|
|
568
|
-
},
|
|
569
|
-
|
|
570
|
-
async popupInitialize() {
|
|
571
|
-
const response = await sendCommand({
|
|
572
|
-
id: generateCommandId(),
|
|
573
|
-
action: 'popupInitialize',
|
|
574
|
-
} as any);
|
|
575
|
-
assertSuccess(response);
|
|
576
|
-
return response.data as { initialized: boolean; reconnected: boolean };
|
|
577
|
-
},
|
|
578
|
-
};
|
|
579
|
-
}
|