@jackwener/browsermcp 0.0.41 → 0.0.42-embedded.0
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/CHANGELOG.md +68 -0
- package/README.md +91 -0
- package/dist/docs/api-reference.md +1 -1
- package/dist/docs/api-use.md +23 -0
- package/dist/docs/instructions.md +1 -0
- package/dist/src/api/action-input.d.ts +87 -0
- package/dist/src/api/agent.d.ts +10 -0
- package/dist/src/api/api.d.ts +54 -0
- package/dist/src/api/browser.d.ts +93 -0
- package/dist/src/api/browser.js +1 -1
- package/dist/src/api/browser.js.map +1 -1
- package/dist/src/api/commands.d.ts +514 -0
- package/dist/src/api/content-wait.d.ts +18 -0
- package/dist/src/api/context.d.ts +7 -0
- package/dist/src/api/diff.d.ts +8 -0
- package/dist/src/api/errors.d.ts +14 -0
- package/dist/src/api/network.d.ts +10 -0
- package/dist/src/api/observation.d.ts +4 -0
- package/dist/src/api/streams.d.ts +13 -0
- package/dist/src/api/tab.d.ts +352 -0
- package/dist/src/api/tab.js +53 -1
- package/dist/src/api/tab.js.map +1 -1
- package/dist/src/api/webmcp.d.ts +19 -0
- package/dist/src/backends/backend.d.ts +14 -0
- package/dist/src/backends/browser-helpers.d.ts +17 -0
- package/dist/src/backends/extension-page.d.ts +5 -0
- package/dist/src/backends/managed-page.d.ts +50 -0
- package/dist/src/backends/page-transport.d.ts +10 -0
- package/dist/src/backends/page-types.d.ts +82 -0
- package/dist/src/docs/embedded.d.ts +2 -0
- package/dist/src/docs/embedded.js +40 -0
- package/dist/src/docs/embedded.js.map +1 -0
- package/dist/src/docs/manifest.d.ts +23 -0
- package/dist/src/docs/manifest.js +6 -3
- package/dist/src/docs/manifest.js.map +1 -1
- package/dist/src/docs/surface.d.ts +12 -0
- package/dist/src/electron/backend.d.ts +50 -0
- package/dist/src/electron/backend.js +377 -0
- package/dist/src/electron/backend.js.map +1 -0
- package/dist/src/electron/chrome.d.ts +24 -0
- package/dist/src/electron/chrome.js +133 -0
- package/dist/src/electron/chrome.js.map +1 -0
- package/dist/src/electron/driver.d.ts +70 -0
- package/dist/src/electron/driver.js +316 -0
- package/dist/src/electron/driver.js.map +1 -0
- package/dist/src/electron/event-buffer.d.ts +16 -0
- package/dist/src/electron/event-buffer.js +59 -0
- package/dist/src/electron/event-buffer.js.map +1 -0
- package/dist/src/electron/page.js +1030 -0
- package/dist/src/electron/registry.d.ts +104 -0
- package/dist/src/electron/registry.js +316 -0
- package/dist/src/electron/registry.js.map +1 -0
- package/dist/src/electron/streams.d.ts +16 -0
- package/dist/src/electron/streams.js +48 -0
- package/dist/src/electron/streams.js.map +1 -0
- package/dist/src/embedded/index.d.ts +49 -0
- package/dist/src/embedded/index.js +85 -0
- package/dist/src/embedded/index.js.map +1 -0
- package/dist/src/host/bridge.d.ts +50 -0
- package/dist/src/host/doctor.d.ts +34 -0
- package/dist/src/host/extension.d.ts +3 -0
- package/dist/src/host/host.d.ts +3 -0
- package/dist/src/host/ipc.d.ts +14 -0
- package/dist/src/host/jsonc-config.d.ts +1 -0
- package/dist/src/host/launch.d.ts +11 -0
- package/dist/src/host/native-messaging.d.ts +28 -0
- package/dist/src/host/opencode.d.ts +6 -0
- package/dist/src/host/pi.d.ts +6 -0
- package/dist/src/host/registration.d.ts +24 -0
- package/dist/src/host/setup.d.ts +7 -0
- package/dist/src/host/socket.d.ts +25 -0
- package/dist/src/host/state.d.ts +39 -0
- package/dist/src/launcher/stdio.d.ts +3 -0
- package/dist/src/lib/paths.d.ts +1 -0
- package/dist/src/lib/sources.d.ts +5 -0
- package/dist/src/main.d.ts +2 -0
- package/dist/src/mcp/catalog.d.ts +202 -0
- package/dist/src/mcp/js-evaluator.mjs +18 -3
- package/dist/src/mcp/js-session.d.ts +64 -0
- package/dist/src/mcp/server.d.ts +15 -0
- package/dist/src/mcp/server.js +6 -4
- package/dist/src/mcp/server.js.map +1 -1
- package/dist/src/protocol.d.ts +340 -0
- package/dist/src/protocol.js.map +1 -1
- package/dist/src/recon/analyzer.d.ts +43 -0
- package/dist/src/recon/discover.d.ts +48 -0
- package/dist/src/runtime/runtime.d.ts +230 -0
- package/dist/src/runtime/runtime.js +109 -1
- package/dist/src/runtime/runtime.js.map +1 -1
- package/dist/src/shared/api-contract.d.ts +86 -0
- package/dist/src/shared/aria-tree.d.ts +2 -0
- package/dist/src/shared/closed-shadow.d.ts +10 -0
- package/dist/src/shared/element-ref.d.ts +4 -0
- package/dist/src/shared/engine.d.ts +62 -0
- package/dist/src/shared/inflight.d.ts +14 -0
- package/dist/src/shared/injected-source.d.ts +2 -0
- package/dist/src/shared/page-contract.d.ts +278 -0
- package/dist/src/sites/define.d.ts +28 -0
- package/dist/src/sites/drafts.d.ts +39 -0
- package/dist/src/sites/executor.d.ts +34 -0
- package/dist/src/sites/loader.d.ts +101 -0
- package/dist/src/sites/manifest.d.ts +5 -0
- package/dist/src/sites/schema.d.ts +11 -0
- package/dist/src/version.d.ts +2 -0
- package/docs/api-reference.md +1 -1
- package/docs/api-use.md +23 -0
- package/docs/instructions.md +1 -0
- package/extension/dist/background.js +1 -1
- package/extension/dist/manifest.json +1 -1
- package/package.json +11 -2
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import type { FrameStep } from '../protocol.js';
|
|
2
|
+
/**
|
|
3
|
+
* Contract between the host-side engine (src/shared/engine.ts) and the page-side module
|
|
4
|
+
* (extension/src/page/index.ts) that runs inside the extension's isolated world next to Playwright's
|
|
5
|
+
* InjectedScript. Only plain JSON crosses this boundary: the host calls `globalThis.__browsermcpPage.<fn>(args)`.
|
|
6
|
+
*/
|
|
7
|
+
export declare const ENGINE_GLOBAL = "__browsermcpInjected";
|
|
8
|
+
export declare const PAGE_GLOBAL = "__browsermcpPage";
|
|
9
|
+
export interface ResolveArgs {
|
|
10
|
+
selector: string;
|
|
11
|
+
fallback: string | null;
|
|
12
|
+
/** strict: several matches are only accepted when exactly one is visible */
|
|
13
|
+
strict: boolean;
|
|
14
|
+
/** actionability states to require, e.g. ['visible','enabled','editable'] */
|
|
15
|
+
states: string[];
|
|
16
|
+
align: {
|
|
17
|
+
block: string;
|
|
18
|
+
inline: string;
|
|
19
|
+
};
|
|
20
|
+
/** The requested accessible name: of several substring matches, the one whose whole name equals it is the target. */
|
|
21
|
+
name?: string;
|
|
22
|
+
}
|
|
23
|
+
/** One of several matches: ref to act on, accessible role and name, and the region it sits in (named landmark, form, dialog or shadow host). */
|
|
24
|
+
export interface Candidate {
|
|
25
|
+
ref: string | null;
|
|
26
|
+
role: string;
|
|
27
|
+
name: string;
|
|
28
|
+
within: string;
|
|
29
|
+
tag: string;
|
|
30
|
+
text: string;
|
|
31
|
+
visible: boolean;
|
|
32
|
+
box: Box;
|
|
33
|
+
}
|
|
34
|
+
export interface Box {
|
|
35
|
+
x: number;
|
|
36
|
+
y: number;
|
|
37
|
+
w: number;
|
|
38
|
+
h: number;
|
|
39
|
+
}
|
|
40
|
+
export interface Resolved {
|
|
41
|
+
ok: true;
|
|
42
|
+
x: number;
|
|
43
|
+
y: number;
|
|
44
|
+
matches_n: number;
|
|
45
|
+
tag: string;
|
|
46
|
+
hit: 'target' | 'other';
|
|
47
|
+
blocker: string | null;
|
|
48
|
+
editable: boolean;
|
|
49
|
+
checkable: boolean;
|
|
50
|
+
checked: boolean;
|
|
51
|
+
isSelect: boolean;
|
|
52
|
+
/** opaque Element ref shared across observation and action */
|
|
53
|
+
ref: string | null;
|
|
54
|
+
/** Playwright-generated selector for replay */
|
|
55
|
+
selector: string | null;
|
|
56
|
+
usedSelector: string;
|
|
57
|
+
}
|
|
58
|
+
export interface ResolveFail {
|
|
59
|
+
error: {
|
|
60
|
+
code: string;
|
|
61
|
+
message: string;
|
|
62
|
+
hint?: string;
|
|
63
|
+
candidates?: Candidate[];
|
|
64
|
+
};
|
|
65
|
+
retry?: boolean;
|
|
66
|
+
}
|
|
67
|
+
export type ResolveOutcome = Resolved | ResolveFail;
|
|
68
|
+
export interface FindArgs {
|
|
69
|
+
name?: string;
|
|
70
|
+
selector: string;
|
|
71
|
+
fallback: string | null;
|
|
72
|
+
limit: number;
|
|
73
|
+
}
|
|
74
|
+
export interface FindEntry {
|
|
75
|
+
nth: number;
|
|
76
|
+
ref: string | null;
|
|
77
|
+
selector: string | null;
|
|
78
|
+
tag: string;
|
|
79
|
+
role: string;
|
|
80
|
+
name: string;
|
|
81
|
+
text: string;
|
|
82
|
+
attrs: Record<string, string>;
|
|
83
|
+
visible: boolean;
|
|
84
|
+
enabled: boolean | null;
|
|
85
|
+
editable: boolean | null;
|
|
86
|
+
box: Box;
|
|
87
|
+
}
|
|
88
|
+
export interface FindResult {
|
|
89
|
+
matches_n: number;
|
|
90
|
+
visible_n: number;
|
|
91
|
+
selector: string;
|
|
92
|
+
entries: FindEntry[];
|
|
93
|
+
}
|
|
94
|
+
export interface QueryFindResult {
|
|
95
|
+
matches_n: number;
|
|
96
|
+
entries: Array<FindEntry & {
|
|
97
|
+
path: string[];
|
|
98
|
+
interactiveAncestorRef: string | null;
|
|
99
|
+
}>;
|
|
100
|
+
}
|
|
101
|
+
export interface AriaArgs {
|
|
102
|
+
name?: string;
|
|
103
|
+
selector?: string;
|
|
104
|
+
fallback?: string | null;
|
|
105
|
+
/** only the subtree of elements intersecting the viewport */
|
|
106
|
+
viewport?: boolean;
|
|
107
|
+
/** open one branch of a previous snapshot (opaque ref). Ignores viewport so an off-screen branch can be read. */
|
|
108
|
+
ref?: string;
|
|
109
|
+
}
|
|
110
|
+
/** Compact DOM evidence. Truncated fields can be read exactly with tab.read({target:{ref}}). */
|
|
111
|
+
export interface DomEntry {
|
|
112
|
+
ref: string;
|
|
113
|
+
tag: string;
|
|
114
|
+
text: string;
|
|
115
|
+
attrs: Record<string, string>;
|
|
116
|
+
truncated: boolean;
|
|
117
|
+
}
|
|
118
|
+
export interface DomSnapshot {
|
|
119
|
+
entries: DomEntry[];
|
|
120
|
+
total: number;
|
|
121
|
+
start: number;
|
|
122
|
+
nextStart?: number;
|
|
123
|
+
scope: 'viewport' | 'document'; /** Continue the live control list with tab.observe(dom.next). */
|
|
124
|
+
next?: {
|
|
125
|
+
format: 'dom';
|
|
126
|
+
frame?: FrameStep[];
|
|
127
|
+
target?: Target;
|
|
128
|
+
start: number;
|
|
129
|
+
limit?: number;
|
|
130
|
+
viewport: boolean;
|
|
131
|
+
includeFrames: false;
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
export interface ObserveFrameArgs extends AriaArgs {
|
|
135
|
+
format?: 'aria' | 'dom';
|
|
136
|
+
start?: number;
|
|
137
|
+
limit?: number;
|
|
138
|
+
}
|
|
139
|
+
export interface FrameOwner {
|
|
140
|
+
ref: string;
|
|
141
|
+
id: string;
|
|
142
|
+
name: string;
|
|
143
|
+
src: string;
|
|
144
|
+
}
|
|
145
|
+
export interface FrameObservation {
|
|
146
|
+
state?: string;
|
|
147
|
+
dom?: DomSnapshot;
|
|
148
|
+
children: FrameOwner[];
|
|
149
|
+
warnings?: string[];
|
|
150
|
+
}
|
|
151
|
+
/** Full current DOM evidence for one element; no preview clipping. */
|
|
152
|
+
export interface ElementDetails {
|
|
153
|
+
ref: string;
|
|
154
|
+
tag: string;
|
|
155
|
+
name: string;
|
|
156
|
+
text: string;
|
|
157
|
+
attrs: Record<string, string>;
|
|
158
|
+
}
|
|
159
|
+
export interface ReadTextArgs {
|
|
160
|
+
maxChars?: number;
|
|
161
|
+
start?: number;
|
|
162
|
+
readId?: string;
|
|
163
|
+
maxSteps?: number;
|
|
164
|
+
waitMs?: number;
|
|
165
|
+
}
|
|
166
|
+
/** Linear document text from one bounded scan. `readId` and `nextStart` continue that same capture. */
|
|
167
|
+
export interface ReadTextResult {
|
|
168
|
+
readId: string;
|
|
169
|
+
text: string;
|
|
170
|
+
complete: boolean;
|
|
171
|
+
reason?: 'budget' | 'scan_limit' | 'unbounded' | 'stale';
|
|
172
|
+
chars: number;
|
|
173
|
+
start: number;
|
|
174
|
+
nextStart?: number;
|
|
175
|
+
}
|
|
176
|
+
export interface DomClickArgs {
|
|
177
|
+
name?: string;
|
|
178
|
+
selector: string;
|
|
179
|
+
fallback: string | null;
|
|
180
|
+
}
|
|
181
|
+
export interface UploadTarget {
|
|
182
|
+
ok: true;
|
|
183
|
+
ref: string | null;
|
|
184
|
+
selector: string | null;
|
|
185
|
+
matches_n: number;
|
|
186
|
+
}
|
|
187
|
+
export interface DomClickOk {
|
|
188
|
+
ok: true;
|
|
189
|
+
ref: string | null;
|
|
190
|
+
tag: string;
|
|
191
|
+
selector: string | null;
|
|
192
|
+
x: number;
|
|
193
|
+
y: number;
|
|
194
|
+
}
|
|
195
|
+
export type DomClickResult = DomClickOk | ResolveFail;
|
|
196
|
+
export interface PointInfo {
|
|
197
|
+
tag: string;
|
|
198
|
+
editable: boolean;
|
|
199
|
+
isSelect: boolean;
|
|
200
|
+
}
|
|
201
|
+
export interface FrameProbeResult {
|
|
202
|
+
found: boolean;
|
|
203
|
+
sameOrigin?: boolean;
|
|
204
|
+
x?: number;
|
|
205
|
+
y?: number;
|
|
206
|
+
src?: string;
|
|
207
|
+
}
|
|
208
|
+
/** Page activity in the action's document: `n` counts real changes, `idleMs` is the time since the last one. */
|
|
209
|
+
/** Rendered content of a document: its own URL, parse state, visible text length and first 200 characters. */
|
|
210
|
+
export interface ContentProbe {
|
|
211
|
+
href: string;
|
|
212
|
+
ready: DocumentReadyState;
|
|
213
|
+
chars: number;
|
|
214
|
+
head: string;
|
|
215
|
+
}
|
|
216
|
+
export interface ActivityInfo {
|
|
217
|
+
n: number;
|
|
218
|
+
idleMs: number;
|
|
219
|
+
ready: DocumentReadyState;
|
|
220
|
+
url: string;
|
|
221
|
+
doc: string;
|
|
222
|
+
}
|
|
223
|
+
export interface SelectResult {
|
|
224
|
+
selected?: string[];
|
|
225
|
+
error?: string;
|
|
226
|
+
available?: string[];
|
|
227
|
+
}
|
|
228
|
+
export interface ElementAtResult {
|
|
229
|
+
matches_n: number;
|
|
230
|
+
entries: FindEntry[];
|
|
231
|
+
}
|
|
232
|
+
/** What a flow expects of the page at a step; every field given must hold. */
|
|
233
|
+
export type Target = ({
|
|
234
|
+
frame?: FrameStep | FrameStep[]; /** container (css/selector/ref) to resolve inside */
|
|
235
|
+
within?: string;
|
|
236
|
+
}) & ({
|
|
237
|
+
ref: number | string;
|
|
238
|
+
} | {
|
|
239
|
+
selector: string;
|
|
240
|
+
nth?: number;
|
|
241
|
+
} | {
|
|
242
|
+
role?: string;
|
|
243
|
+
name?: string;
|
|
244
|
+
label?: string;
|
|
245
|
+
text?: string;
|
|
246
|
+
testid?: string;
|
|
247
|
+
nth?: number;
|
|
248
|
+
} | {
|
|
249
|
+
x: number;
|
|
250
|
+
y: number;
|
|
251
|
+
});
|
|
252
|
+
export interface Expectation {
|
|
253
|
+
target?: Target;
|
|
254
|
+
text?: string;
|
|
255
|
+
notText?: string;
|
|
256
|
+
url?: string;
|
|
257
|
+
title?: string;
|
|
258
|
+
visible?: boolean;
|
|
259
|
+
value?: string;
|
|
260
|
+
checked?: boolean;
|
|
261
|
+
selected?: string[];
|
|
262
|
+
enabled?: boolean;
|
|
263
|
+
}
|
|
264
|
+
/** Compiled once by the host; evaluated in the target document. */
|
|
265
|
+
/** targetText: the text of a text locator, so `visible` asks whether that text (not its container) is on screen. */
|
|
266
|
+
export interface CheckArgs extends Omit<Expectation, 'target'> {
|
|
267
|
+
selector?: string;
|
|
268
|
+
fallback?: string | null;
|
|
269
|
+
targetText?: string;
|
|
270
|
+
targetName?: string;
|
|
271
|
+
}
|
|
272
|
+
export interface CheckResult {
|
|
273
|
+
ok: boolean;
|
|
274
|
+
failed: string[];
|
|
275
|
+
url: string;
|
|
276
|
+
title: string;
|
|
277
|
+
actual?: Record<string, unknown>;
|
|
278
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Arg } from '@jackwener/browsermcp/adapter-sdk';
|
|
2
|
+
export type { Arg } from '@jackwener/browsermcp/adapter-sdk';
|
|
3
|
+
export interface ToolDefinition {
|
|
4
|
+
site: string;
|
|
5
|
+
name: string;
|
|
6
|
+
description: string;
|
|
7
|
+
access: 'read' | 'write';
|
|
8
|
+
domain?: string;
|
|
9
|
+
result?: {
|
|
10
|
+
kind: 'rows' | 'value';
|
|
11
|
+
description: string;
|
|
12
|
+
fields?: Record<string, string>;
|
|
13
|
+
paginated?: boolean;
|
|
14
|
+
};
|
|
15
|
+
args?: Arg[];
|
|
16
|
+
/** JS source of the adapter body: `async ({ tab, args, sites, recon }) => …` */
|
|
17
|
+
func: string;
|
|
18
|
+
}
|
|
19
|
+
export declare function validateDefinition(def: ToolDefinition): void;
|
|
20
|
+
/** Ensure the user source dir can resolve the SDK subpath of this browsermcp installation. */
|
|
21
|
+
export declare function ensureUserSource(userAdaptersDir: string): string;
|
|
22
|
+
export declare function renderAdapterModule(def: ToolDefinition): string;
|
|
23
|
+
export declare function deleteTool(site: string, name: string, userAdaptersDir: string): boolean;
|
|
24
|
+
export declare function listDefinedTools(userAdaptersDir: string): Array<{
|
|
25
|
+
site: string;
|
|
26
|
+
name: string;
|
|
27
|
+
file: string;
|
|
28
|
+
}>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type ToolDefinition } from './define.js';
|
|
2
|
+
import type { CommandRunResult, CommandRunError } from './executor.js';
|
|
3
|
+
import { type Arg } from './schema.js';
|
|
4
|
+
import { type AdapterCommand } from './loader.js';
|
|
5
|
+
export interface DraftExpectation {
|
|
6
|
+
path?: string;
|
|
7
|
+
equals?: unknown;
|
|
8
|
+
minRows?: number;
|
|
9
|
+
}
|
|
10
|
+
export declare function createDraftStore(userAdaptersDir: string): {
|
|
11
|
+
createDraft: (def: ToolDefinition, activeFile?: string) => Promise<{
|
|
12
|
+
draftId: string;
|
|
13
|
+
site: string;
|
|
14
|
+
name: string;
|
|
15
|
+
args: Arg[];
|
|
16
|
+
}>;
|
|
17
|
+
tryDraft: (run: (cmd: AdapterCommand, args: Record<string, unknown>) => Promise<CommandRunResult | CommandRunError>, id: string, args: Record<string, unknown>, expect: DraftExpectation) => Promise<{
|
|
18
|
+
result: CommandRunResult | CommandRunError;
|
|
19
|
+
verification: ReturnType<(result: CommandRunResult | CommandRunError, expect: DraftExpectation) => {
|
|
20
|
+
passed: boolean;
|
|
21
|
+
checks: Array<{
|
|
22
|
+
check: string;
|
|
23
|
+
passed: boolean;
|
|
24
|
+
actual?: unknown;
|
|
25
|
+
}>;
|
|
26
|
+
}>;
|
|
27
|
+
}>;
|
|
28
|
+
activateDraft: (id: string, sourceFile: (site: string, name: string) => string | undefined) => {
|
|
29
|
+
site: string;
|
|
30
|
+
name: string;
|
|
31
|
+
file: string;
|
|
32
|
+
verifiedAt: string;
|
|
33
|
+
};
|
|
34
|
+
discardDraft: (id: string) => {
|
|
35
|
+
draftId: string;
|
|
36
|
+
discarded: true;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
export type DraftStore = ReturnType<typeof createDraftStore>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { AdapterCommand } from './loader.js';
|
|
2
|
+
import type { RuntimePage } from '../backends/page-types.js';
|
|
3
|
+
export interface PageProvider {
|
|
4
|
+
getAdapterPage(site: string): Promise<RuntimePage>;
|
|
5
|
+
browserAvailable(): boolean;
|
|
6
|
+
/** The object model bound to a page: the same `tab`/`sites`/`recon` an agent uses in `js`. */
|
|
7
|
+
toolContext(page: RuntimePage, site: string): Promise<Record<string, unknown>>;
|
|
8
|
+
}
|
|
9
|
+
export interface CommandRunResult {
|
|
10
|
+
ok: true;
|
|
11
|
+
site: string;
|
|
12
|
+
name: string;
|
|
13
|
+
rows?: unknown[];
|
|
14
|
+
value?: unknown;
|
|
15
|
+
nextCursor?: string;
|
|
16
|
+
elapsedMs: number;
|
|
17
|
+
}
|
|
18
|
+
export interface CommandRunError {
|
|
19
|
+
ok: false;
|
|
20
|
+
site: string;
|
|
21
|
+
name: string;
|
|
22
|
+
error: {
|
|
23
|
+
code: string;
|
|
24
|
+
message: string;
|
|
25
|
+
hint?: string;
|
|
26
|
+
details?: Record<string, unknown>;
|
|
27
|
+
};
|
|
28
|
+
elapsedMs: number;
|
|
29
|
+
}
|
|
30
|
+
export declare const DEFAULT_TIMEOUT_MS = 120000;
|
|
31
|
+
export declare function runAdapter(provider: PageProvider, cmd: AdapterCommand, rawArgs: Record<string, unknown>, opts?: {
|
|
32
|
+
timeoutMs?: number;
|
|
33
|
+
signal?: AbortSignal;
|
|
34
|
+
}): Promise<CommandRunResult | CommandRunError>;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { type Arg, type ArgView } from './schema.js';
|
|
2
|
+
export type SourceKind = 'builtin' | 'user';
|
|
3
|
+
export interface Source {
|
|
4
|
+
dir: string;
|
|
5
|
+
kind: SourceKind;
|
|
6
|
+
}
|
|
7
|
+
export interface AdapterContext {
|
|
8
|
+
args: Record<string, unknown>;
|
|
9
|
+
tab: unknown;
|
|
10
|
+
sites: unknown;
|
|
11
|
+
recon: unknown;
|
|
12
|
+
signal?: AbortSignal;
|
|
13
|
+
}
|
|
14
|
+
/** A loaded adapter: the descriptor from the module plus its path-derived identity. */
|
|
15
|
+
export interface AdapterCommand {
|
|
16
|
+
site: string;
|
|
17
|
+
name: string;
|
|
18
|
+
description: string;
|
|
19
|
+
access: 'read' | 'write';
|
|
20
|
+
domain?: string;
|
|
21
|
+
result?: {
|
|
22
|
+
kind: 'rows' | 'value';
|
|
23
|
+
description: string;
|
|
24
|
+
fields?: Record<string, string>;
|
|
25
|
+
paginated?: boolean;
|
|
26
|
+
};
|
|
27
|
+
args: Arg[];
|
|
28
|
+
aliases?: string[];
|
|
29
|
+
source: SourceKind;
|
|
30
|
+
run: (ctx: AdapterContext) => Promise<unknown>;
|
|
31
|
+
}
|
|
32
|
+
/** One descriptor validation path for built-in, user, and draft adapters. */
|
|
33
|
+
export declare function adapterCommandFromDescriptor(site: string, name: string, source: SourceKind, descriptor: Record<string, unknown>): AdapterCommand;
|
|
34
|
+
/** A command's metadata as the index and a source manifest hold it: the descriptor minus `run` and identity. */
|
|
35
|
+
export type AdapterMetadata = Omit<AdapterCommand, 'site' | 'name' | 'source' | 'run'>;
|
|
36
|
+
/** `<source>/manifest.json`: the generated, static description of a read-only source's commands. */
|
|
37
|
+
export declare const ADAPTER_MANIFEST_FILE = "manifest.json";
|
|
38
|
+
export declare const ADAPTER_MANIFEST_FORMAT = 1;
|
|
39
|
+
export interface AdapterManifest {
|
|
40
|
+
format: number;
|
|
41
|
+
sites: Record<string, Record<string, AdapterMetadata>>;
|
|
42
|
+
}
|
|
43
|
+
/** The metadata of a validated command, in index field order (also what a manifest stores). */
|
|
44
|
+
export declare function adapterMetadata(cmd: AdapterCommand): AdapterMetadata;
|
|
45
|
+
export declare class SiteRegistry {
|
|
46
|
+
private sources;
|
|
47
|
+
loadedAt: number | null;
|
|
48
|
+
private index;
|
|
49
|
+
private indexStamp;
|
|
50
|
+
private manifests;
|
|
51
|
+
constructor(sources?: Source[]);
|
|
52
|
+
/** Replace the source list (later overrides earlier). */
|
|
53
|
+
setSources(sources: Source[]): void;
|
|
54
|
+
addSource(source: Source): void;
|
|
55
|
+
load(): Promise<void>;
|
|
56
|
+
private existingDirs;
|
|
57
|
+
/** Include file identity: replacing an adapter does not update its parent directory mtime. A source with a
|
|
58
|
+
* manifest is described by the manifest, so its identity is the manifest's plus its file names. */
|
|
59
|
+
private stamp;
|
|
60
|
+
private manifestKey;
|
|
61
|
+
/** A source's manifest, re-read only when the file changes; null when it has none or it cannot be used. */
|
|
62
|
+
private manifest;
|
|
63
|
+
private siteDirs;
|
|
64
|
+
private siteAliases;
|
|
65
|
+
/** site -> command-name -> absolute file path (later source wins). */
|
|
66
|
+
private map;
|
|
67
|
+
private sourceOf;
|
|
68
|
+
private kindOf;
|
|
69
|
+
private importDescriptor;
|
|
70
|
+
private toCommand;
|
|
71
|
+
private buildIndex;
|
|
72
|
+
private all;
|
|
73
|
+
has(site: string): boolean;
|
|
74
|
+
sites(): Array<{
|
|
75
|
+
site: string;
|
|
76
|
+
aliases: string[];
|
|
77
|
+
commands: number;
|
|
78
|
+
read: number;
|
|
79
|
+
write: number;
|
|
80
|
+
domains: string[];
|
|
81
|
+
source: SourceKind;
|
|
82
|
+
sample: string[];
|
|
83
|
+
}>;
|
|
84
|
+
commandNames(site: string): string[];
|
|
85
|
+
sourceFile(site: string, name: string): string | undefined;
|
|
86
|
+
/** Command metadata for a site (from the index; loads it if cold). */
|
|
87
|
+
commands(site: string): Promise<Array<Omit<AdapterCommand, 'run'>>>;
|
|
88
|
+
/** Rank commands for a free-text query, using the in-memory index. */
|
|
89
|
+
search(query: string, limit?: number): Promise<Array<{
|
|
90
|
+
site: string;
|
|
91
|
+
name: string;
|
|
92
|
+
description: string;
|
|
93
|
+
score: number;
|
|
94
|
+
access: string;
|
|
95
|
+
domain?: string;
|
|
96
|
+
args: ArgView[];
|
|
97
|
+
result?: AdapterCommand['result'];
|
|
98
|
+
}>>;
|
|
99
|
+
/** Load a command with its `run` implementation. Resolves aliases via the index. */
|
|
100
|
+
resolve(site: string, name: string): Promise<AdapterCommand>;
|
|
101
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type AdapterManifest } from './loader.js';
|
|
2
|
+
/** Import and validate every command in `dir`; throws on any adapter that would fail to load at runtime. */
|
|
3
|
+
export declare function generateAdapterManifest(dir: string): Promise<AdapterManifest>;
|
|
4
|
+
export declare function renderAdapterManifest(manifest: AdapterManifest): string;
|
|
5
|
+
export declare function manifestPath(dir: string): string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** One adapter argument contract drives discovery, MCP schemas, and runtime validation. */
|
|
2
|
+
import { type ZodTypeAny } from 'zod';
|
|
3
|
+
import type { Arg } from '@jackwener/browsermcp/adapter-sdk';
|
|
4
|
+
export type { Arg } from '@jackwener/browsermcp/adapter-sdk';
|
|
5
|
+
export type ArgView = Arg;
|
|
6
|
+
export declare function argSpec(args?: Arg[]): ArgView[];
|
|
7
|
+
export declare function argToZod(arg: Arg): ZodTypeAny;
|
|
8
|
+
export declare function argsToShape(args?: Arg[], extra?: Record<string, ZodTypeAny>): Record<string, ZodTypeAny>;
|
|
9
|
+
export declare function validateArgDefinitions(args?: Arg[]): void;
|
|
10
|
+
/** Coerce CLI-like scalar input once, then validate the same schema exposed to MCP. */
|
|
11
|
+
export declare function coerceArgs(cmdArgs: Arg[] | undefined, kwargs: Record<string, unknown>): Record<string, unknown>;
|
package/docs/api-reference.md
CHANGED
|
@@ -67,8 +67,8 @@ class Browser {
|
|
|
67
67
|
class Tab {
|
|
68
68
|
tabId?: number; // `id` is the stable backend page handle; `tabId` is the numeric backend id when claimed from a user tab.
|
|
69
69
|
id: string;
|
|
70
|
-
waitForContentOn(page: RuntimePage): Promise<ContentState>;
|
|
71
70
|
goto(url: string, opts?: { waitUntil?: "load" | "none"; settleMs?: number; ready?: Expectation; timeoutMs?: number; }): Promise<{ url: string | null; title: string | null; content?: "empty" | "placeholder"; }>; // Navigate and wait for the page's content, not only its load event. `content` is present when the page still had no text (`empty`) or only a loading placeholder (`placeholder`) after the bounded wait.
|
|
71
|
+
reportIssue(code: "auth_required" | "blocked" | "error_page", opts?: { note?: string; }): Promise<{ reported: "auth_required" | "blocked" | "error_page"; tab: string; }>; // Say this tab needs the user: a login wall, a block or an error page the HTTP status did not reveal. It is reported with this js call, and the embedding browser can show the user which tab to handle. The flag clears the next time a later js call uses this tab.
|
|
72
72
|
markDeliverable(): Promise<void>; // Preserve this tab for the user when the session is finalized.
|
|
73
73
|
markHandoff(): Promise<void>; // Preserve this tab for a subsequent turn; the same session handle remains usable after finalization.
|
|
74
74
|
clearRetention(): Promise<void>; // Restore default cleanup: close agent tabs, release borrowed user tabs.
|
package/docs/api-use.md
CHANGED
|
@@ -34,6 +34,29 @@ Semantic targets (`role/name`, `label`, `text`, `testid`, `selector`) resolve th
|
|
|
34
34
|
|
|
35
35
|
`fill` replaces; `type` inserts text without individual key presses; `press` sends a specified key or shortcut. A formatted/rejected input reports `controlState:'unverified'` and its actual value rather than overwriting it through a fallback. `method:'dom'` is explicit click activation, suitable only after a real click was not delivered or the element has no box.
|
|
36
36
|
|
|
37
|
+
## Read what the call changed
|
|
38
|
+
|
|
39
|
+
Every `js` result carries `changes` when the call had side effects you did not necessarily ask about. Read it before the value:
|
|
40
|
+
|
|
41
|
+
```js
|
|
42
|
+
// result: {ok:true, changes:{opened:[{tab:'p7', url:'https://example.com/receipt'}],
|
|
43
|
+
// issues:[{tab:'p3', code:'auth_required', source:'detected', status:401, url:'https://example.com/me'}]}, value:...}
|
|
44
|
+
let child = await browser.tabs.get('p7'); // a popup the click opened
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
- `opened` / `closed` / `navigated`: tabs this call opened, closed or moved (final URL).
|
|
48
|
+
- `dialogs`: native dialogs that appeared; answer them with `tab.dialog`.
|
|
49
|
+
- `issues`: the page's own document answered 401 (`auth_required`), 403 (`blocked`), 429 (`rate_limited`, with `retryAfterMs` when the site said) or another 4xx/5xx (`http_error`). A login wall needs the user: do not type credentials you were not given.
|
|
50
|
+
- `sites`: ready-made commands for a site the call just reached, shown once per session. Prefer `site_run` over clicking through the same flow.
|
|
51
|
+
|
|
52
|
+
When the page shows a login form, captcha or error without an HTTP error, say so, then stop and tell the user which tab needs them:
|
|
53
|
+
|
|
54
|
+
```js
|
|
55
|
+
await tab.reportIssue('auth_required', {note: 'Sign-in form shown'}); // or 'blocked', 'error_page'
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
The browser marks that tab for the user; the mark clears the next time a later call uses the tab.
|
|
59
|
+
|
|
37
60
|
## Choose the evidence needed
|
|
38
61
|
|
|
39
62
|
- `observe()` provides a compact viewport ARIA overview and child frames; use `{viewport:false}` for the rendered document. Child-frame content is in `frames[]` (each with its `frame` path and `state`), not in the top-level `state`: read both. Refs from a frame route there automatically; a semantic locator searches only the top document unless you pass `target.frame`. It is not full HTML. Keep headings, messages and surrounding context when choosing an action.
|
package/docs/instructions.md
CHANGED
|
@@ -13,6 +13,7 @@ Start with `docs_get {}` for a short quickstart and available topics. For exact
|
|
|
13
13
|
- If ARIA misses a control, use `tab.observe({format:"dom"})` for visible DOM controls and live values; `tab.read({target:{ref}})` reads exact text/attributes. Refs automatically route to their observed frame. Reuse the same target for read, act and expect. Use a screenshot for visual meaning absent from DOM.
|
|
14
14
|
- Browser management uses `browser.chrome.call(method, argsArray)`; inspect signatures with `browser.chrome.describe(member)`. Page scripts use `tab.evaluate`, and Tab-level protocol calls use `tab.cdp.send`. Discover availability through `browser.capabilities.list()`.
|
|
15
15
|
- Batch already determined steps and data processing. Return new evidence when the next step needs model judgment. Await every API operation before returning.
|
|
16
|
+
- Read `changes` on every `js` result: tabs it opened, closed or navigated, dialogs, `issues` (401 login wall, 403 block, 429 rate limit) and `sites` with ready-made commands for the site just reached. For a login wall or captcha, call `tab.reportIssue('auth_required')` and hand the tab to the user.
|
|
16
17
|
- Read `effect` on every action outcome: `none` means the page did not react, so inspect instead of repeating it; `navigated`/`changed` mean it reacted, not that the task succeeded. Verify the cheapest authoritative result; inspect before retrying uncertain actions.
|
|
17
18
|
- Finish with `session_finish`, keeping only deliverable/handoff tabs. `js_reset` clears JavaScript bindings, closes explicit subscriptions and stops its worker; it does not close browser tabs. `doctor` reports connection and JavaScript execution status.
|
|
18
19
|
- To create an adapter, read `define-tools`, explore and verify its workflow, then use `tools.define`, `tools.try`, and `tools.activate` in `js`.
|
|
@@ -21507,7 +21507,7 @@ var SessionManager = class {
|
|
|
21507
21507
|
lease.title = tab.title;
|
|
21508
21508
|
void this.persist();
|
|
21509
21509
|
}
|
|
21510
|
-
if (info.status === "loading" || info.url) this.emit({ kind: "tab_navigated", session: owner?.key ?? "", page: pageId(tabId), tabId });
|
|
21510
|
+
if (info.status === "loading" || info.url) this.emit({ kind: "tab_navigated", session: owner?.key ?? "", page: pageId(tabId), tabId, ...tab.url && { url: tab.url } });
|
|
21511
21511
|
});
|
|
21512
21512
|
chrome.tabs.onActivated.addListener(({ tabId }) => {
|
|
21513
21513
|
void this.unmuteIfOurs(tabId);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"manifest_version": 3,
|
|
3
3
|
"name": "BrowserMCP Connector",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.30",
|
|
5
5
|
"description": "Connect your logged-in Chrome to BrowserMCP agents through a local native host.",
|
|
6
6
|
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1DKzfAqudbl9AylDyPDJtv4/Uf0DsfYtNmkB42Drff0IJVZ0pRGznikRyz3gNpSSairFyg50pWtuh0EKM/QsU1VrTlHycY529ho8+xMLFO64w3OolId18F73YQ4wRFEo3ESTYLLKVPRrK23dewElkVqtl0u3a63tm6YFkxUxzlS3l6xLMFoSId135BNdVLqHUZe9s/SGE0nD44sDMoNmkJk3qw+oUg65LH+69uc80PtSsXz9uiU6Ma77t2UG42Szvm5HfEDlWfX0NMM042emU8gZ3Id77DKe4195LZs/uEolqwyL12WsUkXcXyhCF7iQ09H/Ye8I6D6SqiEklX1S8QIDAQAB",
|
|
7
7
|
"permissions": [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jackwener/browsermcp",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.42-embedded.0",
|
|
4
4
|
"description": "Chrome-backed MCP browser service with optional site adapters.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"browsermcp": "dist/src/main.js"
|
|
20
20
|
},
|
|
21
21
|
"scripts": {
|
|
22
|
-
"build": "node scripts/clean.mjs && node scripts/extract-playwright-injected.mjs && tsc -p tsconfig.json && node scripts/gen-adapter-manifest.mjs && node scripts/gen-api-reference.mjs && node scripts/render-icons.mjs && node scripts/build-extension.mjs && node scripts/copy-assets.mjs",
|
|
22
|
+
"build": "node scripts/clean.mjs && node scripts/extract-playwright-injected.mjs && tsc -p tsconfig.json && node scripts/gen-adapter-manifest.mjs && node scripts/gen-api-reference.mjs && node scripts/render-icons.mjs && node scripts/build-extension.mjs && node scripts/copy-assets.mjs && node scripts/build-embedded.mjs",
|
|
23
23
|
"build:ext": "node scripts/render-icons.mjs && node scripts/build-extension.mjs",
|
|
24
24
|
"dev": "tsx src/main.ts",
|
|
25
25
|
"test": "vitest run",
|
|
@@ -33,6 +33,9 @@
|
|
|
33
33
|
"pack:manual": "npm run build && node scripts/pack-extension.mjs manual",
|
|
34
34
|
"smoke:native": "node scripts/smoke-native-capabilities.mjs",
|
|
35
35
|
"generate:chrome": "node scripts/gen-chrome-reference.mjs",
|
|
36
|
+
"build:embedded": "tsc -p tsconfig.json && node scripts/gen-adapter-manifest.mjs && node scripts/build-embedded.mjs && node scripts/copy-assets.mjs",
|
|
37
|
+
"smoke:embedded": "npm run build:embedded && node scripts/run-embedded-smoke.mjs",
|
|
38
|
+
"smoke:embedded:package": "npm run build:embedded && node scripts/smoke-embedded-package.mjs",
|
|
36
39
|
"gen:adapters": "tsc -p tsconfig.json && node scripts/gen-adapter-manifest.mjs"
|
|
37
40
|
},
|
|
38
41
|
"files": [
|
|
@@ -61,9 +64,11 @@
|
|
|
61
64
|
"zod": "^4.6.5"
|
|
62
65
|
},
|
|
63
66
|
"devDependencies": {
|
|
67
|
+
"@electron/asar": "^4.3.1",
|
|
64
68
|
"@resvg/resvg-js": "^2.6.2",
|
|
65
69
|
"@types/chrome": "^0.3.0",
|
|
66
70
|
"@types/node": "^22.20.3",
|
|
71
|
+
"electron": "^44.9.0",
|
|
67
72
|
"esbuild": "^0.28.2",
|
|
68
73
|
"playwright-core": "^1.63.0",
|
|
69
74
|
"tsx": "^4.23.13",
|
|
@@ -74,6 +79,10 @@
|
|
|
74
79
|
"./adapter-sdk": {
|
|
75
80
|
"types": "./adapter-sdk/index.d.ts",
|
|
76
81
|
"default": "./adapter-sdk/index.js"
|
|
82
|
+
},
|
|
83
|
+
"./embedded": {
|
|
84
|
+
"types": "./dist/src/embedded/index.d.ts",
|
|
85
|
+
"default": "./dist/src/embedded/index.js"
|
|
77
86
|
}
|
|
78
87
|
}
|
|
79
88
|
}
|