@bctrl/sdk 1.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/README.md +75 -0
- package/dist/agents/browser-use/index.d.ts +1 -0
- package/dist/agents/browser-use/index.js +9 -0
- package/dist/agents/browser-use/namespace.d.ts +39 -0
- package/dist/agents/browser-use/namespace.js +93 -0
- package/dist/agents/index.d.ts +2 -0
- package/dist/agents/index.js +17 -0
- package/dist/agents/stagehand/core.d.ts +93 -0
- package/dist/agents/stagehand/core.js +144 -0
- package/dist/agents/stagehand/index.d.ts +3 -0
- package/dist/agents/stagehand/index.js +24 -0
- package/dist/agents/stagehand/namespace.d.ts +51 -0
- package/dist/agents/stagehand/namespace.js +65 -0
- package/dist/ai-credentials/client.d.ts +12 -0
- package/dist/ai-credentials/client.js +70 -0
- package/dist/ai-credentials/index.d.ts +1 -0
- package/dist/ai-credentials/index.js +1 -0
- package/dist/base/event-binding.d.ts +7 -0
- package/dist/base/event-binding.js +23 -0
- package/dist/base/types.d.ts +109 -0
- package/dist/base/types.js +4 -0
- package/dist/bctrl.d.ts +37 -0
- package/dist/bctrl.js +77 -0
- package/dist/browser-extensions/client.d.ts +15 -0
- package/dist/browser-extensions/client.js +72 -0
- package/dist/browser-extensions/index.d.ts +2 -0
- package/dist/browser-extensions/index.js +1 -0
- package/dist/browser-profiles/client.d.ts +11 -0
- package/dist/browser-profiles/client.js +63 -0
- package/dist/browser-profiles/index.d.ts +1 -0
- package/dist/browser-profiles/index.js +1 -0
- package/dist/captcha/index.d.ts +1 -0
- package/dist/captcha/index.js +1 -0
- package/dist/captcha/namespace.d.ts +34 -0
- package/dist/captcha/namespace.js +41 -0
- package/dist/client/index.d.ts +1 -0
- package/dist/client/index.js +1 -0
- package/dist/client/rpc.d.ts +83 -0
- package/dist/client/rpc.js +354 -0
- package/dist/config.d.ts +5 -0
- package/dist/config.js +28 -0
- package/dist/constants/browser.d.ts +2 -0
- package/dist/constants/browser.js +1 -0
- package/dist/contracts/agent-tools.d.ts +45 -0
- package/dist/contracts/agent-tools.js +31 -0
- package/dist/contracts/automation.d.ts +265 -0
- package/dist/contracts/automation.js +109 -0
- package/dist/contracts/browser-management.d.ts +179 -0
- package/dist/contracts/browser-management.js +95 -0
- package/dist/contracts/browser-use.d.ts +136 -0
- package/dist/contracts/browser-use.js +93 -0
- package/dist/contracts/captcha.d.ts +114 -0
- package/dist/contracts/captcha.js +40 -0
- package/dist/contracts/desktop.d.ts +223 -0
- package/dist/contracts/desktop.js +121 -0
- package/dist/contracts/drivers/playwright.d.ts +2008 -0
- package/dist/contracts/drivers/playwright.js +2033 -0
- package/dist/contracts/drivers/puppeteer.d.ts +1221 -0
- package/dist/contracts/drivers/puppeteer.js +941 -0
- package/dist/contracts/drivers/selenium.d.ts +156 -0
- package/dist/contracts/drivers/selenium.js +61 -0
- package/dist/contracts/drivers/stagehand.d.ts +155 -0
- package/dist/contracts/drivers/stagehand.js +7 -0
- package/dist/contracts/extensions.d.ts +13 -0
- package/dist/contracts/extensions.js +9 -0
- package/dist/contracts/index.d.ts +13 -0
- package/dist/contracts/index.js +13 -0
- package/dist/contracts/public-api.d.ts +360 -0
- package/dist/contracts/public-api.js +17 -0
- package/dist/contracts/runtime.d.ts +81 -0
- package/dist/contracts/runtime.js +16 -0
- package/dist/contracts/stagehand.d.ts +253 -0
- package/dist/contracts/stagehand.js +145 -0
- package/dist/contracts/storage.d.ts +51 -0
- package/dist/contracts/storage.js +56 -0
- package/dist/contracts/vault.d.ts +119 -0
- package/dist/contracts/vault.js +112 -0
- package/dist/contracts/version.d.ts +3 -0
- package/dist/contracts/version.js +16 -0
- package/dist/desktop.d.ts +2 -0
- package/dist/desktop.js +3 -0
- package/dist/drivers/desktop/index.d.ts +65 -0
- package/dist/drivers/desktop/index.js +68 -0
- package/dist/drivers/desktop/session.d.ts +313 -0
- package/dist/drivers/desktop/session.js +432 -0
- package/dist/drivers/playwright/event-emitter.d.ts +160 -0
- package/dist/drivers/playwright/event-emitter.js +297 -0
- package/dist/drivers/playwright/generated/api-request-context.d.ts +137 -0
- package/dist/drivers/playwright/generated/api-request-context.js +154 -0
- package/dist/drivers/playwright/generated/api-response.d.ts +119 -0
- package/dist/drivers/playwright/generated/api-response.js +123 -0
- package/dist/drivers/playwright/generated/browser-context.d.ts +284 -0
- package/dist/drivers/playwright/generated/browser-context.js +458 -0
- package/dist/drivers/playwright/generated/browser.d.ts +120 -0
- package/dist/drivers/playwright/generated/browser.js +151 -0
- package/dist/drivers/playwright/generated/clock.d.ts +80 -0
- package/dist/drivers/playwright/generated/clock.js +94 -0
- package/dist/drivers/playwright/generated/console-message.d.ts +94 -0
- package/dist/drivers/playwright/generated/console-message.js +89 -0
- package/dist/drivers/playwright/generated/coverage.d.ts +57 -0
- package/dist/drivers/playwright/generated/coverage.js +66 -0
- package/dist/drivers/playwright/generated/dialog.d.ts +79 -0
- package/dist/drivers/playwright/generated/dialog.js +80 -0
- package/dist/drivers/playwright/generated/element-handle.d.ts +399 -0
- package/dist/drivers/playwright/generated/element-handle.js +501 -0
- package/dist/drivers/playwright/generated/frame-locator.d.ts +34 -0
- package/dist/drivers/playwright/generated/frame-locator.js +63 -0
- package/dist/drivers/playwright/generated/frame.d.ts +557 -0
- package/dist/drivers/playwright/generated/frame.js +634 -0
- package/dist/drivers/playwright/generated/js-handle.d.ts +72 -0
- package/dist/drivers/playwright/generated/js-handle.js +92 -0
- package/dist/drivers/playwright/generated/keyboard.d.ts +103 -0
- package/dist/drivers/playwright/generated/keyboard.js +113 -0
- package/dist/drivers/playwright/generated/locator.d.ts +795 -0
- package/dist/drivers/playwright/generated/locator.js +974 -0
- package/dist/drivers/playwright/generated/mouse.d.ts +97 -0
- package/dist/drivers/playwright/generated/mouse.js +109 -0
- package/dist/drivers/playwright/generated/page.d.ts +762 -0
- package/dist/drivers/playwright/generated/page.js +988 -0
- package/dist/drivers/playwright/generated/touchscreen.d.ts +34 -0
- package/dist/drivers/playwright/generated/touchscreen.js +37 -0
- package/dist/drivers/playwright/generated/tracing.d.ts +78 -0
- package/dist/drivers/playwright/generated/tracing.js +80 -0
- package/dist/drivers/playwright/generated/worker.d.ts +53 -0
- package/dist/drivers/playwright/generated/worker.js +59 -0
- package/dist/drivers/playwright/index.d.ts +19 -0
- package/dist/drivers/playwright/index.js +20 -0
- package/dist/drivers/playwright/remote-base.d.ts +62 -0
- package/dist/drivers/playwright/remote-base.js +86 -0
- package/dist/drivers/playwright/types.d.ts +148 -0
- package/dist/drivers/playwright/types.js +8 -0
- package/dist/drivers/puppeteer/errors.d.ts +50 -0
- package/dist/drivers/puppeteer/errors.js +71 -0
- package/dist/drivers/puppeteer/event-emitter.d.ts +145 -0
- package/dist/drivers/puppeteer/event-emitter.js +259 -0
- package/dist/drivers/puppeteer/generated/accessibility.d.ts +77 -0
- package/dist/drivers/puppeteer/generated/accessibility.js +74 -0
- package/dist/drivers/puppeteer/generated/browser-context.d.ts +116 -0
- package/dist/drivers/puppeteer/generated/browser-context.js +168 -0
- package/dist/drivers/puppeteer/generated/browser.d.ts +169 -0
- package/dist/drivers/puppeteer/generated/browser.js +246 -0
- package/dist/drivers/puppeteer/generated/console-message.d.ts +54 -0
- package/dist/drivers/puppeteer/generated/console-message.js +69 -0
- package/dist/drivers/puppeteer/generated/coverage.d.ts +49 -0
- package/dist/drivers/puppeteer/generated/coverage.js +57 -0
- package/dist/drivers/puppeteer/generated/dialog.d.ts +46 -0
- package/dist/drivers/puppeteer/generated/dialog.js +60 -0
- package/dist/drivers/puppeteer/generated/element-handle.d.ts +261 -0
- package/dist/drivers/puppeteer/generated/element-handle.js +341 -0
- package/dist/drivers/puppeteer/generated/file-chooser.d.ts +34 -0
- package/dist/drivers/puppeteer/generated/file-chooser.js +43 -0
- package/dist/drivers/puppeteer/generated/frame.d.ts +221 -0
- package/dist/drivers/puppeteer/generated/frame.js +302 -0
- package/dist/drivers/puppeteer/generated/http-request.d.ts +195 -0
- package/dist/drivers/puppeteer/generated/http-request.js +243 -0
- package/dist/drivers/puppeteer/generated/http-response.d.ts +142 -0
- package/dist/drivers/puppeteer/generated/http-response.js +169 -0
- package/dist/drivers/puppeteer/generated/js-handle.d.ts +104 -0
- package/dist/drivers/puppeteer/generated/js-handle.js +125 -0
- package/dist/drivers/puppeteer/generated/keyboard.d.ts +79 -0
- package/dist/drivers/puppeteer/generated/keyboard.js +89 -0
- package/dist/drivers/puppeteer/generated/locator.d.ts +141 -0
- package/dist/drivers/puppeteer/generated/locator.js +164 -0
- package/dist/drivers/puppeteer/generated/mouse.d.ts +74 -0
- package/dist/drivers/puppeteer/generated/mouse.js +94 -0
- package/dist/drivers/puppeteer/generated/page.d.ts +604 -0
- package/dist/drivers/puppeteer/generated/page.js +776 -0
- package/dist/drivers/puppeteer/generated/target.d.ts +105 -0
- package/dist/drivers/puppeteer/generated/target.js +123 -0
- package/dist/drivers/puppeteer/generated/touchscreen.d.ts +87 -0
- package/dist/drivers/puppeteer/generated/touchscreen.js +103 -0
- package/dist/drivers/puppeteer/generated/tracing.d.ts +38 -0
- package/dist/drivers/puppeteer/generated/tracing.js +43 -0
- package/dist/drivers/puppeteer/generated/web-worker.d.ts +63 -0
- package/dist/drivers/puppeteer/generated/web-worker.js +73 -0
- package/dist/drivers/puppeteer/index.d.ts +21 -0
- package/dist/drivers/puppeteer/index.js +23 -0
- package/dist/drivers/puppeteer/remote-base.d.ts +57 -0
- package/dist/drivers/puppeteer/remote-base.js +79 -0
- package/dist/drivers/puppeteer/types.d.ts +178 -0
- package/dist/drivers/puppeteer/types.js +8 -0
- package/dist/drivers/selenium/driver.d.ts +28 -0
- package/dist/drivers/selenium/driver.js +169 -0
- package/dist/drivers/selenium/element.d.ts +34 -0
- package/dist/drivers/selenium/element.js +73 -0
- package/dist/drivers/selenium/index.d.ts +3 -0
- package/dist/drivers/selenium/index.js +5 -0
- package/dist/drivers/selenium/types.d.ts +2 -0
- package/dist/drivers/selenium/types.js +12 -0
- package/dist/drivers/stagehand/generated/context.d.ts +127 -0
- package/dist/drivers/stagehand/generated/context.js +153 -0
- package/dist/drivers/stagehand/generated/locator.d.ts +324 -0
- package/dist/drivers/stagehand/generated/locator.js +368 -0
- package/dist/drivers/stagehand/generated/page.d.ts +377 -0
- package/dist/drivers/stagehand/generated/page.js +439 -0
- package/dist/drivers/stagehand/generated/response.d.ts +197 -0
- package/dist/drivers/stagehand/generated/response.js +232 -0
- package/dist/drivers/stagehand/index.d.ts +5 -0
- package/dist/drivers/stagehand/index.js +8 -0
- package/dist/drivers/stagehand/types.d.ts +1 -0
- package/dist/drivers/stagehand/types.js +7 -0
- package/dist/errors.d.ts +47 -0
- package/dist/errors.js +157 -0
- package/dist/extensions/client.d.ts +47 -0
- package/dist/extensions/client.js +154 -0
- package/dist/extensions/index.d.ts +1 -0
- package/dist/extensions/index.js +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +23 -0
- package/dist/internal/dev-client.d.ts +5 -0
- package/dist/internal/dev-client.js +9 -0
- package/dist/internal/rpc-targets.d.ts +17 -0
- package/dist/internal/rpc-targets.js +58 -0
- package/dist/internal/serialization.d.ts +32 -0
- package/dist/internal/serialization.js +42 -0
- package/dist/internal/transport.d.ts +24 -0
- package/dist/internal/transport.js +29 -0
- package/dist/playwright.d.ts +1 -0
- package/dist/playwright.js +2 -0
- package/dist/puppeteer.d.ts +1 -0
- package/dist/puppeteer.js +2 -0
- package/dist/selenium.d.ts +1 -0
- package/dist/selenium.js +2 -0
- package/dist/stagehand.d.ts +1 -0
- package/dist/stagehand.js +2 -0
- package/dist/storage/client.d.ts +151 -0
- package/dist/storage/client.js +329 -0
- package/dist/storage/index.d.ts +2 -0
- package/dist/storage/index.js +4 -0
- package/dist/telemetry.d.ts +18 -0
- package/dist/telemetry.js +93 -0
- package/dist/updates/client.d.ts +8 -0
- package/dist/updates/client.js +128 -0
- package/dist/updates/index.d.ts +1 -0
- package/dist/updates/index.js +1 -0
- package/dist/utils/http.d.ts +39 -0
- package/dist/utils/http.js +88 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/logger.d.ts +27 -0
- package/dist/utils/logger.js +74 -0
- package/dist/utils/schema.d.ts +17 -0
- package/dist/utils/schema.js +31 -0
- package/dist/utils/url.d.ts +5 -0
- package/dist/utils/url.js +7 -0
- package/dist/vault/client.d.ts +43 -0
- package/dist/vault/client.js +123 -0
- package/dist/vault/index.d.ts +1 -0
- package/dist/vault/index.js +1 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +4 -0
- package/dist/workspaces/browser-runtime.d.ts +251 -0
- package/dist/workspaces/browser-runtime.js +1025 -0
- package/dist/workspaces/client.d.ts +48 -0
- package/dist/workspaces/client.js +222 -0
- package/dist/workspaces/index.d.ts +2 -0
- package/dist/workspaces/index.js +2 -0
- package/dist/workspaces/runtime-event-pump.d.ts +65 -0
- package/dist/workspaces/runtime-event-pump.js +716 -0
- package/package.json +56 -0
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DesktopSession - SDK client for desktop automation
|
|
3
|
+
*
|
|
4
|
+
* Provides namespaced APIs for mouse, keyboard, screen, and window control.
|
|
5
|
+
* Can also launch browsers for DOM-level control via Playwright.
|
|
6
|
+
*/
|
|
7
|
+
import { fetchWithTimeout, parseJsonResponse, DEFAULT_TIMEOUT_MS, LONG_TIMEOUT_MS, } from '../../utils/http.js';
|
|
8
|
+
export class DesktopSession {
|
|
9
|
+
id;
|
|
10
|
+
baseUrl;
|
|
11
|
+
apiKey;
|
|
12
|
+
_mouse;
|
|
13
|
+
_keyboard;
|
|
14
|
+
_screen;
|
|
15
|
+
_window;
|
|
16
|
+
_clipboard;
|
|
17
|
+
_cua;
|
|
18
|
+
constructor(sessionId, baseUrl, options) {
|
|
19
|
+
this.id = sessionId;
|
|
20
|
+
this.baseUrl = baseUrl;
|
|
21
|
+
this.apiKey = options?.apiKey;
|
|
22
|
+
this._mouse = new DesktopMouse(this);
|
|
23
|
+
this._keyboard = new DesktopKeyboard(this);
|
|
24
|
+
this._screen = new DesktopScreen(this);
|
|
25
|
+
this._window = new DesktopWindow(this);
|
|
26
|
+
this._clipboard = new DesktopClipboard(this);
|
|
27
|
+
this._cua = new DesktopCua(this);
|
|
28
|
+
}
|
|
29
|
+
/** Mouse control (move, click, drag, scroll) */
|
|
30
|
+
get mouse() {
|
|
31
|
+
return this._mouse;
|
|
32
|
+
}
|
|
33
|
+
/** Keyboard control (type, press, hotkey) */
|
|
34
|
+
get keyboard() {
|
|
35
|
+
return this._keyboard;
|
|
36
|
+
}
|
|
37
|
+
/** Screen capture and display info */
|
|
38
|
+
get screen() {
|
|
39
|
+
return this._screen;
|
|
40
|
+
}
|
|
41
|
+
/** Window management (list, focus, resize) */
|
|
42
|
+
get window() {
|
|
43
|
+
return this._window;
|
|
44
|
+
}
|
|
45
|
+
/** Clipboard read/write */
|
|
46
|
+
get clipboard() {
|
|
47
|
+
return this._clipboard;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* CUA (Computer Use Agent) - AI-powered desktop automation.
|
|
51
|
+
* Similar to Stagehand for browser automation.
|
|
52
|
+
*/
|
|
53
|
+
get cua() {
|
|
54
|
+
return this._cua;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Launch a browser that can be controlled via Playwright-style API.
|
|
58
|
+
* The browser runs on the desktop agent's machine.
|
|
59
|
+
*
|
|
60
|
+
* @param options - Browser launch options
|
|
61
|
+
* @returns Browser launch result with session, context, and page IDs
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* const browser = await desktop.launchBrowser({ headless: false });
|
|
66
|
+
* // Use browser.sessionId, browser.defaultContextId, browser.defaultPageId
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
async launchBrowser(options) {
|
|
70
|
+
return this.rpc('browser.launch', [options]);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Close a launched browser.
|
|
74
|
+
*/
|
|
75
|
+
async closeBrowser() {
|
|
76
|
+
await this.rpc('browser.close', []);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Check if a browser is running.
|
|
80
|
+
*/
|
|
81
|
+
async isBrowserRunning() {
|
|
82
|
+
return this.rpc('browser.isRunning', []);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Close the desktop session and clean up resources.
|
|
86
|
+
*/
|
|
87
|
+
async close() {
|
|
88
|
+
const headers = {};
|
|
89
|
+
if (this.apiKey) {
|
|
90
|
+
headers['Authorization'] = `Bearer ${this.apiKey}`;
|
|
91
|
+
}
|
|
92
|
+
const response = await fetchWithTimeout(`${this.baseUrl}/desktop/sessions/${this.id}`, { method: 'DELETE', headers }, DEFAULT_TIMEOUT_MS);
|
|
93
|
+
if (!response.ok) {
|
|
94
|
+
const text = await response.text();
|
|
95
|
+
throw new Error(`Failed to close desktop session ${this.id}: HTTP ${response.status} - ${text}`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Send an RPC call to the desktop agent.
|
|
100
|
+
* @internal
|
|
101
|
+
*/
|
|
102
|
+
async rpc(method, args, target = 'desktop') {
|
|
103
|
+
// CUA operations can be slow (AI processing)
|
|
104
|
+
const timeout = target === 'cua' ? LONG_TIMEOUT_MS : DEFAULT_TIMEOUT_MS;
|
|
105
|
+
const headers = {
|
|
106
|
+
'Content-Type': 'application/json',
|
|
107
|
+
};
|
|
108
|
+
if (this.apiKey) {
|
|
109
|
+
headers['Authorization'] = `Bearer ${this.apiKey}`;
|
|
110
|
+
}
|
|
111
|
+
const response = await fetchWithTimeout(`${this.baseUrl}/desktop/cmd`, {
|
|
112
|
+
method: 'POST',
|
|
113
|
+
headers,
|
|
114
|
+
body: JSON.stringify({
|
|
115
|
+
sessionId: this.id,
|
|
116
|
+
target,
|
|
117
|
+
method,
|
|
118
|
+
args,
|
|
119
|
+
}),
|
|
120
|
+
}, timeout);
|
|
121
|
+
if (!response.ok) {
|
|
122
|
+
const text = await response.text();
|
|
123
|
+
throw new Error(`Desktop RPC failed: target=${target}, method=${method}, sessionId=${this.id}, ` +
|
|
124
|
+
`status=${response.status}, message=${text}`);
|
|
125
|
+
}
|
|
126
|
+
return parseJsonResponse(response, `${target} RPC ${method} (session: ${this.id})`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
// ============================================================================
|
|
130
|
+
// Namespace Classes (exported for type access)
|
|
131
|
+
// ============================================================================
|
|
132
|
+
/**
|
|
133
|
+
* Mouse control for desktop automation.
|
|
134
|
+
* Provides move, click, drag, and scroll operations.
|
|
135
|
+
*/
|
|
136
|
+
export class DesktopMouse {
|
|
137
|
+
session;
|
|
138
|
+
constructor(session) {
|
|
139
|
+
this.session = session;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Move the mouse to the specified coordinates.
|
|
143
|
+
* @param x - Horizontal position in pixels (0 = left edge of screen)
|
|
144
|
+
* @param y - Vertical position in pixels (0 = top edge of screen)
|
|
145
|
+
*/
|
|
146
|
+
async move(x, y) {
|
|
147
|
+
await this.session.rpc('mouse.move', [x, y]);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Click at the current mouse position.
|
|
151
|
+
* @param button - Which mouse button to click (default: 'left')
|
|
152
|
+
*/
|
|
153
|
+
async click(button = 'left') {
|
|
154
|
+
await this.session.rpc('mouse.click', [button]);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Double-click at the current mouse position.
|
|
158
|
+
*/
|
|
159
|
+
async doubleClick() {
|
|
160
|
+
await this.session.rpc('mouse.doubleClick', []);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Drag from one position to another.
|
|
164
|
+
* @param fromX - Starting horizontal position
|
|
165
|
+
* @param fromY - Starting vertical position
|
|
166
|
+
* @param toX - Ending horizontal position
|
|
167
|
+
* @param toY - Ending vertical position
|
|
168
|
+
*/
|
|
169
|
+
async drag(fromX, fromY, toX, toY) {
|
|
170
|
+
await this.session.rpc('mouse.drag', [fromX, fromY, toX, toY]);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Scroll at the current mouse position.
|
|
174
|
+
* Positive values scroll down/right, negative scroll up/left.
|
|
175
|
+
* @param deltaX - Horizontal scroll amount in pixels
|
|
176
|
+
* @param deltaY - Vertical scroll amount in pixels
|
|
177
|
+
*/
|
|
178
|
+
async scroll(deltaX, deltaY) {
|
|
179
|
+
await this.session.rpc('mouse.scroll', [deltaX, deltaY]);
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Get the current mouse position.
|
|
183
|
+
* @returns Object with x and y coordinates in pixels
|
|
184
|
+
*/
|
|
185
|
+
async position() {
|
|
186
|
+
return this.session.rpc('mouse.position', []);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Keyboard control for desktop automation.
|
|
191
|
+
* Provides typing, key presses, and hotkey combinations.
|
|
192
|
+
*/
|
|
193
|
+
export class DesktopKeyboard {
|
|
194
|
+
session;
|
|
195
|
+
constructor(session) {
|
|
196
|
+
this.session = session;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Type a string of text.
|
|
200
|
+
* @param text - Text to type
|
|
201
|
+
*/
|
|
202
|
+
async type(text) {
|
|
203
|
+
await this.session.rpc('keyboard.type', [text]);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Press a single key.
|
|
207
|
+
* @param key - Key to press (e.g., 'Enter', 'Tab', 'a')
|
|
208
|
+
*/
|
|
209
|
+
async press(key) {
|
|
210
|
+
await this.session.rpc('keyboard.press', [key]);
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Hold down a key.
|
|
214
|
+
* @param key - Key to hold down
|
|
215
|
+
*/
|
|
216
|
+
async down(key) {
|
|
217
|
+
await this.session.rpc('keyboard.down', [key]);
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Release a held key.
|
|
221
|
+
* @param key - Key to release
|
|
222
|
+
*/
|
|
223
|
+
async up(key) {
|
|
224
|
+
await this.session.rpc('keyboard.up', [key]);
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Press a hotkey combination.
|
|
228
|
+
* @param keys - Keys to press together (e.g., 'Ctrl', 'C')
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
* ```ts
|
|
232
|
+
* await keyboard.hotkey('Ctrl', 'C'); // Copy
|
|
233
|
+
* await keyboard.hotkey('Ctrl', 'Shift', 'T'); // Reopen closed tab
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
|
+
async hotkey(...keys) {
|
|
237
|
+
await this.session.rpc('keyboard.hotkey', [keys]);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Screen control for desktop automation.
|
|
242
|
+
* Provides capture and display information.
|
|
243
|
+
*/
|
|
244
|
+
export class DesktopScreen {
|
|
245
|
+
session;
|
|
246
|
+
constructor(session) {
|
|
247
|
+
this.session = session;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Capture the screen or a region.
|
|
251
|
+
* @param region - Optional region to capture
|
|
252
|
+
* @returns PNG image as Buffer
|
|
253
|
+
*/
|
|
254
|
+
async capture(region) {
|
|
255
|
+
const base64 = await this.session.rpc('screen.capture', [region]);
|
|
256
|
+
return Buffer.from(base64, 'base64');
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Get the primary screen size.
|
|
260
|
+
* @returns Screen dimensions in pixels
|
|
261
|
+
*/
|
|
262
|
+
async size() {
|
|
263
|
+
return this.session.rpc('screen.size', []);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Window management for desktop automation.
|
|
268
|
+
* Provides listing, focusing, and resizing windows.
|
|
269
|
+
*/
|
|
270
|
+
export class DesktopWindow {
|
|
271
|
+
session;
|
|
272
|
+
constructor(session) {
|
|
273
|
+
this.session = session;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* List all visible windows.
|
|
277
|
+
* @returns Array of window information
|
|
278
|
+
*/
|
|
279
|
+
async list() {
|
|
280
|
+
return this.session.rpc('window.list', []);
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Get the currently active (focused) window.
|
|
284
|
+
* @returns Active window info or null if none
|
|
285
|
+
*/
|
|
286
|
+
async active() {
|
|
287
|
+
return this.session.rpc('window.active', []);
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Focus a window by handle.
|
|
291
|
+
* @param handle - Window handle from list()
|
|
292
|
+
*/
|
|
293
|
+
async focus(handle) {
|
|
294
|
+
await this.session.rpc('window.focus', [handle]);
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Get window bounds.
|
|
298
|
+
* @param handle - Window handle
|
|
299
|
+
* @returns Window position and size
|
|
300
|
+
*/
|
|
301
|
+
async bounds(handle) {
|
|
302
|
+
return this.session.rpc('window.bounds', [handle]);
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Set window bounds.
|
|
306
|
+
* @param handle - Window handle
|
|
307
|
+
* @param bounds - Partial bounds to set
|
|
308
|
+
*/
|
|
309
|
+
async setBounds(handle, bounds) {
|
|
310
|
+
await this.session.rpc('window.setBounds', [handle, bounds]);
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Minimize a window.
|
|
314
|
+
* @param handle - Window handle
|
|
315
|
+
*/
|
|
316
|
+
async minimize(handle) {
|
|
317
|
+
await this.session.rpc('window.minimize', [handle]);
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Maximize a window.
|
|
321
|
+
* @param handle - Window handle
|
|
322
|
+
*/
|
|
323
|
+
async maximize(handle) {
|
|
324
|
+
await this.session.rpc('window.maximize', [handle]);
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Restore a minimized/maximized window.
|
|
328
|
+
* @param handle - Window handle
|
|
329
|
+
*/
|
|
330
|
+
async restore(handle) {
|
|
331
|
+
await this.session.rpc('window.restore', [handle]);
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Close a window.
|
|
335
|
+
* @param handle - Window handle
|
|
336
|
+
*/
|
|
337
|
+
async close(handle) {
|
|
338
|
+
await this.session.rpc('window.close', [handle]);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Clipboard operations for desktop automation.
|
|
343
|
+
*/
|
|
344
|
+
export class DesktopClipboard {
|
|
345
|
+
session;
|
|
346
|
+
constructor(session) {
|
|
347
|
+
this.session = session;
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Read text from the clipboard.
|
|
351
|
+
* @returns Clipboard text content
|
|
352
|
+
*/
|
|
353
|
+
async read() {
|
|
354
|
+
return this.session.rpc('clipboard.read', []);
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Write text to the clipboard.
|
|
358
|
+
* @param text - Text to write
|
|
359
|
+
*/
|
|
360
|
+
async write(text) {
|
|
361
|
+
await this.session.rpc('clipboard.write', [text]);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* CUA (Computer Use Agent) - AI-powered desktop automation.
|
|
366
|
+
*
|
|
367
|
+
* Similar to Stagehand for browser automation, CUA provides:
|
|
368
|
+
* - run(): Execute multi-step tasks with AI guidance
|
|
369
|
+
* - predictClick(): Find elements using vision
|
|
370
|
+
*/
|
|
371
|
+
export class DesktopCua {
|
|
372
|
+
session;
|
|
373
|
+
constructor(session) {
|
|
374
|
+
this.session = session;
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Initialize the CUA agent.
|
|
378
|
+
* Must be called before using run() or predictClick().
|
|
379
|
+
*
|
|
380
|
+
* @param config - Agent configuration
|
|
381
|
+
*
|
|
382
|
+
* @example
|
|
383
|
+
* ```ts
|
|
384
|
+
* await desktop.cua.init({ model: 'claude-sonnet-4-5-20250929' });
|
|
385
|
+
* ```
|
|
386
|
+
*/
|
|
387
|
+
async init(config) {
|
|
388
|
+
return this.session.rpc('agent.init', [config], 'cua');
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Close the CUA agent and clean up resources.
|
|
392
|
+
*/
|
|
393
|
+
async close() {
|
|
394
|
+
await this.session.rpc('agent.close', [], 'cua');
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Run a computer-use task with AI guidance.
|
|
398
|
+
*
|
|
399
|
+
* Like Stagehand's act() but for desktop automation.
|
|
400
|
+
* The AI will analyze the screen and execute steps to complete the task.
|
|
401
|
+
*
|
|
402
|
+
* @param instruction - What task to perform
|
|
403
|
+
* @param options - Run options
|
|
404
|
+
*
|
|
405
|
+
* @example
|
|
406
|
+
* ```ts
|
|
407
|
+
* const result = await desktop.cua.run('Open Chrome and navigate to google.com');
|
|
408
|
+
* console.log(result.steps);
|
|
409
|
+
* ```
|
|
410
|
+
*/
|
|
411
|
+
async run(instruction, options) {
|
|
412
|
+
return this.session.rpc('run', [instruction, options], 'cua');
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Predict where to click to accomplish a task.
|
|
416
|
+
*
|
|
417
|
+
* Uses vision model to find elements on screen.
|
|
418
|
+
* Returns coordinates that can be used with mouse.move() and mouse.click().
|
|
419
|
+
*
|
|
420
|
+
* @param instruction - What to find on screen
|
|
421
|
+
*
|
|
422
|
+
* @example
|
|
423
|
+
* ```ts
|
|
424
|
+
* const { x, y } = await desktop.cua.predictClick('the submit button');
|
|
425
|
+
* await desktop.mouse.move(x, y);
|
|
426
|
+
* await desktop.mouse.click();
|
|
427
|
+
* ```
|
|
428
|
+
*/
|
|
429
|
+
async predictClick(instruction) {
|
|
430
|
+
return this.session.rpc('predictClick', [instruction], 'cua');
|
|
431
|
+
}
|
|
432
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handler function type for event listeners.
|
|
3
|
+
*/
|
|
4
|
+
export type Handler<T = unknown> = (event: T) => void;
|
|
5
|
+
/**
|
|
6
|
+
* The EventEmitter class that many Playwright classes extend.
|
|
7
|
+
*
|
|
8
|
+
* This provides a familiar event-driven interface for handling browser events
|
|
9
|
+
* like page load, console messages, dialogs, network requests, etc.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* page.on('console', msg => {
|
|
14
|
+
* console.log('Page logged:', msg.text());
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* page.once('load', () => {
|
|
18
|
+
* console.log('Page loaded!');
|
|
19
|
+
* });
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @see https://playwright.dev/docs/api/class-page#events
|
|
23
|
+
*/
|
|
24
|
+
export declare class PlaywrightEventEmitter<Events extends Record<string, unknown> = Record<string, unknown>> {
|
|
25
|
+
/**
|
|
26
|
+
* Map of event types to their listeners.
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
private _listeners;
|
|
30
|
+
private notifyFirstListener;
|
|
31
|
+
private notifyNoListeners;
|
|
32
|
+
/**
|
|
33
|
+
* Bind an event listener to fire when an event occurs.
|
|
34
|
+
*
|
|
35
|
+
* @param event - The event type to listen for.
|
|
36
|
+
* @param handler - The function to call when the event occurs.
|
|
37
|
+
* @returns `this` to allow for method chaining.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* page.on('request', request => {
|
|
42
|
+
* console.log('Request:', request.url());
|
|
43
|
+
* });
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @see https://playwright.dev/docs/api/class-page#page-event-request
|
|
47
|
+
*/
|
|
48
|
+
on<Key extends keyof Events>(event: Key, handler: Handler<Events[Key]>): this;
|
|
49
|
+
/**
|
|
50
|
+
* Remove an event listener.
|
|
51
|
+
*
|
|
52
|
+
* If `handler` is provided, only that specific listener is removed.
|
|
53
|
+
* If `handler` is not provided, all listeners for that event type are removed.
|
|
54
|
+
*
|
|
55
|
+
* @param event - The event type.
|
|
56
|
+
* @param handler - Optional specific handler to remove.
|
|
57
|
+
* @returns `this` to allow for method chaining.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* const handler = msg => console.log(msg);
|
|
62
|
+
* page.on('console', handler);
|
|
63
|
+
* // Later...
|
|
64
|
+
* page.off('console', handler);
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* @see https://playwright.dev/docs/api/class-page#page-remove-listener
|
|
68
|
+
*/
|
|
69
|
+
off<Key extends keyof Events>(event: Key, handler?: Handler<Events[Key]>): this;
|
|
70
|
+
/**
|
|
71
|
+
* Alias for off() - removes an event listener.
|
|
72
|
+
*
|
|
73
|
+
* @see https://playwright.dev/docs/api/class-page#page-remove-listener
|
|
74
|
+
*/
|
|
75
|
+
removeListener<Key extends keyof Events>(event: Key, handler: Handler<Events[Key]>): this;
|
|
76
|
+
/**
|
|
77
|
+
* Bind an event listener that will fire only once.
|
|
78
|
+
*
|
|
79
|
+
* After the handler is called once, it is automatically removed.
|
|
80
|
+
*
|
|
81
|
+
* @param event - The event type to listen for.
|
|
82
|
+
* @param handler - The function to call when the event occurs.
|
|
83
|
+
* @returns `this` to allow for method chaining.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* page.once('load', () => {
|
|
88
|
+
* console.log('Page loaded for the first time!');
|
|
89
|
+
* });
|
|
90
|
+
* ```
|
|
91
|
+
*
|
|
92
|
+
* @see https://playwright.dev/docs/api/class-page#page-wait-for-event
|
|
93
|
+
*/
|
|
94
|
+
once<Key extends keyof Events>(event: Key, handler: Handler<Events[Key]>): this;
|
|
95
|
+
/**
|
|
96
|
+
* Alias for on() - adds an event listener.
|
|
97
|
+
*
|
|
98
|
+
* @see https://playwright.dev/docs/api/class-page#page-event-console
|
|
99
|
+
*/
|
|
100
|
+
addListener<Key extends keyof Events>(event: Key, handler: Handler<Events[Key]>): this;
|
|
101
|
+
/**
|
|
102
|
+
* Emit an event, calling all registered handlers.
|
|
103
|
+
*
|
|
104
|
+
* This method is typically used internally by Playwright classes to dispatch
|
|
105
|
+
* events. Users rarely need to call this directly.
|
|
106
|
+
*
|
|
107
|
+
* @param event - The event type to emit.
|
|
108
|
+
* @param data - The event data to pass to handlers.
|
|
109
|
+
* @returns `true` if there were listeners for this event, `false` otherwise.
|
|
110
|
+
*/
|
|
111
|
+
emit<Key extends keyof Events>(event: Key, data: Events[Key]): boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Get the count of listeners for a specific event type.
|
|
114
|
+
*
|
|
115
|
+
* @param event - The event type.
|
|
116
|
+
* @returns The number of registered listeners.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* const count = page.listenerCount('request');
|
|
121
|
+
* console.log(`There are ${count} request listeners`);
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
listenerCount<Key extends keyof Events>(event: Key): number;
|
|
125
|
+
/**
|
|
126
|
+
* Remove all listeners.
|
|
127
|
+
*
|
|
128
|
+
* If `event` is provided, only listeners for that event type are removed.
|
|
129
|
+
* If `event` is not provided, all listeners for all event types are removed.
|
|
130
|
+
*
|
|
131
|
+
* @param event - Optional event type to remove listeners for.
|
|
132
|
+
* @returns `this` to allow for method chaining.
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```ts
|
|
136
|
+
* // Remove all 'request' listeners
|
|
137
|
+
* page.removeAllListeners('request');
|
|
138
|
+
*
|
|
139
|
+
* // Remove ALL listeners
|
|
140
|
+
* page.removeAllListeners();
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
removeAllListeners<Key extends keyof Events>(event?: Key): this;
|
|
144
|
+
/**
|
|
145
|
+
* PrependListener - adds a listener that will be called before other listeners.
|
|
146
|
+
*
|
|
147
|
+
* @param event - The event type to listen for.
|
|
148
|
+
* @param handler - The function to call when the event occurs.
|
|
149
|
+
* @returns `this` to allow for method chaining.
|
|
150
|
+
*/
|
|
151
|
+
prependListener<Key extends keyof Events>(event: Key, handler: Handler<Events[Key]>): this;
|
|
152
|
+
/**
|
|
153
|
+
* PrependOnceListener - adds a once listener that will be called before other listeners.
|
|
154
|
+
*
|
|
155
|
+
* @param event - The event type to listen for.
|
|
156
|
+
* @param handler - The function to call when the event occurs.
|
|
157
|
+
* @returns `this` to allow for method chaining.
|
|
158
|
+
*/
|
|
159
|
+
prependOnceListener<Key extends keyof Events>(event: Key, handler: Handler<Events[Key]>): this;
|
|
160
|
+
}
|