@jackwener/browsermcp 0.0.42-embedded.0 → 0.0.43

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 (102) hide show
  1. package/CHANGELOG.md +3 -60
  2. package/README.md +0 -91
  3. package/dist/docs/api-use.md +2 -0
  4. package/dist/src/api/api.js +3 -1
  5. package/dist/src/api/api.js.map +1 -1
  6. package/dist/src/api/tab.js +70 -0
  7. package/dist/src/api/tab.js.map +1 -1
  8. package/dist/src/docs/manifest.js +3 -6
  9. package/dist/src/docs/manifest.js.map +1 -1
  10. package/dist/src/mcp/server.js +3 -2
  11. package/dist/src/mcp/server.js.map +1 -1
  12. package/dist/src/runtime/runtime.js +28 -2
  13. package/dist/src/runtime/runtime.js.map +1 -1
  14. package/docs/api-use.md +2 -0
  15. package/package.json +2 -11
  16. package/dist/src/api/action-input.d.ts +0 -87
  17. package/dist/src/api/agent.d.ts +0 -10
  18. package/dist/src/api/api.d.ts +0 -54
  19. package/dist/src/api/browser.d.ts +0 -93
  20. package/dist/src/api/commands.d.ts +0 -514
  21. package/dist/src/api/content-wait.d.ts +0 -18
  22. package/dist/src/api/context.d.ts +0 -7
  23. package/dist/src/api/diff.d.ts +0 -8
  24. package/dist/src/api/errors.d.ts +0 -14
  25. package/dist/src/api/network.d.ts +0 -10
  26. package/dist/src/api/observation.d.ts +0 -4
  27. package/dist/src/api/streams.d.ts +0 -13
  28. package/dist/src/api/tab.d.ts +0 -352
  29. package/dist/src/api/webmcp.d.ts +0 -19
  30. package/dist/src/backends/backend.d.ts +0 -14
  31. package/dist/src/backends/browser-helpers.d.ts +0 -17
  32. package/dist/src/backends/extension-page.d.ts +0 -5
  33. package/dist/src/backends/managed-page.d.ts +0 -50
  34. package/dist/src/backends/page-transport.d.ts +0 -10
  35. package/dist/src/backends/page-types.d.ts +0 -82
  36. package/dist/src/docs/embedded.d.ts +0 -2
  37. package/dist/src/docs/embedded.js +0 -40
  38. package/dist/src/docs/embedded.js.map +0 -1
  39. package/dist/src/docs/manifest.d.ts +0 -23
  40. package/dist/src/docs/surface.d.ts +0 -12
  41. package/dist/src/electron/backend.d.ts +0 -50
  42. package/dist/src/electron/backend.js +0 -377
  43. package/dist/src/electron/backend.js.map +0 -1
  44. package/dist/src/electron/chrome.d.ts +0 -24
  45. package/dist/src/electron/chrome.js +0 -133
  46. package/dist/src/electron/chrome.js.map +0 -1
  47. package/dist/src/electron/driver.d.ts +0 -70
  48. package/dist/src/electron/driver.js +0 -316
  49. package/dist/src/electron/driver.js.map +0 -1
  50. package/dist/src/electron/event-buffer.d.ts +0 -16
  51. package/dist/src/electron/event-buffer.js +0 -59
  52. package/dist/src/electron/event-buffer.js.map +0 -1
  53. package/dist/src/electron/page.js +0 -1030
  54. package/dist/src/electron/registry.d.ts +0 -104
  55. package/dist/src/electron/registry.js +0 -316
  56. package/dist/src/electron/registry.js.map +0 -1
  57. package/dist/src/electron/streams.d.ts +0 -16
  58. package/dist/src/electron/streams.js +0 -48
  59. package/dist/src/electron/streams.js.map +0 -1
  60. package/dist/src/embedded/index.d.ts +0 -49
  61. package/dist/src/embedded/index.js +0 -85
  62. package/dist/src/embedded/index.js.map +0 -1
  63. package/dist/src/host/bridge.d.ts +0 -50
  64. package/dist/src/host/doctor.d.ts +0 -34
  65. package/dist/src/host/extension.d.ts +0 -3
  66. package/dist/src/host/host.d.ts +0 -3
  67. package/dist/src/host/ipc.d.ts +0 -14
  68. package/dist/src/host/jsonc-config.d.ts +0 -1
  69. package/dist/src/host/launch.d.ts +0 -11
  70. package/dist/src/host/native-messaging.d.ts +0 -28
  71. package/dist/src/host/opencode.d.ts +0 -6
  72. package/dist/src/host/pi.d.ts +0 -6
  73. package/dist/src/host/registration.d.ts +0 -24
  74. package/dist/src/host/setup.d.ts +0 -7
  75. package/dist/src/host/socket.d.ts +0 -25
  76. package/dist/src/host/state.d.ts +0 -39
  77. package/dist/src/launcher/stdio.d.ts +0 -3
  78. package/dist/src/lib/paths.d.ts +0 -1
  79. package/dist/src/lib/sources.d.ts +0 -5
  80. package/dist/src/main.d.ts +0 -2
  81. package/dist/src/mcp/catalog.d.ts +0 -202
  82. package/dist/src/mcp/js-session.d.ts +0 -64
  83. package/dist/src/mcp/server.d.ts +0 -15
  84. package/dist/src/protocol.d.ts +0 -340
  85. package/dist/src/recon/analyzer.d.ts +0 -43
  86. package/dist/src/recon/discover.d.ts +0 -48
  87. package/dist/src/runtime/runtime.d.ts +0 -230
  88. package/dist/src/shared/api-contract.d.ts +0 -86
  89. package/dist/src/shared/aria-tree.d.ts +0 -2
  90. package/dist/src/shared/closed-shadow.d.ts +0 -10
  91. package/dist/src/shared/element-ref.d.ts +0 -4
  92. package/dist/src/shared/engine.d.ts +0 -62
  93. package/dist/src/shared/inflight.d.ts +0 -14
  94. package/dist/src/shared/injected-source.d.ts +0 -2
  95. package/dist/src/shared/page-contract.d.ts +0 -278
  96. package/dist/src/sites/define.d.ts +0 -28
  97. package/dist/src/sites/drafts.d.ts +0 -39
  98. package/dist/src/sites/executor.d.ts +0 -34
  99. package/dist/src/sites/loader.d.ts +0 -101
  100. package/dist/src/sites/manifest.d.ts +0 -5
  101. package/dist/src/sites/schema.d.ts +0 -11
  102. package/dist/src/version.d.ts +0 -2
