@jackwener/browsermcp 0.0.40 → 0.0.41-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 +62 -0
- package/README.md +91 -0
- package/dist/docs/api-use.md +2 -2
- 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/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 +337 -0
- package/dist/src/api/tab.js +2 -2
- 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/extension-page.js +1 -1
- package/dist/src/backends/extension-page.js.map +1 -1
- 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 +39 -0
- package/dist/src/embedded/index.js +72 -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-session.d.ts +64 -0
- package/dist/src/mcp/server.d.ts +15 -0
- package/dist/src/protocol.d.ts +329 -0
- 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 +148 -0
- 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/engine.js +4 -4
- package/dist/src/shared/engine.js.map +1 -1
- 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-use.md +2 -2
- package/extension/dist/background.js +4 -4
- package/extension/dist/manifest.json +1 -1
- package/extension/dist/page.js +45 -45
- package/package.json +11 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.0.41-embedded.0 — 2026-11-12
|
|
4
|
+
|
|
5
|
+
Align with stable 0.0.41. Share single-target name disambiguation across actions, DOM clicks, upload, targeted observe/read and expectations, with child-frame recovery hints.
|
|
6
|
+
|
|
7
|
+
## 0.0.41 — 2026-11-12
|
|
8
|
+
|
|
9
|
+
Unify single-target name disambiguation across actions, DOM clicks, upload, targeted observation, reading, and expectations. Improve child-frame recovery hints, including frames inside shadow roots. Includes Chrome extension 0.0.29.
|
|
10
|
+
|
|
11
|
+
## 0.0.40-embedded.0 — 2026-11-11
|
|
12
|
+
|
|
13
|
+
Align with stable 0.0.40: content readiness, closed Shadow DOM support, improved action feedback and compact observations. Includes host-owned Electron tabs and lazy adapter loading.
|
|
14
|
+
|
|
3
15
|
## 0.0.40 — 2026-11-11
|
|
4
16
|
|
|
5
17
|
Unified stable and embedded 0.0.40 release line. Adds content readiness waiting, closed Shadow DOM support, actionable ambiguity candidates, improved action feedback, compact observations, hidden-content filtering, and Chrome extension 0.0.28.
|
|
@@ -8,26 +20,76 @@ Unified stable and embedded 0.0.40 release line. Adds content readiness waiting,
|
|
|
8
20
|
|
|
9
21
|
Improve browser Agent Experience: wait for page content after navigation, observe and act inside closed shadow roots, report action outcomes, return named ambiguity candidates, keep waiting for late targets, compact layout tables, hide closed details and transparent text, and expose empty fields and selection state. Includes Chrome extension 0.0.28 and updated release-gate coverage.
|
|
10
22
|
|
|
23
|
+
## 0.0.39-embedded.0 — 2026-11-09
|
|
24
|
+
|
|
25
|
+
Includes stable 0.0.38 manifest-based adapter indexing and lazy command loading, with validated metadata and live writable user adapters. Incorporates the Electron driver that avoids enabling the Runtime domain and resolves frame contexts on demand. Real Electron and installed ASAR smoke checks passed before release.
|
|
26
|
+
|
|
11
27
|
## 0.0.38 — 2026-11-09
|
|
12
28
|
|
|
13
29
|
Index built-in adapters from a build-generated manifest without importing command modules at startup or during search. Load a command module on execution. Validate manifest metadata and preserve live indexing for writable user adapters. Build, targeted checks, real Electron and installed ASAR verification completed before release.
|
|
14
30
|
|
|
31
|
+
## 0.0.38-embedded.0 — 2026-10-28
|
|
32
|
+
|
|
33
|
+
Includes stable 0.0.37 Agent Experience improvements: compact viewport observations and semantic pagination, navigation readiness via expect, explicit evaluate timeout outcomes, bounded error details, API signatures for recovery, and close receipts. Retains built-in adapter defaults and application-owned custom adapters.
|
|
34
|
+
|
|
15
35
|
## 0.0.37 — 2026-10-28
|
|
16
36
|
|
|
17
37
|
Improve Agent Experience across browser backends: compact viewport observations with explicit scope and semantic pagination; navigation readiness conditions shared with expect; explicit evaluation timeout outcomes and bounded error details; API signatures in unknown-method recovery; clear reading continuation and close receipts.
|
|
18
38
|
|
|
39
|
+
## 0.0.37-embedded.1 — 2026-10-28
|
|
40
|
+
|
|
41
|
+
Embedded adapters load from the packaged defaults and application-owned dataDir. MCP instructions expose loaded sites and the sites_search to site_run workflow. Activated custom adapters are immediately usable; externally edited adapters refresh on demand during command search. Clarify source overrides and packaging requirements.
|
|
42
|
+
|
|
43
|
+
## 0.0.37-embedded.0 — 2026-10-28
|
|
44
|
+
|
|
45
|
+
Load packaged site adapters by default in embedded applications while keeping custom adapters in application-owned dataDir. Surface loaded adapters and direct sites_search to site_run usage at agent initialization. Explicit sources replaces built-ins; sources: [] keeps application adapters only. Activated custom adapters are immediately available to existing sessions.
|
|
46
|
+
|
|
19
47
|
## 0.0.36 — 2026-10-28
|
|
20
48
|
|
|
21
49
|
Make existing site adapters discoverable at agent initialization: show loaded sites and command counts, document direct sites_search to site_run invocation without enabling, and clarify application-owned adapter storage.
|
|
22
50
|
|
|
51
|
+
## 0.0.36-embedded.0 — 2026-10-28
|
|
52
|
+
|
|
53
|
+
Includes stable 0.0.35 shared typed browser commands and helpers. navigate_tab reuses existing pages; close_tab is available through MCP and session.api.helper. Retained page handles stay usable until session closure.
|
|
54
|
+
|
|
23
55
|
## 0.0.35 — 2026-10-28
|
|
24
56
|
|
|
25
57
|
Add shared typed browser commands and session helpers, including navigate_tab and close_tab. Reuse existing tabs and preserve handoff handles. Protocol revision 5 requires extension 0.0.27 and a matching host.
|
|
26
58
|
|
|
59
|
+
## 0.0.35-embedded.0 — 2026-10-22
|
|
60
|
+
|
|
61
|
+
Includes stable 0.0.34 strict evaluation and lossless RPC contracts, shared tab discovery with scope/counts/pagination, and invalid-response detection. Fixes debugger cleanup after WebContents destruction. Verified with 31 tests, real Electron MCP flows and the installed npm package inside app.asar. openTabs now returns an envelope; read items.
|
|
62
|
+
|
|
27
63
|
## 0.0.34 — 2026-10-22
|
|
28
64
|
|
|
29
65
|
Enforce strict evaluate options and lossless REPL call transport. Separate user data from internal RPC references. Return explicit tab discovery scope, counts and pagination using shared backend contracts. Reject malformed backend responses. Protocol revision 4 requires updating host and extension together; read openTabs results from items.
|
|
30
66
|
|
|
67
|
+
## 0.0.34-embedded.3 — 2026-10-22
|
|
68
|
+
|
|
69
|
+
Host-owned logical tabs, lazy page registration, active-tab selection, session lifecycle events, and retention controls. Includes session-bound adapters and automatic npm publishing through GitHub Actions OIDC.
|
|
70
|
+
|
|
71
|
+
## 0.0.34-embedded.2 — 2026-10-22
|
|
72
|
+
|
|
73
|
+
- Preserve logical tab identity, session ownership and retention across WebContents replacement.
|
|
74
|
+
- Define host-owned create/load/close callbacks and explicit attach/detach lifecycle operations.
|
|
75
|
+
- Report structured host failures with recoverable tab state; protect cleanup against invalid keep entries.
|
|
76
|
+
- Add handle-based deliverable/handoff retention and safe local remote-method inspection.
|
|
77
|
+
- Verify background duplicate claims, host failure recovery and installed ASAR execution.
|
|
78
|
+
|
|
79
|
+
## 0.0.34-embedded.1 — 2026-10-21
|
|
80
|
+
|
|
81
|
+
- Model host tabs independently of WebContents, with stable logical IDs, explicit active selection, metadata updates and lazy loading.
|
|
82
|
+
- Expose typed host events and snapshots with public MCP session IDs; reserve ownership during loading and roll back or cancel failed/revoked claims.
|
|
83
|
+
- Unify tab state across MCP and Chrome APIs, and default MCP version to the installed package version.
|
|
84
|
+
- Migration: use registerPage handles and reported tabId values; tabId no longer equals webContents.id. Synchronize host selection with setActivePage(scope, handle).
|
|
85
|
+
- Share runtime isolation, storage injection, package version resolution and release infrastructure with main.
|
|
86
|
+
|
|
87
|
+
## 0.0.34-embedded.0 — 2026-10-21
|
|
88
|
+
|
|
89
|
+
- Add the embedded Electron SDK with host-owned storage, profiles and page lifecycle.
|
|
90
|
+
- Support MCP sessions, adapter creation and updates, Chrome API compatibility and CDP in embedded Chromium.
|
|
91
|
+
- Import @jackwener/browsermcp/embedded without CLI setup or a Chrome extension.
|
|
92
|
+
|
|
31
93
|
## 0.0.33 — 2026-10-20
|
|
32
94
|
|
|
33
95
|
- refactor: standardize BrowserMCP runtime names and simplify configuration
|
package/README.md
CHANGED
|
@@ -143,6 +143,97 @@ Site commands execute directly without additional approval prompts. The read/wri
|
|
|
143
143
|
| [Tab lifecycle](docs/tab-lifecycle.md) | Claiming tabs, grouping, and cleanup |
|
|
144
144
|
| [Errors](docs/errors.md) | Error codes and recovery |
|
|
145
145
|
|
|
146
|
+
## Embedded Electron applications
|
|
147
|
+
|
|
148
|
+
Import `@jackwener/browsermcp/embedded` from Electron's main process. This entry does not run setup, register Native Messaging, discover Chrome, read global CLI configuration, or install an extension. The application supplies its writable directory, profile sessions, and page lifecycle callbacks. Adapters can still be created, verified, activated, updated, and removed through `tools`.
|
|
149
|
+
|
|
150
|
+
```ts
|
|
151
|
+
import { app, BrowserWindow, session } from 'electron';
|
|
152
|
+
import path from 'node:path';
|
|
153
|
+
import { createEmbeddedBrowser } from '@jackwener/browsermcp/embedded';
|
|
154
|
+
|
|
155
|
+
await app.whenReady();
|
|
156
|
+
const windows = new Map<number, BrowserWindow>();
|
|
157
|
+
const profile = ({ profileId }) => session.fromPartition(`persist:${profileId}`);
|
|
158
|
+
const browser = await createEmbeddedBrowser({
|
|
159
|
+
dataDir: path.join(app.getPath('userData'), 'browsermcp'),
|
|
160
|
+
execution: 'trusted-node',
|
|
161
|
+
browser: {
|
|
162
|
+
profile,
|
|
163
|
+
async createPage(scope) {
|
|
164
|
+
const window = new BrowserWindow({
|
|
165
|
+
webPreferences: {
|
|
166
|
+
session: profile(scope), contextIsolation: true,
|
|
167
|
+
sandbox: true, nodeIntegration: false,
|
|
168
|
+
},
|
|
169
|
+
});
|
|
170
|
+
const id = window.webContents.id;
|
|
171
|
+
windows.set(id, window);
|
|
172
|
+
window.once('closed', () => windows.delete(id));
|
|
173
|
+
return { contents: window.webContents, close: async () => { window.destroy(); } };
|
|
174
|
+
},
|
|
175
|
+
async activatePage(contents) { windows.get(contents.id)?.show(); },
|
|
176
|
+
},
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
// Scope comes from the application, not from agent-provided MCP arguments.
|
|
180
|
+
const connection = browser.createSession({ workspaceId: 'project-a', profileId: 'personal' });
|
|
181
|
+
await connection.server.connect(transport); // Any host-provided MCP SDK transport.
|
|
182
|
+
// On disconnect, cleanup is automatic. Explicit close and application shutdown:
|
|
183
|
+
await connection.close();
|
|
184
|
+
await browser.dispose();
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
The host owns logical tabs; a tab does not need a `WebContents` until it is claimed. Register restored tabs immediately, and synchronize selection from the host UI:
|
|
188
|
+
|
|
189
|
+
```ts
|
|
190
|
+
const scope = { workspaceId: 'workspace', profileId: 'personal' };
|
|
191
|
+
const handle = browser.registerPage({
|
|
192
|
+
scope,
|
|
193
|
+
url: restoredTab.url,
|
|
194
|
+
title: restoredTab.title,
|
|
195
|
+
load: async (signal) => {
|
|
196
|
+
// Resolve only once the restored tab has loaded; honor cancellation.
|
|
197
|
+
return hostTabs.ensureLoaded(restoredTab.id, { signal });
|
|
198
|
+
},
|
|
199
|
+
close: async () => { await hostTabs.close(restoredTab.id); },
|
|
200
|
+
});
|
|
201
|
+
browser.setActivePage(scope, handle); // Call on each host selection change.
|
|
202
|
+
browser.updatePage(handle, { url: restoredTab.url, title: restoredTab.title });
|
|
203
|
+
const unsubscribe = browser.subscribe((event) => {
|
|
204
|
+
// event.sessionId matches createSession().id, with no internal prefix.
|
|
205
|
+
// event.page.sessionId is the current owner; undefined after release.
|
|
206
|
+
hostTabs.setAgentOwner(event.page.handle, event.page.sessionId);
|
|
207
|
+
});
|
|
208
|
+
const snapshot = browser.getPages(scope); // Initialize/reconcile host UI.
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
`registerPage` takes a descriptor with `scope`, `url`, optional `title` / `contents` / `load(signal)`, and a required `close()` callback. For restored tabs, pass metadata and `load(signal)`; enumeration and matching do not trigger loading. A claim reserves exclusive ownership before loading, validates the resolved Electron profile, and returns only after loading succeeds. Failed loads return an unowned tab to the pool. Loading is cancelled on release, unregister, or session cleanup, and is bounded to 30 seconds. A host must honor the signal to prevent its own late side effects; BrowserMCP never attaches a result after access is revoked. WebContents destruction detaches the execution resource; the logical tab, ownership and retention remain intact. Use `attachPage(handle, contents)` to attach a replacement, or let `load(signal)` restore it on demand. `detachPage(handle)` explicitly detaches a resource. `close()` must close the logical host tab, including dormant tabs and tabs whose WebContents was replaced; bind it to the host tab identity, not an obsolete WebContents. Call `unregisterPage(handle)` when the logical host tab is removed.
|
|
212
|
+
|
|
213
|
+
**Identity contract:** the returned handle and the numeric `tabId` in `getPages()` / agent tab lists belong to BrowserMCP. `tabId` is not `webContents.id`. Use the handle to map to your host tab and use the reported `tabId` for Chrome-shaped calls. Both stay stable across loading and WebContents replacement. `webContentsId` identifies only the current execution resource. This changes the implicit `webContents.id` behavior in `0.0.34-embedded.0` and the original vendored branch.
|
|
214
|
+
|
|
215
|
+
`setActivePage(scope, handle | null)` is authoritative; keyboard focus is never used to infer the selected tab. Each workspace/profile has at most one active tab. `openTabs`, `claimTab({ active: true })`, owned-tab lists and `chrome.tabs.query` read the same registry state. `activatePage(contents)` implements agent-requested activation, after which the registry selection is updated. A zero-match claim reports `tab_not_found`; multiple matches report `ambiguous_tab`.
|
|
216
|
+
|
|
217
|
+
Host `subscribe()` emits typed snapshots for registration, metadata/lifecycle changes, activation, acquisition, release, navigation, closure and unregister. Acquisition is idempotent for the same session. Listener exceptions cannot break ownership transitions. Subscribe before taking `getPages(scope)` when initializing UI, and unsubscribe when disposing it. MCP version defaults to the installed BrowserMCP package version; explicit `version` remains available for bundled hosts.
|
|
218
|
+
|
|
219
|
+
The callbacks can manage `WebContentsView` instead of `BrowserWindow`; layout is entirely application-owned. Use `browser.registerPage({ scope, url, contents, close })` to make an existing user page available for claiming. Register only intended browser content, not application settings or privileged UI. `unregisterPage(handle)` revokes access without closing the page. User pages are released during cleanup; unkept agent pages are closed. Profile IDs must map to the intended Electron `Session`, and the backend checks this identity when registering/creating pages.
|
|
220
|
+
|
|
221
|
+
The current evaluator explicitly requires **trusted Node execution**. REPL and adapter modules can access Node capabilities; neither `vm`, a Worker, nor page registration is a sandbox against malicious host code. The REPL runs in a Worker; adapter modules execute in the runtime process. This main-process entry is for applications that trust the connected agent and loaded adapter code. Browser pages should retain `sandbox: true`, `contextIsolation: true`, and `nodeIntegration: false`.
|
|
222
|
+
|
|
223
|
+
Storage is confined by configuration: generated adapters are in `<dataDir>/adapters`, inactive candidates in `<dataDir>/drafts`, and a small standalone adapter SDK in `<dataDir>/node_modules`. No implicit `~/.browsermcp` or `~/.opencli-mcp` source is loaded. Built-in adapters load by default. Set `sources` to replace the read-only sources, or `sources: []` to use only application-owned adapters. Activated adapters in `<dataDir>/adapters` override these sources and become available to existing sessions immediately through `sites_search` and `site_run`. For files copied or edited externally, command searches recheck source file metadata and reload changed adapters on demand; no restart is required. Adapter code is shared within the service, while execution uses the caller's authorized profile and pages. No login credentials are copied between profiles.
|
|
224
|
+
|
|
225
|
+
`browser.chrome.call/describe/watch` remain available. Electron implements `tabs.query/get/create/update/remove/reload` and `cookies.getAll/get/set/remove`, plus session-scoped `tabs.onCreated/onUpdated/onRemoved/onActivated` events. Call `describe` for method availability and differences. Only registered, accessible tabs are returned; `windowId` is `-1` because window organization belongs to the host. Unsupported methods/options return `capability_unavailable`. Page-scoped CDP is available through `tab.cdp.send`; browser-wide `Target.*` and `Browser.*` commands are rejected. This is an explicit compatibility surface, not an emulation of every extension API.
|
|
226
|
+
|
|
227
|
+
Package the generated `dist`, `docs`, `adapters`, and `adapter-sdk` resources with the npm package. When using ASAR, unpack `**/js-*.mjs` so the REPL worker and evaluator remain loadable. Keep Electron as an application dependency; it is only a development dependency here. Call `dispose()` before quitting, await it, and handle cleanup failures; it is safe to retry. The SDK does not install process exit handlers or call `process.exit()`.
|
|
228
|
+
|
|
229
|
+
Validation:
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
npm run build:embedded # SDK and page resources; no extension build required
|
|
233
|
+
npm run smoke:embedded # real Electron + MCP, two profiles, adapter editing, cleanup
|
|
234
|
+
npm run smoke:embedded:package # installed npm package inside app.asar
|
|
235
|
+
```
|
|
236
|
+
|
|
146
237
|
## Development
|
|
147
238
|
|
|
148
239
|
```bash
|
package/dist/docs/api-use.md
CHANGED
|
@@ -15,7 +15,7 @@ await tab.expect({target, value:'42'});
|
|
|
15
15
|
|
|
16
16
|
The same target works in `observe({target})`, `find(target)`, `read({target})`, `act({target,...})` and `expect({target,...})`. Refs remember their observed frame automatically within this session and tab. Copy them unchanged. Surviving Elements retain their refs; replacement or navigation makes old refs stale. Never substitute a similarly named element automatically.
|
|
17
17
|
|
|
18
|
-
Semantic targets (`role/name`, `label`, `text`, `testid`, `selector`) resolve the current page. Add `frame` for an explicit iframe route and `within` for a container. Resolution is strict: multiple matches require exactly one visible match, or fail with `selector_ambiguous`. The error lists each candidate's ref, role, name and region (`in form "Support"`, `in shadow root of <x-widget>`): act on one of those refs or scope with `within`. A locator that matches nothing on a page that has not changed for 2 s fails after about 0.5 s instead of the default 3 s; a page that just loaded or reacted keeps the full wait. Pass `timeoutMs` for content that renders later (a timer, a lazy panel): an explicit timeout is always waited out. An explicit `nth` is supported when you have inspected the ordered candidates; the engine never silently chooses the first match.
|
|
18
|
+
Semantic targets (`role/name`, `label`, `text`, `testid`, `selector`) resolve the current page. Add `frame` for an explicit iframe route and `within` for a container. Resolution is strict: multiple matches require exactly one visible match, or fail with `selector_ambiguous`. The error lists each candidate's ref, role, name and region (`in form "Support"`, `in shadow root of <x-widget>`): act on one of those refs or scope with `within`. Names match by case-insensitive substring (`name:'Designer 1'` also matches "Designer 10"); of several matches, the one whose name is exactly the requested name, or contains it as a whole phrase, is chosen. This single-target rule is shared by actions (including DOM click and upload), targeted observe/read, and expect; find still returns all candidates. A locator that matches nothing on a page that has not changed for 2 s fails after about 0.5 s instead of the default 3 s; a page that just loaded or reacted keeps the full wait. Pass `timeoutMs` for content that renders later (a timer, a lazy panel): an explicit timeout is always waited out. An explicit `nth` is supported when you have inspected the ordered candidates; the engine never silently chooses the first match.
|
|
19
19
|
|
|
20
20
|
`act` waits for actionability, scrolls, hit-tests, dispatches input and settles: it returns once the page shows no change and no request the action started is in flight, or after `settleMs` (default 1000). Every outcome carries `effect`:
|
|
21
21
|
|
|
@@ -36,7 +36,7 @@ Semantic targets (`role/name`, `label`, `text`, `testid`, `selector`) resolve th
|
|
|
36
36
|
|
|
37
37
|
## Choose the evidence needed
|
|
38
38
|
|
|
39
|
-
- `observe()` provides a compact viewport ARIA overview and child frames; use `{viewport:false}` for the rendered document. It is not full HTML. Keep headings, messages and surrounding context when choosing an action.
|
|
39
|
+
- `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.
|
|
40
40
|
- `browser.tabs.new(url)` and `tab.goto(url)` return after the page shows content, not only after its load event: script-rendered text and "Loading…" placeholders get a few seconds. `goto` reports `content:'empty'` or `content:'placeholder'` when the page still had nothing to read; wait for the specific content with `expect` before concluding the page is empty.
|
|
41
41
|
- Controls inside closed shadow roots (payment fields, some design-system widgets) are observed and actionable like any other: refs, role/name locators and `expect` reach them. Page scripts still see those roots as closed.
|
|
42
42
|
- Observations and `read()` contain only rendered content: inactive tab panels hidden with `display:none` and transparent content are left out. In your own `tab.evaluate` code, `el.innerText` of a hidden element returns its full `textContent`, so filter with `el.checkVisibility({checkOpacity:true})` before extracting.
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { Expectation } from '../shared/page-contract.js';
|
|
3
|
+
import type { ActAction, Target } from './tab.js';
|
|
4
|
+
export interface RawTarget {
|
|
5
|
+
ref?: string | number;
|
|
6
|
+
selector?: string;
|
|
7
|
+
within?: string;
|
|
8
|
+
nth?: number;
|
|
9
|
+
role?: string;
|
|
10
|
+
name?: string;
|
|
11
|
+
label?: string;
|
|
12
|
+
text?: string;
|
|
13
|
+
testid?: string;
|
|
14
|
+
x?: number;
|
|
15
|
+
y?: number;
|
|
16
|
+
frame?: Target['frame'];
|
|
17
|
+
}
|
|
18
|
+
export interface ActToolInput {
|
|
19
|
+
action: ActAction;
|
|
20
|
+
target?: RawTarget;
|
|
21
|
+
to?: RawTarget;
|
|
22
|
+
value?: string;
|
|
23
|
+
files?: string[];
|
|
24
|
+
direction?: 'up' | 'down' | 'left' | 'right';
|
|
25
|
+
amount?: number;
|
|
26
|
+
method?: 'cdp' | 'dom';
|
|
27
|
+
timeoutMs?: number;
|
|
28
|
+
settleMs?: number;
|
|
29
|
+
}
|
|
30
|
+
export declare const targetShape: z.ZodObject<{
|
|
31
|
+
ref: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
32
|
+
selector: z.ZodOptional<z.ZodString>;
|
|
33
|
+
within: z.ZodOptional<z.ZodString>;
|
|
34
|
+
nth: z.ZodOptional<z.ZodNumber>;
|
|
35
|
+
role: z.ZodOptional<z.ZodString>;
|
|
36
|
+
name: z.ZodOptional<z.ZodString>;
|
|
37
|
+
label: z.ZodOptional<z.ZodString>;
|
|
38
|
+
text: z.ZodOptional<z.ZodString>;
|
|
39
|
+
testid: z.ZodOptional<z.ZodString>;
|
|
40
|
+
x: z.ZodOptional<z.ZodNumber>;
|
|
41
|
+
y: z.ZodOptional<z.ZodNumber>;
|
|
42
|
+
frame: z.ZodOptional<z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>]>>;
|
|
43
|
+
}, z.core.$strict>;
|
|
44
|
+
export declare const expectationShape: z.ZodObject<{
|
|
45
|
+
target: z.ZodOptional<z.ZodObject<{
|
|
46
|
+
ref: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
47
|
+
selector: z.ZodOptional<z.ZodString>;
|
|
48
|
+
within: z.ZodOptional<z.ZodString>;
|
|
49
|
+
nth: z.ZodOptional<z.ZodNumber>;
|
|
50
|
+
role: z.ZodOptional<z.ZodString>;
|
|
51
|
+
name: z.ZodOptional<z.ZodString>;
|
|
52
|
+
label: z.ZodOptional<z.ZodString>;
|
|
53
|
+
text: z.ZodOptional<z.ZodString>;
|
|
54
|
+
testid: z.ZodOptional<z.ZodString>;
|
|
55
|
+
x: z.ZodOptional<z.ZodNumber>;
|
|
56
|
+
y: z.ZodOptional<z.ZodNumber>;
|
|
57
|
+
frame: z.ZodOptional<z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>]>>;
|
|
58
|
+
}, z.core.$strict>>;
|
|
59
|
+
text: z.ZodOptional<z.ZodString>;
|
|
60
|
+
notText: z.ZodOptional<z.ZodString>;
|
|
61
|
+
url: z.ZodOptional<z.ZodString>;
|
|
62
|
+
title: z.ZodOptional<z.ZodString>;
|
|
63
|
+
visible: z.ZodOptional<z.ZodBoolean>;
|
|
64
|
+
value: z.ZodOptional<z.ZodString>;
|
|
65
|
+
checked: z.ZodOptional<z.ZodBoolean>;
|
|
66
|
+
selected: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
67
|
+
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
68
|
+
}, z.core.$strict>;
|
|
69
|
+
type Need = 'required' | 'nonempty' | 'present' | 'optional' | 'forbidden';
|
|
70
|
+
export declare const ACTION_RULES: Record<ActAction, {
|
|
71
|
+
target: Need;
|
|
72
|
+
value: Need;
|
|
73
|
+
files: Need;
|
|
74
|
+
to: Need;
|
|
75
|
+
scroll: boolean;
|
|
76
|
+
}>;
|
|
77
|
+
/** What the model can copy into the next call. Wire shape is error.details.expected. */
|
|
78
|
+
export declare function expectedAct(action: ActAction): Record<string, string>;
|
|
79
|
+
export declare function pickTarget(t: RawTarget | undefined, action: ActAction, slot: 'target' | 'to'): Target | undefined;
|
|
80
|
+
export declare function checkActInput(input: ActToolInput): {
|
|
81
|
+
target?: Target;
|
|
82
|
+
to?: Target;
|
|
83
|
+
method?: 'cdp' | 'dom';
|
|
84
|
+
};
|
|
85
|
+
/** Validate the public contract before sending a compiled expectation to the page. */
|
|
86
|
+
export declare function checkExpect(what: Expectation): void;
|
|
87
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The object model — the single surface behind both the typed MCP tools and the `js` session.
|
|
3
|
+
* agent.browsers → browser.tabs / browser.user / browser.capabilities → tab.observe / tab.act / …
|
|
4
|
+
* sites.<site>.<command>(args) · recon.discover(tab) · tools.define · browser.nameSession / browser.tabs.finalize
|
|
5
|
+
* Split by object: tab.ts, browser.ts, api.ts (context.ts carries what they share). This file re-exports them.
|
|
6
|
+
*/
|
|
7
|
+
export * from './tab.js';
|
|
8
|
+
export * from './browser.js';
|
|
9
|
+
export * from './api.js';
|
|
10
|
+
export * from './context.js';
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { type BrowserHelper, type BrowserCommands } from './commands.js';
|
|
2
|
+
/**
|
|
3
|
+
* The object model's entry: agent.browsers · sites.<site>.<command>() · recon.discover(tab) · tools.define.
|
|
4
|
+
* One surface behind both the typed entry tools and the `js` session.
|
|
5
|
+
*/
|
|
6
|
+
import type { Runtime } from '../runtime/runtime.js';
|
|
7
|
+
import { discoverEndpoints, type DiscoverResult } from '../recon/discover.js';
|
|
8
|
+
import { listDefinedTools, type ToolDefinition } from '../sites/define.js';
|
|
9
|
+
import type { DraftExpectation } from '../sites/drafts.js';
|
|
10
|
+
import { Tab } from './tab.js';
|
|
11
|
+
import { Browser } from './browser.js';
|
|
12
|
+
export interface AgentApi {
|
|
13
|
+
helper: BrowserHelper;
|
|
14
|
+
agent: {
|
|
15
|
+
browsers: {
|
|
16
|
+
getDefault(): Promise<Browser>;
|
|
17
|
+
};
|
|
18
|
+
browser: Browser;
|
|
19
|
+
documentation: {
|
|
20
|
+
get(name: string): Promise<string | null>;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
sites: Record<string, unknown> & {
|
|
24
|
+
search(q: string, limit?: number): Promise<unknown>;
|
|
25
|
+
list(): Promise<unknown>;
|
|
26
|
+
enable(site: string, opts?: {
|
|
27
|
+
write?: boolean;
|
|
28
|
+
}): Promise<{
|
|
29
|
+
site: string;
|
|
30
|
+
tools: string[];
|
|
31
|
+
}>;
|
|
32
|
+
disable(site: string): Promise<boolean>;
|
|
33
|
+
run(site: string, name: string, args?: Record<string, unknown>): Promise<unknown>;
|
|
34
|
+
};
|
|
35
|
+
recon: {
|
|
36
|
+
discover(tab: Tab, opts?: Parameters<typeof discoverEndpoints>[1]): Promise<DiscoverResult>;
|
|
37
|
+
};
|
|
38
|
+
tools: {
|
|
39
|
+
define(def: ToolDefinition | (Omit<ToolDefinition, 'func'> & {
|
|
40
|
+
func?: string | ((ctx: Record<string, unknown>) => unknown);
|
|
41
|
+
})): ReturnType<Runtime['defineTool']>;
|
|
42
|
+
try(draftId: string, args: Record<string, unknown>, expect: DraftExpectation): ReturnType<Runtime['tryToolDraft']>;
|
|
43
|
+
activate(draftId: string): ReturnType<Runtime['activateToolDraft']>;
|
|
44
|
+
discard(draftId: string): Promise<ReturnType<Runtime['discardToolDraft']>>;
|
|
45
|
+
list(): Promise<ReturnType<typeof listDefinedTools>>;
|
|
46
|
+
remove(site: string, name: string): ReturnType<Runtime['removeTool']>;
|
|
47
|
+
};
|
|
48
|
+
session: {
|
|
49
|
+
id: string;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export declare function createAgentApi(rt: Runtime, sessionId: string): AgentApi & {
|
|
53
|
+
commands: BrowserCommands;
|
|
54
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { type TabDiscoveryOptions, type TabDiscoveryResult } from '../shared/api-contract.js';
|
|
2
|
+
import type { StreamOptions, StreamReadOptions, StreamBatch } from '../protocol.js';
|
|
3
|
+
import type { CloseUserTabsResult } from '../protocol.js';
|
|
4
|
+
import { Tab } from './tab.js';
|
|
5
|
+
import type { SessionContext } from './context.js';
|
|
6
|
+
export declare class Browser {
|
|
7
|
+
readonly id: string;
|
|
8
|
+
readonly type: 'extension' | 'electron';
|
|
9
|
+
private readonly ctx;
|
|
10
|
+
constructor(id: string, type: 'extension' | 'electron', ctx: SessionContext);
|
|
11
|
+
toJSON(): {
|
|
12
|
+
type: 'Browser';
|
|
13
|
+
id: string;
|
|
14
|
+
backend: string;
|
|
15
|
+
};
|
|
16
|
+
private page;
|
|
17
|
+
private ext;
|
|
18
|
+
/** Chrome APIs through the connected backend. Electron supports an explicit compatibility subset. */
|
|
19
|
+
readonly chrome: {
|
|
20
|
+
call: (method: string, args?: unknown[]) => Promise<unknown>;
|
|
21
|
+
describe: (member: string) => Promise<unknown>;
|
|
22
|
+
watch: (event: string, options?: StreamOptions) => Promise<import("./streams.js").EventStream>;
|
|
23
|
+
};
|
|
24
|
+
/** This extension's own service-worker logs; not logs of other installed extensions. */
|
|
25
|
+
readonly logs: {
|
|
26
|
+
watch: (options?: StreamOptions) => Promise<import("./streams.js").EventStream>;
|
|
27
|
+
read: (options?: StreamReadOptions) => Promise<StreamBatch>;
|
|
28
|
+
};
|
|
29
|
+
readonly tabs: {
|
|
30
|
+
new: (url?: string) => Promise<Tab>;
|
|
31
|
+
list: () => Promise<Array<{
|
|
32
|
+
id?: string;
|
|
33
|
+
tabId: number;
|
|
34
|
+
pending?: true;
|
|
35
|
+
url?: string;
|
|
36
|
+
title?: string;
|
|
37
|
+
active: boolean;
|
|
38
|
+
selected: boolean;
|
|
39
|
+
lifecycle?: "dormant" | "loading" | "ready";
|
|
40
|
+
origin: "agent" | "user";
|
|
41
|
+
state: "active" | "handoff";
|
|
42
|
+
}>>;
|
|
43
|
+
get: (tab: string | {
|
|
44
|
+
tab?: string;
|
|
45
|
+
tabId: number;
|
|
46
|
+
}, opts?: {
|
|
47
|
+
timeoutMs?: number;
|
|
48
|
+
}) => Promise<Tab>;
|
|
49
|
+
selected: () => Promise<Tab | undefined>;
|
|
50
|
+
finalize: (opts?: {
|
|
51
|
+
keep?: Array<{
|
|
52
|
+
tab: string | Tab;
|
|
53
|
+
status: "deliverable" | "handoff";
|
|
54
|
+
}>;
|
|
55
|
+
}) => Promise<{
|
|
56
|
+
closed: string[];
|
|
57
|
+
released: string[];
|
|
58
|
+
retained: string[];
|
|
59
|
+
failed: Array<{
|
|
60
|
+
page: string;
|
|
61
|
+
reason: string;
|
|
62
|
+
}>;
|
|
63
|
+
}>;
|
|
64
|
+
};
|
|
65
|
+
readonly user: {
|
|
66
|
+
/** Unclaimed supported tabs in the visible scope. Query is trimmed, case-insensitive literal substring of URL OR title (no token splitting). Inspect items, matched, totalInScope, excluded and hasMore; continue with nextOffset. Each call takes a fresh snapshot. */
|
|
67
|
+
openTabs: (options?: {
|
|
68
|
+
query?: string | undefined;
|
|
69
|
+
limit?: number | undefined;
|
|
70
|
+
offset?: number | undefined;
|
|
71
|
+
} | undefined) => Promise<TabDiscoveryResult>;
|
|
72
|
+
/** Claim by foreground, id, or unique url/title lookup; expected fields verify the tab's current identity. */
|
|
73
|
+
claimTab: (tab: {
|
|
74
|
+
tabId?: number;
|
|
75
|
+
active?: boolean;
|
|
76
|
+
title?: string;
|
|
77
|
+
url?: string;
|
|
78
|
+
expectedUrl?: string;
|
|
79
|
+
expectedTitle?: string;
|
|
80
|
+
}) => Promise<Tab>;
|
|
81
|
+
/** Close user tabs by Chrome id without claiming or loading their pages. */
|
|
82
|
+
closeTabs: (tabIds: number[]) => Promise<CloseUserTabsResult>;
|
|
83
|
+
};
|
|
84
|
+
nameSession(name: string): Promise<void>;
|
|
85
|
+
readonly capabilities: {
|
|
86
|
+
list: () => Promise<Array<{
|
|
87
|
+
id: string;
|
|
88
|
+
description: string;
|
|
89
|
+
}>>;
|
|
90
|
+
get: (id: string) => Promise<Record<string, unknown>>;
|
|
91
|
+
};
|
|
92
|
+
documentation(): Promise<string>;
|
|
93
|
+
}
|