autokap 1.0.6 → 1.0.7

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.
Files changed (130) hide show
  1. package/assets/chrome/ios-statusbar-comparison-reference.jpg +0 -0
  2. package/assets/chrome/ios-statusbar-dark-reference.jpg +0 -0
  3. package/assets/chrome/ios-statusbar-light-reference.jpg +0 -0
  4. package/assets/devices/ipad-pro-11-m4.json +52 -0
  5. package/assets/devices/iphone-16-pro.json +53 -0
  6. package/assets/devices/macbook-air-13.json +45 -0
  7. package/assets/frames/MacBook Air 13.svg +242 -0
  8. package/assets/frames/Status bar - iPhone.png +0 -0
  9. Menu bar- iPad.png +0 -0
  10. package/assets/frames/iPad Pro M4 11_.png +0 -0
  11. package/assets/frames/iPhone 16 Pro.png +0 -0
  12. package/assets/icons/Cellular Connection.svg +3 -0
  13. package/assets/icons/Union.svg +6 -0
  14. package/assets/icons/Wifi.svg +3 -0
  15. package/assets/icons/battery.svg +5 -0
  16. package/assets/icons/battery_charging.svg +8 -0
  17. package/dist/abort.d.ts +5 -0
  18. package/dist/abort.js +44 -0
  19. package/dist/agent.d.ts +142 -0
  20. package/dist/agent.js +4511 -0
  21. package/dist/billing-operation-logging.d.ts +38 -0
  22. package/dist/billing-operation-logging.js +248 -0
  23. package/dist/browser-bar.d.ts +40 -0
  24. package/dist/browser-bar.js +147 -0
  25. package/dist/browser.d.ts +25 -0
  26. package/dist/browser.js +177 -9
  27. package/dist/capture-alt-text.d.ts +12 -0
  28. package/dist/capture-alt-text.js +51 -0
  29. package/dist/capture-encryption.d.ts +10 -0
  30. package/dist/capture-encryption.js +41 -0
  31. package/dist/capture-language-preflight.d.ts +41 -0
  32. package/dist/capture-language-preflight.js +286 -0
  33. package/dist/capture-llm-page-identity.d.ts +15 -0
  34. package/dist/capture-llm-page-identity.js +116 -0
  35. package/dist/capture-model-resolution.d.ts +9 -0
  36. package/dist/capture-model-resolution.js +21 -0
  37. package/dist/capture-page-identity.d.ts +9 -0
  38. package/dist/capture-page-identity.js +219 -0
  39. package/dist/capture-preset-credentials.d.ts +12 -0
  40. package/dist/capture-preset-credentials.js +57 -0
  41. package/dist/capture-request-plan.d.ts +58 -0
  42. package/dist/capture-request-plan.js +216 -0
  43. package/dist/capture-run-optimizer.d.ts +139 -0
  44. package/dist/capture-run-optimizer.js +848 -0
  45. package/dist/capture-selector-memory.d.ts +26 -0
  46. package/dist/capture-selector-memory.js +327 -0
  47. package/dist/capture-session-profile-encryption.d.ts +2 -0
  48. package/dist/capture-session-profile-encryption.js +22 -0
  49. package/dist/capture-step-timeout.d.ts +10 -0
  50. package/dist/capture-step-timeout.js +30 -0
  51. package/dist/capture-studio-sync.d.ts +22 -0
  52. package/dist/capture-studio-sync.js +166 -0
  53. package/dist/capture-variant-state.d.ts +54 -0
  54. package/dist/capture-variant-state.js +156 -0
  55. package/dist/cli.js +15 -0
  56. package/dist/clip-orchestrator.d.ts +148 -0
  57. package/dist/clip-orchestrator.js +950 -0
  58. package/dist/clip-postprocess.d.ts +42 -0
  59. package/dist/clip-postprocess.js +192 -0
  60. package/dist/cost-logging.d.ts +27 -0
  61. package/dist/cost-logging.js +128 -0
  62. package/dist/credential-templates.d.ts +5 -0
  63. package/dist/credential-templates.js +60 -0
  64. package/dist/element-capture.d.ts +53 -0
  65. package/dist/element-capture.js +766 -0
  66. package/dist/hybrid-navigator.d.ts +138 -0
  67. package/dist/hybrid-navigator.js +468 -0
  68. package/dist/index.d.ts +15 -0
  69. package/dist/index.js +11 -0
  70. package/dist/llm-usage.d.ts +17 -0
  71. package/dist/llm-usage.js +45 -0
  72. package/dist/mockup-html.d.ts +119 -0
  73. package/dist/mockup-html.js +253 -0
  74. package/dist/mockup.d.ts +94 -0
  75. package/dist/mockup.js +608 -0
  76. package/dist/mouse-animation.d.ts +46 -0
  77. package/dist/mouse-animation.js +100 -0
  78. package/dist/overlay-utils.d.ts +14 -0
  79. package/dist/overlay-utils.js +13 -0
  80. package/dist/posthog.d.ts +4 -0
  81. package/dist/posthog.js +26 -0
  82. package/dist/prompt-cache.d.ts +10 -0
  83. package/dist/prompt-cache.js +24 -0
  84. package/dist/prompts.d.ts +167 -0
  85. package/dist/prompts.js +1165 -0
  86. package/dist/remote-browser.d.ts +191 -0
  87. package/dist/remote-browser.js +305 -0
  88. package/dist/security.d.ts +20 -0
  89. package/dist/security.js +569 -0
  90. package/dist/server-capture-runtime.d.ts +123 -0
  91. package/dist/server-capture-runtime.js +638 -0
  92. package/dist/server-credit-usage.d.ts +12 -0
  93. package/dist/server-credit-usage.js +41 -0
  94. package/dist/server-posthog.d.ts +2 -0
  95. package/dist/server-posthog.js +16 -0
  96. package/dist/server-project-webhooks.d.ts +45 -0
  97. package/dist/server-project-webhooks.js +97 -0
  98. package/dist/server-screenshot-watermark.d.ts +7 -0
  99. package/dist/server-screenshot-watermark.js +38 -0
  100. package/dist/session-profile.d.ts +86 -0
  101. package/dist/session-profile.js +1373 -0
  102. package/dist/sf-pro-fonts.d.ts +4 -0
  103. package/dist/sf-pro-fonts.js +7 -0
  104. package/dist/status-bar-l10n.d.ts +14 -0
  105. package/dist/status-bar-l10n.js +177 -0
  106. package/dist/status-bar.d.ts +44 -0
  107. package/dist/status-bar.js +336 -0
  108. package/dist/tools.d.ts +4 -0
  109. package/dist/tools.js +578 -0
  110. package/dist/video-agent.d.ts +143 -0
  111. package/dist/video-agent.js +4783 -0
  112. package/dist/video-observation.d.ts +36 -0
  113. package/dist/video-observation.js +192 -0
  114. package/dist/video-planner.d.ts +12 -0
  115. package/dist/video-planner.js +500 -0
  116. package/dist/video-prompts.d.ts +37 -0
  117. package/dist/video-prompts.js +554 -0
  118. package/dist/video-tools.d.ts +3 -0
  119. package/dist/video-tools.js +59 -0
  120. package/dist/video-variant-state.d.ts +29 -0
  121. package/dist/video-variant-state.js +80 -0
  122. package/dist/vision-model.d.ts +17 -0
  123. package/dist/vision-model.js +74 -0
  124. package/dist/ws-auth.d.ts +20 -0
  125. package/dist/ws-auth.js +67 -0
  126. package/dist/ws-handler.d.ts +10 -0
  127. package/dist/ws-handler.js +1663 -0
  128. package/dist/ws-server.d.ts +9 -0
  129. package/dist/ws-server.js +52 -0
  130. package/package.json +93 -39