@@ -1,15 +0,0 @@
1
- /**
2
- * MCP server per session: REPL entry, dynamic site tools, diagnostics and cleanup,
3
- * resources (docs, sites) and prompts — all backed by the same object model.
4
- */
5
- import { McpServer } from '@modelcontextprotocol/server';
6
- import type { Runtime } from '../runtime/runtime.js';
7
- import { type AgentApi } from '../api/agent.js';
8
- export interface SessionServer {
9
- server: McpServer;
10
- api: AgentApi;
11
- close(): Promise<void>;
12
- }
13
- export declare function createMcpServer(rt: Runtime, sessionId: string, opts?: {
14
- version?: string;
15
- }): SessionServer;
@@ -1,340 +0,0 @@
1
- /**
2
- * browsermcp host ⇄ extension protocol.
3
- *
4
- * Transport: Chrome Native Messaging (4-byte LE length + JSON) between the
5
- * Chrome-spawned host process and the extension service worker. The host is
6
- * the MCP server; the extension is the browser runtime that owns the
7
- * chrome.debugger session, tab leases, tab groups, and cursor overlay.
8
- *
9
- * Envelope kinds:
10
- * host → ext: { type: 'command', command: Command }
11
- * ext → host: { type: 'hello', ... } | { type: 'result', result: Result } | { type: 'event', event: BrowserEvent }
12
- */
13
- export type Action = 'chrome-call' | 'chrome-describe' | 'stream-watch' | 'stream-read' | 'stream-close' | 'streams-reset' | 'extension-logs' | 'exec' | 'navigate' | 'tabs' | 'cookies' | 'screenshot' | 'network-capture-start' | 'network-capture-read' | 'wait-download' | 'cdp' | 'frames' | 'session-name' | 'session-finalize' | 'user-tabs' | 'claim' | 'close-user-tabs' | 'mark' | 'dialog' | 'history' | 'console' | 'act' | 'cursor' | 'visibility' | 'ping';
14
- export interface Command {
15
- id: string;
16
- action: Action;
17
- /** Logical session (one MCP session ⇄ one named tab group). */
18
- session?: string;
19
- /** Surface policy: interactive browser session vs. background adapter run. */
20
- surface?: 'browser' | 'adapter';
21
- /** Stable Chrome tab id, encoded as a string; the extension checks session ownership. */
22
- page?: string;
23
- code?: string;
24
- chromeMethod?: string;
25
- chromeArgs?: unknown[];
26
- streamSource?: 'chrome' | 'cdp' | 'console' | 'extension';
27
- eventName?: string;
28
- streamId?: string;
29
- streamOptions?: StreamOptions;
30
- streamRead?: StreamReadOptions;
31
- cdpTarget?: {
32
- frameId: string;
33
- };
34
- /** exec: evaluate in the page's main world (default) or in the engine's isolated world */
35
- world?: 'main' | 'engine';
36
- url?: string;
37
- op?: 'list' | 'new' | 'close' | 'release';
38
- dialogOp?: 'get' | 'accept' | 'dismiss';
39
- historyOp?: 'reload' | 'back' | 'forward';
40
- /** console read: cursor paging */
41
- afterSequence?: number;
42
- limit?: number;
43
- /** user-tabs: case-insensitive literal title or URL substring; paginated discovery envelope. */
44
- offset?: number;
45
- query?: string;
46
- levels?: string[];
47
- filter?: string;
48
- domain?: string;
49
- format?: 'png' | 'jpeg';
50
- quality?: number;
51
- fullPage?: boolean;
52
- width?: number;
53
- height?: number;
54
- text?: string;
55
- pattern?: string;
56
- timeoutMs?: number;
57
- cdpMethod?: string;
58
- cdpParams?: Record<string, unknown>;
59
- /** Engine and Main World calls use the same frame path as actions. */
60
- frame?: FrameStep | FrameStep[];
61
- deadlineAt?: number;
62
- /** session-name */
63
- name?: string;
64
- /** claim: tabId/active choose a tab; url/title find a unique tab; expectedUrl/expectedTitle verify its current identity. */
65
- claim?: {
66
- tabId?: number;
67
- active?: boolean;
68
- title?: string;
69
- url?: string;
70
- expectedUrl?: string;
71
- expectedTitle?: string;
72
- };
73
- /** close-user-tabs: numeric Chrome ids, without adopting the tabs into the session. */
74
- tabIds?: number[];
75
- /** mark / finalize */
76
- mark?: 'deliverable' | 'handoff' | null;
77
- closing?: boolean;
78
- keep?: Array<{
79
- page: string;
80
- status: 'deliverable' | 'handoff';
81
- }>;
82
- /** cursor */
83
- x?: number;
84
- y?: number;
85
- waitForArrival?: boolean;
86
- /** visibility */
87
- visible?: boolean;
88
- /** act */
89
- act?: ActSpec;
90
- }
91
- export type ActionEffect = 'navigated' | 'changed' | 'none' | 'unknown';
92
- export type ActKind = 'click' | 'dblclick' | 'hover' | 'focus' | 'fill' | 'type' | 'press' | 'check' | 'uncheck' | 'select' | 'scroll' | 'upload' | 'drag';
93
- export interface ActTarget {
94
- ref?: number | string; /** raw Playwright selector, e.g. the `selector` returned by find */
95
- selector?: string; /** scope: selector of a container, or an observed ref — the target is resolved inside it (generic labels are ambiguous by default; scope them) */
96
- within?: string;
97
- nth?: number;
98
- role?: string;
99
- name?: string;
100
- label?: string;
101
- text?: string;
102
- testid?: string;
103
- x?: number;
104
- y?: number; /** iframe(s) to enter first, outermost first: css selector of the <iframe> or its 0-based index; a string may chain with ' >> ' (Codex enter-frame); same- and cross-origin frames are handled alike */
105
- frame?: FrameStep | FrameStep[];
106
- }
107
- export type FrameStep = string | number;
108
- export interface ActSpec {
109
- kind: ActKind;
110
- target: ActTarget;
111
- value?: string;
112
- timeoutMs?: number;
113
- /** The caller chose timeoutMs (transports fill in a default): a missing target is then waited for the whole time. */
114
- explicitTimeout?: boolean;
115
- settleMs?: number;
116
- cursor?: boolean;
117
- force?: boolean;
118
- /**
119
- * click only. `cdp` (default) is a real mouse event and fails if the page did not receive it.
120
- * `dom` runs HTMLElement.click() and sends no mouse event — only when the event was not delivered or the element has no box.
121
- */
122
- method?: 'cdp' | 'dom';
123
- /** scroll */
124
- direction?: 'up' | 'down' | 'left' | 'right';
125
- amount?: number;
126
- /** upload */
127
- files?: string[];
128
- /** drag */
129
- to?: ActTarget;
130
- }
131
- /** A native JavaScript dialog currently blocking a tab. */
132
- export interface DialogInfo {
133
- type: 'alert' | 'confirm' | 'prompt' | 'beforeunload';
134
- message: string;
135
- defaultPrompt?: string;
136
- url?: string;
137
- openedAt: number;
138
- }
139
- export interface ConsoleEntry {
140
- seq: number;
141
- level: 'debug' | 'info' | 'log' | 'warn' | 'error';
142
- message: string;
143
- timestamp: string;
144
- url?: string;
145
- line?: number;
146
- }
147
- export interface ActResult {
148
- ok: true;
149
- kind: ActKind;
150
- ref?: string | null;
151
- matches_n: number;
152
- visible_n: number;
153
- match_level: 'exact';
154
- point: {
155
- x: number;
156
- y: number;
157
- };
158
- method: 'cdp' | 'dom';
159
- hit: 'target' | 'ancestor' | 'other';
160
- tag: string;
161
- /** ms spent resolving the target (visible/enabled/stable/hit-test) */
162
- waitedMs: number;
163
- /** end-to-end ms and its breakdown: resolve → dispatch (input events + verification) → settle (DOM quiet wait) */
164
- elapsedMs?: number;
165
- timings?: {
166
- resolveMs: number;
167
- actionMs: number;
168
- settleMs: number;
169
- };
170
- /** Playwright-generated selector for locating the same element again. */
171
- selector?: string;
172
- /** What the page did in response: a new document or URL, a DOM/form/scroll change, no change, or unknown (the page could not be read afterwards). */
173
- effect?: ActionEffect;
174
- /** Present when the page was still changing or loading when the settle wait ended. */
175
- settled?: false;
176
- /** Requests the action started that were still in flight when the settle wait ended. */
177
- pendingRequests?: number;
178
- /** set when the action triggered a navigation that has now finished */
179
- navigated?: boolean;
180
- url?: string;
181
- filled?: boolean;
182
- verified?: boolean;
183
- actual?: string;
184
- checked?: boolean;
185
- changed?: boolean;
186
- key?: string;
187
- /** options actually selected; upload count */
188
- selected?: string[];
189
- files?: number;
190
- /** Child tabs from this source tab while the action ran; each is claimed into the same session. */
191
- openedTabs?: Array<{
192
- page?: string;
193
- tabId: number;
194
- url?: string;
195
- title?: string;
196
- pending?: true;
197
- }>;
198
- /** Page.downloadWillBegin events observed while this action ran; completion is checked separately. */
199
- download?: {
200
- afterSequence: number;
201
- started: Array<{
202
- seq: number;
203
- guid?: string;
204
- url: string;
205
- suggestedFilename: string;
206
- }>;
207
- };
208
- }
209
- export interface DownloadWaitResult {
210
- downloaded: boolean;
211
- started: boolean;
212
- sequence?: number;
213
- suggestedFilename?: string;
214
- /** Chrome has no source-tab field for files; this new download was paired with the tab's Page event by URL. */
215
- association?: 'url+event';
216
- candidates?: number;
217
- id?: number;
218
- filename?: string;
219
- url?: string;
220
- finalUrl?: string;
221
- mime?: string;
222
- totalBytes?: number;
223
- state?: string;
224
- danger?: string;
225
- error?: string;
226
- elapsedMs: number;
227
- }
228
- export interface CloseUserTabsResult {
229
- complete: boolean;
230
- closed: number[];
231
- failed: Array<{
232
- tabId: number;
233
- reason: string;
234
- }>;
235
- }
236
- export interface Result {
237
- id: string;
238
- ok: boolean;
239
- /** result payload on success; structured error details (e.g. candidates) on failure */
240
- data?: unknown;
241
- error?: string;
242
- errorCode?: string;
243
- errorHint?: string;
244
- page?: string;
245
- }
246
- export type BrowserEvent = {
247
- kind: 'tab_created' | 'tab_acquired' | 'tab_closed' | 'tab_released' | 'tab_navigated' | 'tab_detached' | 'tab_attached';
248
- session: string;
249
- page?: string;
250
- tabId: number;
251
- url?: string;
252
- title?: string;
253
- origin?: 'agent' | 'user';
254
- } | {
255
- kind: 'download';
256
- state: string;
257
- filename?: string;
258
- url?: string;
259
- } | {
260
- kind: 'dialog';
261
- page?: string;
262
- dialogType: string;
263
- message?: string;
264
- } | {
265
- kind: 'webmcp_changed';
266
- page?: string;
267
- }
268
- /** A session tab needs the user (waiting:true) or no longer does (waiting:false). Emitted by the host runtime, never by the browser. */
269
- | {
270
- kind: 'attention';
271
- session: string;
272
- page: string;
273
- tabId?: number;
274
- reason: 'auth_required' | 'blocked' | 'rate_limited' | 'http_error' | 'error_page';
275
- waiting: boolean;
276
- url?: string;
277
- note?: string;
278
- } | {
279
- kind: 'session_released';
280
- session: string;
281
- reason: string;
282
- };
283
- export type HostToExt = {
284
- type: 'command';
285
- command: Command;
286
- } | {
287
- type: 'ready';
288
- version: string;
289
- };
290
- /** Advisory contract revision; individual capabilities and command results decide what works. */
291
- export declare const PROTOCOL_REVISION = 5;
292
- export type BrowserFeature = 'chrome-api' | 'streams' | 'extension-logs' | 'page-evaluate' | 'frame-evaluate' | 'cdp' | 'network' | 'frames' | 'dialogs' | 'console' | 'downloads' | 'viewport' | 'visibility' | 'webmcp';
293
- export type ExtToHost = {
294
- type: 'hello';
295
- browserId: string;
296
- extensionVersion: string;
297
- protocolRevision?: number;
298
- features?: BrowserFeature[];
299
- } | {
300
- type: 'result';
301
- result: Result;
302
- } | {
303
- type: 'event';
304
- event: BrowserEvent;
305
- };
306
- export declare const NATIVE_HOST_NAME = "com.browsermcp.host";
307
- /** Chrome caps host → extension frames at 1 MiB. */
308
- export declare const MAX_FRAME_BYTES: number;
309
- /** Opaque cursors identify both a buffer generation and a sequence. */
310
- export interface StreamReadOptions {
311
- cursor?: string;
312
- limit?: number;
313
- levels?: string[];
314
- filter?: string;
315
- }
316
- export interface StreamOptions {
317
- capacity?: number; /** Chrome addListener filter arguments, after the listener. */
318
- args?: unknown[];
319
- }
320
- export interface StreamEntry {
321
- seq: number;
322
- timestamp: string;
323
- event?: string;
324
- args?: unknown[];
325
- params?: unknown;
326
- level?: string;
327
- message?: string;
328
- url?: string;
329
- line?: number;
330
- truncated?: boolean;
331
- }
332
- export interface StreamBatch {
333
- entries: StreamEntry[];
334
- cursor: string;
335
- hasMore: boolean;
336
- dropped: number;
337
- reset: boolean;
338
- closed?: boolean;
339
- reason?: string;
340
- }
@@ -1,43 +0,0 @@
1
- import { type Node } from 'web-tree-sitter';
2
- export declare const EXPR = "EXPR";
3
- export interface UrlMatch {
4
- url: string;
5
- method: string;
6
- type: string;
7
- queryParams: string[];
8
- bodyParams: string[];
9
- headers?: Record<string, string>;
10
- contentType?: string;
11
- kind: 'api' | 'asset' | 'page' | 'unknown';
12
- line: number;
13
- source: string;
14
- filename?: string;
15
- }
16
- export interface AnalyzeResult {
17
- urls: UrlMatch[];
18
- parseErrors: boolean;
19
- }
20
- export declare function maybeUrl(s: string): boolean;
21
- export declare function decodeString(raw: string): string;
22
- export declare class JsAnalyzer {
23
- private readonly parser;
24
- private static langPromise;
25
- private constructor();
26
- static create(): Promise<JsAnalyzer>;
27
- analyze(source: string, opts?: {
28
- filename?: string;
29
- maxBytes?: number;
30
- }): AnalyzeResult;
31
- private walk;
32
- /** Resolve a node to a string, substituting EXPR for anything unknown. */
33
- resolve(n: Node | null): string;
34
- private objectKeys;
35
- private objectPairs;
36
- private bodyParams;
37
- private line;
38
- private src;
39
- private matchString;
40
- private matchCall;
41
- private matchNew;
42
- private matchAssignment;
43
- }
@@ -1,48 +0,0 @@
1
- /**
2
- * recon.discover — the "static candidates" leg of API discovery.
3
- * Collects the scripts a live page has loaded, runs the JsAnalyzer over them, and merges the
4
- * candidates with dynamic network evidence into a ledger: seen-in-network > api-shaped static > other.
5
- * Candidates are evidence, not contracts: `EXPR` marks unknown dynamic parts.
6
- */
7
- import { type UrlMatch } from './analyzer.js';
8
- import type { RuntimePage } from '../backends/page-types.js';
9
- export interface EndpointCandidate {
10
- url: string;
11
- method: string;
12
- type: string;
13
- kind: UrlMatch['kind'];
14
- queryParams: string[];
15
- bodyParams: string[];
16
- evidence: 'network+static' | 'network' | 'static';
17
- network?: {
18
- status?: number;
19
- contentType?: string;
20
- count: number;
21
- requestId?: string;
22
- };
23
- sources: Array<{
24
- script: string;
25
- line: number;
26
- snippet: string;
27
- }>;
28
- score: number;
29
- }
30
- export interface DiscoverResult {
31
- pageUrl: string | null;
32
- scripts: Array<{
33
- url: string;
34
- bytes: number;
35
- analyzed: boolean;
36
- error?: string;
37
- }>;
38
- endpoints: EndpointCandidate[];
39
- networkEntries: number;
40
- }
41
- export declare function discoverEndpoints(page: RuntimePage, opts?: {
42
- maxScripts?: number;
43
- includeStatic?: boolean;
44
- includeAssets?: boolean;
45
- includeInline?: boolean;
46
- fetchTimeoutMs?: number; /** network entries already harvested by the session (Tab.network); when given the page's capture is not drained */
47
- network?: Array<Record<string, unknown>>;
48
- }): Promise<DiscoverResult>;
@@ -1,230 +0,0 @@
1
- import type { BrowserBackend } from '../backends/backend.js';
2
- import type { ManagedRuntimePage } from '../backends/managed-page.js';
3
- /**
4
- * Runtime — the resident kernel: site registry, per-MCP-session state, and page backends.
5
- * Lives inside the Chrome-spawned host. The stdio launcher proxies to this runtime.
6
- */
7
- import type { ObserveResult } from '../api/tab.js';
8
- import { EventEmitter } from 'node:events';
9
- import type { ExtensionBridge } from '../host/bridge.js';
10
- import type { BrowserEvent } from '../protocol.js';
11
- import { type BrowserFeature } from '../protocol.js';
12
- import { SiteRegistry, type Source } from '../sites/loader.js';
13
- import { type CommandRunResult, type CommandRunError, type PageProvider } from '../sites/executor.js';
14
- import { listDefinedTools, type ToolDefinition } from '../sites/define.js';
15
- import { type DraftStore, type DraftExpectation } from '../sites/drafts.js';
16
- import type { RuntimePage } from '../backends/page-types.js';
17
- import { JsSession } from '../mcp/js-session.js';
18
- export type Backend = 'extension' | 'electron' | 'none';
19
- export interface RuntimeOptions {
20
- bridge?: ExtensionBridge | null;
21
- backend?: BrowserBackend;
22
- sources?: Source[];
23
- userAdaptersDir?: string | null;
24
- sites?: string[];
25
- sitesWrite?: string[];
26
- cursor?: boolean;
27
- log?: (msg: string) => void;
28
- }
29
- export interface SessionState {
30
- id: string;
31
- name?: string;
32
- createdAt: number;
33
- browserPage?: RuntimePage;
34
- browserPagePromise?: Promise<RuntimePage>;
35
- /** One page object per tab (same bridge, own identity); the session page above carries no tab and serves session-scope calls. */
36
- pages: Map<string, RuntimePage>;
37
- /** Per-tab serialization of page operations. */
38
- tabLocks: Map<string, Promise<void>>;
39
- enabledSites: Map<string, {
40
- write: boolean;
41
- }>;
42
- capabilities: Set<string>;
43
- js?: JsSession;
44
- observationSeq: number;
45
- /** Most recent immutable observation per tab; replaced on fresh capture, cleared on release. */
46
- observations: Map<string, ObserveResult>;
47
- webmcpCatalogs: Map<string, string>;
48
- /** Document namespace → frame route, shared by handles for the same tab. */
49
- refFrames: Map<string, Map<string, import('../protocol.js').FrameStep[]>>;
50
- lastObserve: Map<string, {
51
- id: string;
52
- text: string;
53
- }>;
54
- /** Network entries seen per tab, with monotonically increasing sequence numbers for cursor-based reads. */
55
- netLog: Map<string, {
56
- seq: number;
57
- entries: Array<Record<string, unknown> & {
58
- seq: number;
59
- }>;
60
- seen: Set<string>;
61
- bodyChars: number;
62
- }>;
63
- /** Side effects seen in this session, in order; each js call reports the ones recorded while it ran. */
64
- changes: {
65
- seq: number;
66
- entries: Array<SessionChange & {
67
- seq: number;
68
- }>;
69
- };
70
- /** Sites whose adapters were already suggested to this session. */
71
- suggestedSites: Set<string>;
72
- /** Tabs this session flagged as needing the user (reportIssue); cleared when the agent next uses the tab. */
73
- attention: Map<string, PageIssue & {
74
- atRun: number;
75
- }>;
76
- finalized: boolean;
77
- }
78
- /** A problem a page shows the agent: detected from the main document's HTTP status, or reported by the agent with tab.reportIssue. */
79
- export type IssueCode = 'auth_required' | 'blocked' | 'rate_limited' | 'http_error' | 'error_page';
80
- export interface PageIssue {
81
- code: IssueCode;
82
- source: 'detected' | 'agent';
83
- url?: string;
84
- status?: number;
85
- retryAfterMs?: number;
86
- note?: string;
87
- }
88
- export type SessionChange = {
89
- kind: 'opened';
90
- tab: string;
91
- tabId: number;
92
- url?: string;
93
- } | {
94
- kind: 'closed';
95
- tab: string;
96
- tabId: number;
97
- } | {
98
- kind: 'navigated';
99
- tab: string;
100
- url?: string;
101
- } | {
102
- kind: 'dialog';
103
- tab: string;
104
- dialogType: string;
105
- message?: string;
106
- } | {
107
- kind: 'issue';
108
- tab: string;
109
- issue: PageIssue;
110
- };
111
- /** Reported with each js call that caused it. Absent fields mean nothing of that kind happened. */
112
- export interface ChangeSummary {
113
- opened?: Array<{
114
- tab: string;
115
- url?: string;
116
- }>;
117
- navigated?: Array<{
118
- tab: string;
119
- url?: string;
120
- }>;
121
- closed?: string[];
122
- dialogs?: Array<{
123
- tab: string;
124
- type: string;
125
- message?: string;
126
- }>;
127
- issues?: Array<PageIssue & {
128
- tab: string;
129
- }>;
130
- /** Ready-made commands for a site this session just reached; suggested once per session. */
131
- sites?: Array<{
132
- site: string;
133
- commands: string[];
134
- more?: number;
135
- }>;
136
- }
137
- export interface DoctorReport {
138
- backend: Backend;
139
- browser: {
140
- connected: boolean;
141
- features: BrowserFeature[];
142
- };
143
- extension: {
144
- connected: boolean;
145
- protocolMatches: boolean | null;
146
- protocolWarning: string | null;
147
- version: string | null;
148
- protocolRevision: number | null;
149
- hostProtocolRevision: number;
150
- features: BrowserFeature[];
151
- };
152
- sites: number;
153
- commands: number;
154
- definedTools: number;
155
- sessions: number;
156
- cursor: boolean;
157
- }
158
- export interface RuntimeEvents {
159
- 'browser-event': [BrowserEvent];
160
- 'features-changed': [BrowserFeature[]];
161
- 'tools-changed': [{
162
- site?: string;
163
- }];
164
- log: [string];
165
- }
166
- export declare class Runtime extends EventEmitter<RuntimeEvents> implements PageProvider {
167
- readonly registry: SiteRegistry;
168
- readonly userAdaptersDir: string | null;
169
- private readonly drafts;
170
- readonly sessions: Map<string, SessionState>;
171
- private readonly adapterRuns;
172
- private readonly adapterCallContext;
173
- private readonly siteApis;
174
- bridge: ExtensionBridge | null;
175
- private readonly browserBackend?;
176
- private readonly unsubscribeBackend?;
177
- readonly cursorEnabled: boolean;
178
- readonly configSites: string[];
179
- readonly configSitesWrite: string[];
180
- readonly startedAt: number;
181
- constructor(opts?: RuntimeOptions);
182
- init(): Promise<void>;
183
- backend(): Backend;
184
- browserCommand(action: import('../protocol.js').Command['action'], params?: Partial<import('../protocol.js').Command>): Promise<{
185
- data: unknown;
186
- }>;
187
- browserAvailable(): boolean;
188
- features(): BrowserFeature[];
189
- hasFeature(feature: BrowserFeature): boolean;
190
- session(id: string): SessionState;
191
- /** One interactive browser page per MCP session (tabs are page identities on it). */
192
- getBrowserPage(sessionId: string): Promise<RuntimePage>;
193
- /** The page object bound to one tab of a session: commands carry the tab's identity, nothing is switched or shared. */
194
- pageFor(sessionId: string, pageId: string): Promise<RuntimePage>;
195
- recordChange(sessionId: string, change: SessionChange): void;
196
- /** The agent says the tab needs the user (login, block, error page). The embedding browser shows it; the next use of the tab clears it. */
197
- flagAttention(sessionId: string, page: {
198
- id: string;
199
- tabId?: number;
200
- }, issue: PageIssue, atRun: number): void;
201
- clearAttention(sessionId: string, pageId: string, tabId?: number): void;
202
- /** What happened in this session since change `from`: tabs opened/closed/navigated, dialogs, issues, and adapters for sites it reached. */
203
- changesSince(sessionId: string, from: number): Promise<ChangeSummary | undefined>;
204
- private suggestSites;
205
- forgetPage(sessionId: string, pageId: string): void;
206
- /** Bind each adapter call to the site's current live tab; the extension owns that selection. */
207
- getAdapterPage(site: string): Promise<RuntimePage>;
208
- private createPage;
209
- /** Adapters run on the browser object model: a Tab bound to the adapter page, plus sites/recon. */
210
- toolContext(page: RuntimePage, site: string): Promise<Record<string, unknown>>;
211
- isManagedPage(page: RuntimePage): page is ManagedRuntimePage;
212
- runSite(site: string, name: string, args: Record<string, unknown>, opts?: {
213
- timeoutMs?: number;
214
- signal?: AbortSignal;
215
- sessionId?: string;
216
- }): Promise<CommandRunResult | CommandRunError>;
217
- private runCommand;
218
- private draftStore;
219
- listTools(): ReturnType<typeof listDefinedTools>;
220
- defineTool(def: ToolDefinition): ReturnType<DraftStore['createDraft']>;
221
- tryToolDraft(id: string, args: Record<string, unknown>, expect: DraftExpectation, sessionId?: string): ReturnType<DraftStore['tryDraft']>;
222
- activateToolDraft(id: string): Promise<ReturnType<DraftStore['activateDraft']>>;
223
- discardToolDraft(id: string): ReturnType<DraftStore['discardDraft']>;
224
- removeTool(site: string, name: string): Promise<boolean>;
225
- closeSession(id: string, opts?: {
226
- finalize?: boolean;
227
- }): Promise<void>;
228
- shutdown(): Promise<void>;
229
- doctor(): DoctorReport;
230
- }