@jackwener/browsermcp 0.0.38 → 0.0.39
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 +4 -0
- package/README.md +6 -2
- package/dist/docs/api-reference.md +10 -3
- package/dist/docs/api-use.md +15 -3
- package/dist/docs/instructions.md +1 -1
- package/dist/src/api/browser.js +2 -0
- package/dist/src/api/browser.js.map +1 -1
- package/dist/src/api/content-wait.js +48 -0
- package/dist/src/api/content-wait.js.map +1 -0
- package/dist/src/api/tab.js +14 -2
- package/dist/src/api/tab.js.map +1 -1
- package/dist/src/backends/extension-page.js +2 -2
- package/dist/src/backends/extension-page.js.map +1 -1
- package/dist/src/protocol.js.map +1 -1
- package/dist/src/shared/aria-tree.js +7 -1
- package/dist/src/shared/aria-tree.js.map +1 -1
- package/dist/src/shared/closed-shadow.js +50 -0
- package/dist/src/shared/closed-shadow.js.map +1 -0
- package/dist/src/shared/engine.js +97 -30
- package/dist/src/shared/engine.js.map +1 -1
- package/dist/src/shared/inflight.js +50 -0
- package/dist/src/shared/inflight.js.map +1 -0
- package/dist/src/shared/injected-source.js +2 -2
- package/dist/src/shared/injected-source.js.map +1 -1
- package/docs/api-reference.md +10 -3
- package/docs/api-use.md +15 -3
- package/docs/instructions.md +1 -1
- package/extension/dist/background.js +195 -47
- package/extension/dist/manifest.json +1 -1
- package/extension/dist/page.js +231 -35
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injected-source.js","sourceRoot":"","sources":["../../../src/shared/injected-source.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,
|
|
1
|
+
{"version":3,"file":"injected-source.js","sourceRoot":"","sources":["../../../src/shared/injected-source.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,0MAA0M;AAC1M,MAAM,CAAC,MAAM,eAAe,GAAW,mn0UAAmn0U,CAAC;AAC3p0U,MAAM,CAAC,MAAM,gBAAgB,GAAG,QAAQ,CAAC"}
|
package/docs/api-reference.md
CHANGED
|
@@ -9,12 +9,12 @@ interface AgentApi {
|
|
|
9
9
|
tabs_list(input: { query?: string | undefined; scope?: "unclaimed" | "all" | "session" | undefined; limit?: number | undefined; cursor?: string | undefined; }): Promise<{ snapshot: string; scope: "unclaimed" | "all" | "session"; excluded: string; nextCursor?: string; items: Array<Row>; total: number; complete: boolean; }>;
|
|
10
10
|
claim_tab(input: { backendId?: number | undefined; active?: true | undefined; url?: string | undefined; title?: string | undefined; expectedUrl?: string | undefined; expectedTitle?: string | undefined; }): Promise<{ tabId: string; }>;
|
|
11
11
|
open_tab(input: { url?: string | undefined; }): Promise<{ tabId: string; }>;
|
|
12
|
-
navigate_tab(input: { tabId: string; url: string; ready?: { target?: { ref?: string | number | undefined; selector?: string | undefined; within?: string | undefined; nth?: number | undefined; role?: string | undefined; name?: string | undefined; label?: string | undefined; text?: string | undefined; testid?: string | undefined; x?: number | undefined; y?: number | undefined; frame?: string | number | Array<string | number> | undefined; } | undefined; text?: string | undefined; notText?: string | undefined; url?: string | undefined; title?: string | undefined; visible?: boolean | undefined; value?: string | undefined; checked?: boolean | undefined; selected?: Array<string> | undefined; enabled?: boolean | undefined; } | undefined; timeoutMs?: number | undefined; waitUntil?: "load" | "none" | undefined; settleMs?: number | undefined; }): Promise<{ url: string | null; title: string | null; tabId: string; }>;
|
|
12
|
+
navigate_tab(input: { tabId: string; url: string; ready?: { target?: { ref?: string | number | undefined; selector?: string | undefined; within?: string | undefined; nth?: number | undefined; role?: string | undefined; name?: string | undefined; label?: string | undefined; text?: string | undefined; testid?: string | undefined; x?: number | undefined; y?: number | undefined; frame?: string | number | Array<string | number> | undefined; } | undefined; text?: string | undefined; notText?: string | undefined; url?: string | undefined; title?: string | undefined; visible?: boolean | undefined; value?: string | undefined; checked?: boolean | undefined; selected?: Array<string> | undefined; enabled?: boolean | undefined; } | undefined; timeoutMs?: number | undefined; waitUntil?: "load" | "none" | undefined; settleMs?: number | undefined; }): Promise<{ url: string | null; title: string | null; content?: "empty" | "placeholder"; tabId: string; }>;
|
|
13
13
|
close_tab(input: { tabId: string; }): Promise<{ tabId: string; closed: boolean; }>;
|
|
14
14
|
tabs_close(input: { tabIds: Array<string>; }): Promise<{ complete: boolean; results: Array<{ tabId: string; closed: boolean; } | { ok: false; error: Record<string, unknown>; tabId: string; closed: boolean; }>; }>;
|
|
15
15
|
release_tab(input: { tabId: string; }): Promise<{ tabId: string; released: boolean; }>;
|
|
16
16
|
tab_observe(input: { tabId: string; options?: { cursor?: string | undefined; mode?: "state" | "screenshot" | "both" | undefined; format?: "aria" | "dom" | undefined; target?: { ref?: string | number | undefined; selector?: string | undefined; within?: string | undefined; nth?: number | undefined; role?: string | undefined; name?: string | undefined; label?: string | undefined; text?: string | undefined; testid?: string | undefined; x?: number | undefined; y?: number | undefined; frame?: string | number | Array<string | number> | undefined; } | undefined; viewport?: boolean | undefined; includeFrames?: boolean | undefined; fullPage?: boolean | undefined; limit?: number | undefined; start?: number | undefined; } | undefined; }): Promise<{ scope?: "target" | "viewport" | "document"; complete?: boolean; webmcp?: PageToolsUpdate; nextCursor?: string; next?: { cursor: string; }; url: string | null; title: string | null; snapshotId?: string; image?: ImageValue; frames?: Array<ObservedFrame>; framesComplete?: boolean; metadataTruncated?: boolean; stateContinued?: boolean; stateContinues?: boolean; state?: string; dom?: DomSnapshot; warnings?: Array<string>; diff?: boolean; changed?: { added: number; removed: number; changed?: number; }; tabId: string; }>;
|
|
17
|
-
tab_act(input: { tabId: string; action: { [x: string]: unknown; }; }): Promise<{ action: ActAction; delivery: "applied" | "received" | "dispatched"; controlState: "verified" | "unverified"; network?: { afterSequence: number; cursor: number; }; matches_n?: number; navigated?: boolean; url?: string; title?: string; timedOut?: boolean; ref?: string; filled?: boolean; verified?: boolean; actual?: string; checked?: boolean; changed?: boolean; selected?: Array<string>; files?: number; openedTabs?: Array<{ tab?: string; tabId: number; url?: string; title?: string; pending?: true; }>; download?: { tab: string; afterSequence: number; started: Array<{ seq: number; guid?: string; url: string; suggestedFilename: string; }>; }; method?: "dom"; tabId: string; }>;
|
|
17
|
+
tab_act(input: { tabId: string; action: { [x: string]: unknown; }; }): Promise<{ action: ActAction; delivery: "applied" | "received" | "dispatched"; controlState: "verified" | "unverified"; network?: { afterSequence: number; cursor: number; }; effect?: "unknown" | "none" | "navigated" | "changed"; settled?: false; pendingRequests?: number; matches_n?: number; navigated?: boolean; url?: string; title?: string; timedOut?: boolean; ref?: string; filled?: boolean; verified?: boolean; actual?: string; checked?: boolean; changed?: boolean; selected?: Array<string>; files?: number; openedTabs?: Array<{ tab?: string; tabId: number; url?: string; title?: string; pending?: true; }>; download?: { tab: string; afterSequence: number; started: Array<{ seq: number; guid?: string; url: string; suggestedFilename: string; }>; }; method?: "dom"; tabId: string; }>;
|
|
18
18
|
};
|
|
19
19
|
agent: { browsers: { getDefault(): Promise<Browser>; }; browser: Browser; documentation: { get(name: string): Promise<string | null>; }; };
|
|
20
20
|
sites: Record<string, unknown> & { search(q: string, limit?: number): Promise<unknown>; list(): Promise<unknown>; enable(site: string, opts?: { write?: boolean; }): Promise<{ site: string; tools: Array<string>; }>; disable(site: string): Promise<boolean>; run(site: string, name: string, args?: Record<string, unknown>): Promise<unknown>; };
|
|
@@ -67,7 +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
|
-
|
|
70
|
+
waitForContentOn(page: RuntimePage): Promise<ContentState>;
|
|
71
|
+
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
72
|
markDeliverable(): Promise<void>; // Preserve this tab for the user when the session is finalized.
|
|
72
73
|
markHandoff(): Promise<void>; // Preserve this tab for a subsequent turn; the same session handle remains usable after finalization.
|
|
73
74
|
clearRetention(): Promise<void>; // Restore default cleanup: close agent tabs, release borrowed user tabs.
|
|
@@ -133,6 +134,12 @@ interface ActionOutcome {
|
|
|
133
134
|
delivery: 'applied' | 'received' | 'dispatched';
|
|
134
135
|
controlState: 'verified' | 'unverified';
|
|
135
136
|
network?: { afterSequence: number; cursor: number };
|
|
137
|
+
/**
|
|
138
|
+
* What the page did in response, measured in the action's document (and the top document for a frame target):
|
|
139
|
+
* `navigated` (new document or URL), `changed` (DOM, form value or scroll changed), `none` (nothing changed: the
|
|
140
|
+
* input reached the page but it did not react), `unknown` (the page could not be read afterwards).
|
|
141
|
+
*/
|
|
142
|
+
effect?: 'navigated' | 'changed' | 'none' | 'unknown'; settled?: false; pendingRequests?: number;
|
|
136
143
|
matches_n?: number;
|
|
137
144
|
navigated?: boolean; url?: string; title?: string; timedOut?: boolean;
|
|
138
145
|
ref?: string; filled?: boolean; verified?: boolean; actual?: string;
|
package/docs/api-use.md
CHANGED
|
@@ -15,11 +15,18 @@ 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`. 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`. 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
|
-
`act` waits for actionability, scrolls, hit-tests, dispatches input and settles
|
|
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
|
|
|
22
|
-
- `
|
|
22
|
+
- `navigated`: a new document or URL (`url` says where).
|
|
23
|
+
- `changed`: the DOM, a form value or the scroll position changed.
|
|
24
|
+
- `none`: the input reached the page and nothing changed. The control did not react: inspect it (disabled look, overlay, wrong target) before acting again; do not repeat the same action.
|
|
25
|
+
- `unknown`: the page could not be read afterwards.
|
|
26
|
+
|
|
27
|
+
`settled:false` with `pendingRequests` means the page was still loading when `act` returned; wait with `expect` rather than acting on a half-updated page. `changed` says the page reacted, not that the task succeeded. Verify the cheapest authoritative result:
|
|
28
|
+
|
|
29
|
+
- `expect({target})` waits for visibility. Elements with `opacity:0` are not visible, and their text is not page text: observations leave it out, `expect({text})` does not match it. A transparent native control (a styled checkbox) stays in observations because a click still reaches it.
|
|
23
30
|
- `expect({target, value:'42'})`, `{target, checked:true}`, `{target, selected:['id']}`, or `{target, enabled:true}` check control state. Multiple conditions must all hold.
|
|
24
31
|
- `expect({target, text:'Saved'})` checks text in that element; `{text:'Saved'}` checks the document.
|
|
25
32
|
- `expect({url:'/receipt'})` or `{title:'Receipt'}` checks the page. Keep page and element expectations separate.
|
|
@@ -30,6 +37,11 @@ Semantic targets (`role/name`, `label`, `text`, `testid`, `selector`) resolve th
|
|
|
30
37
|
## Choose the evidence needed
|
|
31
38
|
|
|
32
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.
|
|
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
|
+
- 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
|
+
- 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.
|
|
43
|
+
- Content of a closed `<details>` is not on screen: it is left out of observations and `read()`, and `expect` does not match it. Its `summary` line shows `[collapsed]` or `[expanded]`.
|
|
44
|
+
- Snapshot lines carry state the ARIA tree lacks: `[empty class="salary"]` marks a field that exists but shows no value (often withheld until login: the field is not missing); `[current=page]` comes from `aria-current`; `[selected? class="cur"]` marks the one sibling of a group (tab strip, panel set) that the page styles as selected without ARIA state. The `?` means it is inferred from class names: confirm it before relying on it.
|
|
33
45
|
- `observe({target})` expands a known branch. `observe({format:'dom'})` finds visible DOM controls and live values when ARIA lacks detail.
|
|
34
46
|
- `read({target})` reads exact current element text/attributes without scrolling. `read()` scans document text, including bounded scroll-and-read for lazy content, and restores scrolling.
|
|
35
47
|
- `find({query:'...'})` searches DOM evidence and returns candidate refs. `find({x,y})` connects screenshot coordinates to elements.
|
package/docs/instructions.md
CHANGED
|
@@ -13,6 +13,6 @@ 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
|
-
-
|
|
16
|
+
- 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
17
|
- 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
18
|
- To create an adapter, read `define-tools`, explore and verify its workflow, then use `tools.define`, `tools.try`, and `tools.activate` in `js`.
|