@@ -0,0 +1,191 @@
1
+ /**
2
+ * RemoteBrowser — Server-side proxy that mirrors the Browser interface
3
+ * but forwards every method call to a remote CLI via WebSocket.
4
+ *
5
+ * Used by the WS server to control a Playwright browser running on the user's machine.
6
+ */
7
+ import type { WebSocket } from 'ws';
8
+ import type { PageState, PageStateLite, InteractiveElement, BrowserStorageState, BrowserSessionStorageState, VideoPageSignals, OutscaleConfig, SelectorValidationResult } from './types.js';
9
+ import type { BrowserObservation, BrowserReaction, BrowserSelectorProbe, BrowserStorageHintWriteParams, BrowserVerificationBundle, BrowserVideoVerificationBundle } from './browser.js';
10
+ export interface WsCommand {
11
+ id: string;
12
+ method: string;
13
+ params: Record<string, unknown>;
14
+ }
15
+ export interface WsResult {
16
+ id: string;
17
+ result?: unknown;
18
+ error?: string;
19
+ }
20
+ export interface WsEvent {
21
+ type: 'done' | 'error' | 'progress';
22
+ message?: string;
23
+ summary?: {
24
+ successes: number;
25
+ total: number;
26
+ };
27
+ }
28
+ export declare const REMOTE_BROWSER_PROTOCOL_VERSION = 2;
29
+ export interface RemoteBrowserClientInfo {
30
+ version?: string;
31
+ protocolVersion?: number;
32
+ }
33
+ export interface WsClientHello {
34
+ type: 'client_hello';
35
+ client: RemoteBrowserClientInfo;
36
+ }
37
+ export declare function buildRemoteBrowserClientHello(version: string): WsClientHello;
38
+ export declare function getRemoteBrowserCompatibilityError(client: RemoteBrowserClientInfo | null | undefined): string | null;
39
+ /**
40
+ * Lightweight proxy for `browser.currentPage` — only exposes the methods
41
+ * that `runAgent` actually calls: `.url()`, `.viewportSize()`, `.title()`.
42
+ */
43
+ declare class RemotePageProxy {
44
+ private callFn;
45
+ constructor(callFn: (method: string, params: Record<string, unknown>) => Promise<unknown>);
46
+ url(): string;
47
+ viewportSize(): {
48
+ width: number;
49
+ height: number;
50
+ } | null;
51
+ title(): Promise<string>;
52
+ _cachedUrl: string;
53
+ _cachedViewport: {
54
+ width: number;
55
+ height: number;
56
+ } | null;
57
+ _sync(): Promise<void>;
58
+ }
59
+ export declare class RemoteBrowser {
60
+ private ws;
61
+ private pending;
62
+ private idCounter;
63
+ private _pageProxy;
64
+ /** Proxy for browser.currentPage — provides url(), viewportSize(), title() */
65
+ get currentPage(): RemotePageProxy;
66
+ constructor(ws: WebSocket);
67
+ launch(): Promise<void>;
68
+ close(): Promise<void>;
69
+ closeContext(): Promise<void>;
70
+ recreateContext(options: {
71
+ viewport?: {
72
+ width: number;
73
+ height: number;
74
+ };
75
+ deviceScaleFactor?: number;
76
+ lang?: string;
77
+ colorScheme?: 'light' | 'dark';
78
+ storageState?: BrowserStorageState;
79
+ }): Promise<void>;
80
+ setDeviceScaleFactor(deviceScaleFactor: number): Promise<void>;
81
+ navigateTo(url: string): Promise<void>;
82
+ addCookies(cookies: Array<Record<string, unknown>>): Promise<void>;
83
+ takeScreenshot(): Promise<Buffer>;
84
+ takeScreenshotForAI(options?: {
85
+ timeoutMs?: number;
86
+ }): Promise<Buffer>;
87
+ screenshotElement(index: number, padding?: number): Promise<Buffer>;
88
+ screenshotRegion(x: number, y: number, width: number, height: number, padding?: number): Promise<Buffer>;
89
+ screenshotBySelector(selector: string, outscale?: OutscaleConfig | number): Promise<{
90
+ buffer: Buffer;
91
+ validation: SelectorValidationResult;
92
+ }>;
93
+ screenshotByRegion(region: {
94
+ x: number;
95
+ y: number;
96
+ width: number;
97
+ height: number;
98
+ }, outscale?: OutscaleConfig | number): Promise<Buffer>;
99
+ getPageState(opts?: {
100
+ skipAnnotation?: boolean;
101
+ }): Promise<PageState>;
102
+ getPageStateLite(): Promise<PageStateLite>;
103
+ getAccessibilityTree(options?: {
104
+ timeoutMs?: number;
105
+ }): Promise<string>;
106
+ getInteractiveElements(options?: {
107
+ timeoutMs?: number;
108
+ }): Promise<InteractiveElement[]>;
109
+ getSimplifiedDOM(): Promise<string>;
110
+ captureObservation(): Promise<BrowserObservation>;
111
+ capturePageSignals(options?: {
112
+ timeoutMs?: number;
113
+ }): Promise<VideoPageSignals>;
114
+ captureVerificationBundle(options?: {
115
+ settleMs?: number;
116
+ maxAttempts?: number;
117
+ }): Promise<BrowserVerificationBundle>;
118
+ captureVideoVerificationBundle(options?: {
119
+ settleMs?: number;
120
+ maxAttempts?: number;
121
+ helperTimeoutMs?: number;
122
+ }): Promise<BrowserVideoVerificationBundle>;
123
+ clickByIndex(index: number): Promise<void>;
124
+ clickBySelector(selector: string, options?: {
125
+ force?: boolean;
126
+ }): Promise<void>;
127
+ clickByCoordinates(x: number, y: number): Promise<void>;
128
+ hoverByIndex(index: number): Promise<void>;
129
+ hoverBySelector(selector: string): Promise<void>;
130
+ hoverByCoordinates(x: number, y: number): Promise<void>;
131
+ typeText(text: string, options?: {
132
+ index?: number;
133
+ selector?: string;
134
+ clearFirst?: boolean;
135
+ }): Promise<void>;
136
+ selectOption(options: {
137
+ index?: number;
138
+ selector?: string;
139
+ optionLabel?: string;
140
+ optionValue?: string;
141
+ optionIndex?: number;
142
+ }): Promise<void>;
143
+ scroll(direction: string, amount?: number, selector?: string): Promise<void>;
144
+ scrollElementIntoView(index: number, options?: {
145
+ align?: 'start' | 'center' | 'end';
146
+ margin?: number;
147
+ }): Promise<void>;
148
+ safeExpand(options: {
149
+ index?: number;
150
+ selector?: string;
151
+ expectedText?: string;
152
+ expectedSelector?: string;
153
+ }): Promise<void>;
154
+ pressKey(key: string): Promise<void>;
155
+ searchText(query: string): Promise<Array<Record<string, unknown>>>;
156
+ waitForPageReaction(before?: BrowserObservation, options?: {
157
+ timeoutMs?: number;
158
+ settleMs?: number;
159
+ idleGraceMs?: number;
160
+ }): Promise<BrowserReaction>;
161
+ wait(ms: number): Promise<void>;
162
+ dismissOverlays(): Promise<{
163
+ dismissed: boolean;
164
+ method: string | null;
165
+ }>;
166
+ setColorScheme(scheme: 'light' | 'dark'): Promise<void>;
167
+ setLanguage(lang: string): Promise<void>;
168
+ resizeViewport(width: number, height: number): Promise<void>;
169
+ forceLoadLazyImages(options?: {
170
+ timeout?: number;
171
+ }): Promise<void>;
172
+ exportStorageState(): Promise<BrowserStorageState>;
173
+ exportSessionStorage(): Promise<BrowserSessionStorageState>;
174
+ reloadCurrentPage(options?: {
175
+ waitUntil?: 'load' | 'domcontentloaded' | 'networkidle' | 'commit';
176
+ timeout?: number;
177
+ }): Promise<void>;
178
+ writeStorageHintCandidate(params: BrowserStorageHintWriteParams): Promise<boolean>;
179
+ probeSelector(selector: string): Promise<BrowserSelectorProbe | null>;
180
+ prepareSessionStorage(bundle: BrowserSessionStorageState | undefined, options?: {
181
+ replace?: boolean;
182
+ }): Promise<void>;
183
+ observeNetworkRequests(url: string, waitMs?: number): Promise<Array<Record<string, unknown>>>;
184
+ setupRouteInterception(mocks: Array<Record<string, unknown>>): Promise<void>;
185
+ clearRouteInterception(): Promise<void>;
186
+ private call;
187
+ private callAndSyncPageInfo;
188
+ sendEvent(event: WsEvent): void;
189
+ destroy(): void;
190
+ }
191
+ export {};
@@ -0,0 +1,305 @@
1
+ /**
2
+ * RemoteBrowser — Server-side proxy that mirrors the Browser interface
3
+ * but forwards every method call to a remote CLI via WebSocket.
4
+ *
5
+ * Used by the WS server to control a Playwright browser running on the user's machine.
6
+ */
7
+ export const REMOTE_BROWSER_PROTOCOL_VERSION = 2;
8
+ export function buildRemoteBrowserClientHello(version) {
9
+ return {
10
+ type: 'client_hello',
11
+ client: {
12
+ version,
13
+ protocolVersion: REMOTE_BROWSER_PROTOCOL_VERSION,
14
+ },
15
+ };
16
+ }
17
+ export function getRemoteBrowserCompatibilityError(client) {
18
+ if (!client) {
19
+ return 'Installed AutoKap CLI is too old for this server. Update the CLI and retry.';
20
+ }
21
+ if ((client.protocolVersion ?? 0) < REMOTE_BROWSER_PROTOCOL_VERSION) {
22
+ const versionLabel = client.version ? ` ${client.version}` : '';
23
+ return `Installed AutoKap CLI${versionLabel} is too old for this server. Update the CLI and retry.`;
24
+ }
25
+ return null;
26
+ }
27
+ const DEFAULT_TIMEOUT_MS = 60_000;
28
+ /**
29
+ * Lightweight proxy for `browser.currentPage` — only exposes the methods
30
+ * that `runAgent` actually calls: `.url()`, `.viewportSize()`, `.title()`.
31
+ */
32
+ class RemotePageProxy {
33
+ callFn;
34
+ constructor(callFn) {
35
+ this.callFn = callFn;
36
+ }
37
+ url() {
38
+ // Synchronous in Playwright but we cache the last known value.
39
+ // The agent calls this frequently — we use a sync fallback via _cachedUrl.
40
+ return this._cachedUrl;
41
+ }
42
+ viewportSize() {
43
+ return this._cachedViewport;
44
+ }
45
+ async title() {
46
+ return await this.callFn('getPageTitle', {});
47
+ }
48
+ _cachedUrl = '';
49
+ _cachedViewport = null;
50
+ async _sync() {
51
+ const state = await this.callFn('getPageInfo', {});
52
+ this._cachedUrl = state.url;
53
+ this._cachedViewport = state.viewport;
54
+ }
55
+ }
56
+ export class RemoteBrowser {
57
+ ws;
58
+ pending = new Map();
59
+ idCounter = 0;
60
+ _pageProxy;
61
+ /** Proxy for browser.currentPage — provides url(), viewportSize(), title() */
62
+ get currentPage() {
63
+ return this._pageProxy;
64
+ }
65
+ constructor(ws) {
66
+ this.ws = ws;
67
+ this._pageProxy = new RemotePageProxy((method, params) => this.call(method, params));
68
+ this.ws.on('message', (data) => {
69
+ try {
70
+ const msg = JSON.parse(typeof data === 'string' ? data : data.toString('utf-8'));
71
+ const call = this.pending.get(msg.id);
72
+ if (!call)
73
+ return;
74
+ this.pending.delete(msg.id);
75
+ clearTimeout(call.timer);
76
+ if (msg.error) {
77
+ call.reject(new Error(msg.error));
78
+ }
79
+ else {
80
+ call.resolve(msg.result);
81
+ }
82
+ }
83
+ catch { /* ignore malformed messages */ }
84
+ });
85
+ }
86
+ // ── Lifecycle ────────────────────────────────────────────────────
87
+ async launch() {
88
+ await this.call('launch', {});
89
+ }
90
+ async close() {
91
+ await this.call('close', {});
92
+ }
93
+ async closeContext() {
94
+ await this.call('closeContext', {});
95
+ }
96
+ async recreateContext(options) {
97
+ await this.call('recreateContext', options);
98
+ await this._pageProxy._sync();
99
+ }
100
+ async setDeviceScaleFactor(deviceScaleFactor) {
101
+ await this.call('setDeviceScaleFactor', { deviceScaleFactor });
102
+ await this._pageProxy._sync();
103
+ }
104
+ // ── Navigation ───────────────────────────────────────────────────
105
+ async navigateTo(url) {
106
+ await this.call('navigateTo', { url });
107
+ await this._pageProxy._sync();
108
+ }
109
+ async addCookies(cookies) {
110
+ await this.call('addCookies', { cookies });
111
+ }
112
+ // ── Screenshots ──────────────────────────────────────────────────
113
+ async takeScreenshot() {
114
+ const r = await this.call('takeScreenshot', {});
115
+ return Buffer.from(r.screenshot, 'base64');
116
+ }
117
+ async takeScreenshotForAI(options) {
118
+ const r = await this.call('takeScreenshotForAI', options ?? {});
119
+ return Buffer.from(r.screenshot, 'base64');
120
+ }
121
+ async screenshotElement(index, padding) {
122
+ const r = await this.call('screenshotElement', { index, padding });
123
+ return Buffer.from(r.screenshot, 'base64');
124
+ }
125
+ async screenshotRegion(x, y, width, height, padding) {
126
+ const r = await this.call('screenshotRegion', { x, y, width, height, padding });
127
+ return Buffer.from(r.screenshot, 'base64');
128
+ }
129
+ async screenshotBySelector(selector, outscale) {
130
+ const r = await this.call('screenshotBySelector', { selector, outscale });
131
+ return { buffer: Buffer.from(r.buffer, 'base64'), validation: r.validation };
132
+ }
133
+ async screenshotByRegion(region, outscale) {
134
+ const r = await this.call('screenshotByRegion', { region, outscale });
135
+ return Buffer.from(r.screenshot, 'base64');
136
+ }
137
+ // ── Page State ───────────────────────────────────────────────────
138
+ async getPageState(opts) {
139
+ const r = await this.call('getPageState', opts ?? {});
140
+ // Sync page info from the response metadata if available, or fetch separately
141
+ await this._pageProxy._sync();
142
+ return {
143
+ ...r,
144
+ cleanScreenshot: Buffer.from(r.cleanScreenshot, 'base64'),
145
+ screenshot: Buffer.from(r.screenshot, 'base64'),
146
+ };
147
+ }
148
+ async getPageStateLite() {
149
+ return await this.call('getPageStateLite', {});
150
+ }
151
+ async getAccessibilityTree(options) {
152
+ return await this.call('getAccessibilityTree', options ?? {});
153
+ }
154
+ async getInteractiveElements(options) {
155
+ return await this.call('getInteractiveElements', options ?? {});
156
+ }
157
+ async getSimplifiedDOM() {
158
+ return await this.call('getSimplifiedDOM', {});
159
+ }
160
+ async captureObservation() {
161
+ return await this.call('captureObservation', {});
162
+ }
163
+ async capturePageSignals(options) {
164
+ return await this.call('capturePageSignals', options ?? {});
165
+ }
166
+ async captureVerificationBundle(options) {
167
+ const r = await this.call('captureVerificationBundle', options ?? {});
168
+ return {
169
+ ...r,
170
+ screenshot: Buffer.from(r.screenshot, 'base64'),
171
+ };
172
+ }
173
+ async captureVideoVerificationBundle(options) {
174
+ const r = await this.call('captureVideoVerificationBundle', options ?? {});
175
+ return {
176
+ ...r,
177
+ screenshot: Buffer.from(r.screenshot, 'base64'),
178
+ };
179
+ }
180
+ // ── Interactions ─────────────────────────────────────────────────
181
+ async clickByIndex(index) {
182
+ await this.callAndSyncPageInfo('clickByIndex', { index });
183
+ }
184
+ async clickBySelector(selector, options) {
185
+ await this.callAndSyncPageInfo('clickBySelector', { selector, ...options });
186
+ }
187
+ async clickByCoordinates(x, y) {
188
+ await this.callAndSyncPageInfo('clickByCoordinates', { x, y });
189
+ }
190
+ async hoverByIndex(index) {
191
+ await this.call('hoverByIndex', { index });
192
+ }
193
+ async hoverBySelector(selector) {
194
+ await this.call('hoverBySelector', { selector });
195
+ }
196
+ async hoverByCoordinates(x, y) {
197
+ await this.call('hoverByCoordinates', { x, y });
198
+ }
199
+ async typeText(text, options) {
200
+ await this.callAndSyncPageInfo('typeText', { text, ...options });
201
+ }
202
+ async selectOption(options) {
203
+ await this.callAndSyncPageInfo('selectOption', options);
204
+ }
205
+ async scroll(direction, amount, selector) {
206
+ await this.callAndSyncPageInfo('scroll', { direction, amount, selector });
207
+ }
208
+ async scrollElementIntoView(index, options) {
209
+ await this.callAndSyncPageInfo('scrollElementIntoView', { index, ...options });
210
+ }
211
+ async safeExpand(options) {
212
+ await this.callAndSyncPageInfo('safeExpand', options);
213
+ }
214
+ async pressKey(key) {
215
+ await this.callAndSyncPageInfo('pressKey', { key });
216
+ }
217
+ async searchText(query) {
218
+ return await this.call('searchText', { query });
219
+ }
220
+ // ── Reactions ────────────────────────────────────────────────────
221
+ async waitForPageReaction(before, options) {
222
+ const reaction = await this.call('waitForPageReaction', { before, ...options });
223
+ await this._pageProxy._sync();
224
+ return reaction;
225
+ }
226
+ // ── UI Manipulation ──────────────────────────────────────────────
227
+ async wait(ms) {
228
+ await this.call('wait', { ms });
229
+ }
230
+ async dismissOverlays() {
231
+ const result = await this.call('dismissOverlays', {});
232
+ await this._pageProxy._sync();
233
+ return result;
234
+ }
235
+ async setColorScheme(scheme) {
236
+ await this.callAndSyncPageInfo('setColorScheme', { scheme });
237
+ }
238
+ async setLanguage(lang) {
239
+ await this.callAndSyncPageInfo('setLanguage', { lang });
240
+ }
241
+ async resizeViewport(width, height) {
242
+ await this.call('resizeViewport', { width, height });
243
+ this._pageProxy._cachedViewport = { width, height };
244
+ }
245
+ async forceLoadLazyImages(options) {
246
+ await this.call('forceLoadLazyImages', options ?? {});
247
+ }
248
+ // ── Storage ──────────────────────────────────────────────────────
249
+ async exportStorageState() {
250
+ return await this.call('exportStorageState', {});
251
+ }
252
+ async exportSessionStorage() {
253
+ return await this.call('exportSessionStorage', {});
254
+ }
255
+ async reloadCurrentPage(options) {
256
+ await this.callAndSyncPageInfo('reloadCurrentPage', options ?? {});
257
+ }
258
+ async writeStorageHintCandidate(params) {
259
+ return await this.call('writeStorageHintCandidate', params);
260
+ }
261
+ async probeSelector(selector) {
262
+ return await this.call('probeSelector', { selector });
263
+ }
264
+ async prepareSessionStorage(bundle, options) {
265
+ await this.call('prepareSessionStorage', { bundle, ...options });
266
+ }
267
+ // ── Network ──────────────────────────────────────────────────────
268
+ async observeNetworkRequests(url, waitMs) {
269
+ return await this.call('observeNetworkRequests', { url, waitMs });
270
+ }
271
+ async setupRouteInterception(mocks) {
272
+ await this.call('setupRouteInterception', { mocks });
273
+ }
274
+ async clearRouteInterception() {
275
+ await this.call('clearRouteInterception', {});
276
+ }
277
+ // ── RPC core ─────────────────────────────────────────────────────
278
+ call(method, params, timeoutMs = DEFAULT_TIMEOUT_MS) {
279
+ return new Promise((resolve, reject) => {
280
+ const id = `cmd_${++this.idCounter}`;
281
+ const timer = setTimeout(() => {
282
+ this.pending.delete(id);
283
+ reject(new Error(`RemoteBrowser: timeout waiting for ${method} (${timeoutMs}ms)`));
284
+ }, timeoutMs);
285
+ this.pending.set(id, { resolve, reject, timer });
286
+ this.ws.send(JSON.stringify({ id, method, params }));
287
+ });
288
+ }
289
+ async callAndSyncPageInfo(method, params) {
290
+ const result = await this.call(method, params);
291
+ await this._pageProxy._sync();
292
+ return result;
293
+ }
294
+ sendEvent(event) {
295
+ this.ws.send(JSON.stringify(event));
296
+ }
297
+ destroy() {
298
+ for (const [, call] of this.pending) {
299
+ clearTimeout(call.timer);
300
+ call.reject(new Error('RemoteBrowser: connection closed'));
301
+ }
302
+ this.pending.clear();
303
+ }
304
+ }
305
+ //# sourceMappingURL=remote-browser.js.map
@@ -0,0 +1,20 @@
1
+ import type { ActionType, AgentConfig, CaptureObjective, CaptureRepairCause, InteractiveElement } from './types.js';
2
+ export interface SecurityContext {
3
+ rootUrl?: string;
4
+ currentUrl?: string;
5
+ credentials?: AgentConfig['credentials'];
6
+ interactiveElements: InteractiveElement[];
7
+ currentLang?: string;
8
+ currentTheme?: 'light' | 'dark';
9
+ runMode?: AgentConfig['runMode'];
10
+ currentObjective?: CaptureObjective;
11
+ activeRepairCause?: CaptureRepairCause | null;
12
+ }
13
+ export interface SecurityDecision {
14
+ allowed: boolean;
15
+ reason?: string;
16
+ target?: InteractiveElement | null;
17
+ }
18
+ export declare function evaluateResolvedActionSecurity(action: ActionType, args: Record<string, unknown>, context: SecurityContext, target: InteractiveElement | null): SecurityDecision;
19
+ export declare function evaluateActionSecurity(action: ActionType, args: Record<string, unknown>, context: SecurityContext): SecurityDecision;
20
+ export declare function describeSecurityTarget(target: InteractiveElement | null | undefined): string;