@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.
Files changed (103) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/README.md +91 -0
  3. package/dist/docs/api-use.md +2 -2
  4. package/dist/src/api/action-input.d.ts +87 -0
  5. package/dist/src/api/agent.d.ts +10 -0
  6. package/dist/src/api/api.d.ts +54 -0
  7. package/dist/src/api/browser.d.ts +93 -0
  8. package/dist/src/api/commands.d.ts +514 -0
  9. package/dist/src/api/content-wait.d.ts +18 -0
  10. package/dist/src/api/context.d.ts +7 -0
  11. package/dist/src/api/diff.d.ts +8 -0
  12. package/dist/src/api/errors.d.ts +14 -0
  13. package/dist/src/api/network.d.ts +10 -0
  14. package/dist/src/api/observation.d.ts +4 -0
  15. package/dist/src/api/streams.d.ts +13 -0
  16. package/dist/src/api/tab.d.ts +337 -0
  17. package/dist/src/api/tab.js +2 -2
  18. package/dist/src/api/tab.js.map +1 -1
  19. package/dist/src/api/webmcp.d.ts +19 -0
  20. package/dist/src/backends/backend.d.ts +14 -0
  21. package/dist/src/backends/browser-helpers.d.ts +17 -0
  22. package/dist/src/backends/extension-page.d.ts +5 -0
  23. package/dist/src/backends/extension-page.js +1 -1
  24. package/dist/src/backends/extension-page.js.map +1 -1
  25. package/dist/src/backends/managed-page.d.ts +50 -0
  26. package/dist/src/backends/page-transport.d.ts +10 -0
  27. package/dist/src/backends/page-types.d.ts +82 -0
  28. package/dist/src/docs/embedded.d.ts +2 -0
  29. package/dist/src/docs/embedded.js +40 -0
  30. package/dist/src/docs/embedded.js.map +1 -0
  31. package/dist/src/docs/manifest.d.ts +23 -0
  32. package/dist/src/docs/manifest.js +6 -3
  33. package/dist/src/docs/manifest.js.map +1 -1
  34. package/dist/src/docs/surface.d.ts +12 -0
  35. package/dist/src/electron/backend.d.ts +50 -0
  36. package/dist/src/electron/backend.js +377 -0
  37. package/dist/src/electron/backend.js.map +1 -0
  38. package/dist/src/electron/chrome.d.ts +24 -0
  39. package/dist/src/electron/chrome.js +133 -0
  40. package/dist/src/electron/chrome.js.map +1 -0
  41. package/dist/src/electron/driver.d.ts +70 -0
  42. package/dist/src/electron/driver.js +316 -0
  43. package/dist/src/electron/driver.js.map +1 -0
  44. package/dist/src/electron/event-buffer.d.ts +16 -0
  45. package/dist/src/electron/event-buffer.js +59 -0
  46. package/dist/src/electron/event-buffer.js.map +1 -0
  47. package/dist/src/electron/page.js +1030 -0
  48. package/dist/src/electron/registry.d.ts +104 -0
  49. package/dist/src/electron/registry.js +316 -0
  50. package/dist/src/electron/registry.js.map +1 -0
  51. package/dist/src/electron/streams.d.ts +16 -0
  52. package/dist/src/electron/streams.js +48 -0
  53. package/dist/src/electron/streams.js.map +1 -0
  54. package/dist/src/embedded/index.d.ts +39 -0
  55. package/dist/src/embedded/index.js +72 -0
  56. package/dist/src/embedded/index.js.map +1 -0
  57. package/dist/src/host/bridge.d.ts +50 -0
  58. package/dist/src/host/doctor.d.ts +34 -0
  59. package/dist/src/host/extension.d.ts +3 -0
  60. package/dist/src/host/host.d.ts +3 -0
  61. package/dist/src/host/ipc.d.ts +14 -0
  62. package/dist/src/host/jsonc-config.d.ts +1 -0
  63. package/dist/src/host/launch.d.ts +11 -0
  64. package/dist/src/host/native-messaging.d.ts +28 -0
  65. package/dist/src/host/opencode.d.ts +6 -0
  66. package/dist/src/host/pi.d.ts +6 -0
  67. package/dist/src/host/registration.d.ts +24 -0
  68. package/dist/src/host/setup.d.ts +7 -0
  69. package/dist/src/host/socket.d.ts +25 -0
  70. package/dist/src/host/state.d.ts +39 -0
  71. package/dist/src/launcher/stdio.d.ts +3 -0
  72. package/dist/src/lib/paths.d.ts +1 -0
  73. package/dist/src/lib/sources.d.ts +5 -0
  74. package/dist/src/main.d.ts +2 -0
  75. package/dist/src/mcp/catalog.d.ts +202 -0
  76. package/dist/src/mcp/js-session.d.ts +64 -0
  77. package/dist/src/mcp/server.d.ts +15 -0
  78. package/dist/src/protocol.d.ts +329 -0
  79. package/dist/src/recon/analyzer.d.ts +43 -0
  80. package/dist/src/recon/discover.d.ts +48 -0
  81. package/dist/src/runtime/runtime.d.ts +148 -0
  82. package/dist/src/shared/api-contract.d.ts +86 -0
  83. package/dist/src/shared/aria-tree.d.ts +2 -0
  84. package/dist/src/shared/closed-shadow.d.ts +10 -0
  85. package/dist/src/shared/element-ref.d.ts +4 -0
  86. package/dist/src/shared/engine.d.ts +62 -0
  87. package/dist/src/shared/engine.js +4 -4
  88. package/dist/src/shared/engine.js.map +1 -1
  89. package/dist/src/shared/inflight.d.ts +14 -0
  90. package/dist/src/shared/injected-source.d.ts +2 -0
  91. package/dist/src/shared/page-contract.d.ts +278 -0
  92. package/dist/src/sites/define.d.ts +28 -0
  93. package/dist/src/sites/drafts.d.ts +39 -0
  94. package/dist/src/sites/executor.d.ts +34 -0
  95. package/dist/src/sites/loader.d.ts +101 -0
  96. package/dist/src/sites/manifest.d.ts +5 -0
  97. package/dist/src/sites/schema.d.ts +11 -0
  98. package/dist/src/version.d.ts +2 -0
  99. package/docs/api-use.md +2 -2
  100. package/extension/dist/background.js +4 -4
  101. package/extension/dist/manifest.json +1 -1
  102. package/extension/dist/page.js +45 -45
  103. package/package.json +11 -2
@@ -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>;
@@ -0,0 +1,2 @@
1
+ /** Resolve in source, installed packages and Electron app.asar without using the host's cwd. */
2
+ export declare function getPackageVersion(): string;
package/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.
@@ -198,7 +198,7 @@ async function resolve(io, spec, target, timeoutMs, started) {
198
198
  let quietMiss = false;
199
199
  for (; ; ) {
200
200
  for (const align of spec.force ? [ALIGNMENTS[0]] : ALIGNMENTS) {
201
- const res = await io.call("resolve", { selector, fallback, strict, states, align }, timeoutMs + 2e3);
201
+ const res = await io.call("resolve", { selector, fallback, strict, states, align, ...typeof target.name === "string" && { name: target.name } }, timeoutMs + 2e3);
202
202
  if ("ok" in res && res.ok) {
203
203
  if (res.hit === "other" && !spec.force) {
204
204
  last = { error: { code: "intercepted", message: `${res.blocker ?? "another element"} intercepts the ${spec.kind} point`, hint: "Dismiss the overlay or use a different target from tab_find." }, retry: true };
@@ -223,7 +223,7 @@ async function resolve(io, spec, target, timeoutMs, started) {
223
223
  await new Promise((s) => setTimeout(s, 100));
224
224
  }
225
225
  const e = last?.error ?? { code: "timeout", message: "target did not become actionable" };
226
- const hint = quietMiss ? `Nothing matched and the page had not changed for ${NOT_FOUND_QUIET_MS / 1e3} s, so this did not wait the full timeout. Observe again for the right target; if it renders later (a lazy panel, a timer), pass timeoutMs to wait for it.` : e.hint;
226
+ const hint = quietMiss ? `Nothing matched and the page had not changed for ${NOT_FOUND_QUIET_MS / 1e3} s, so this did not wait the full timeout. Observe again for the right target; if it renders later (a lazy panel, a timer), pass timeoutMs to wait for it.${e.hint ? ` ${e.hint}` : ""}` : e.hint;
227
227
  throw new ActError(e.code, `${e.message} (waited ${Date.now() - started}ms)`, hint, e.candidates ? { candidates: e.candidates } : void 0);
228
228
  }
229
229
  async function performAct(io, spec) {
@@ -384,7 +384,7 @@ async function performUpload(io, spec) {
384
384
  const selector = targetToSelector(spec.target);
385
385
  if (!selector) throw new ActError("invalid_target", "upload needs a file-input ref or a locator associated with one");
386
386
  const started = Date.now();
387
- const resolved = await io.call("resolveUpload", { selector, fallback: fallbackSelector(spec.target), files: files.length });
387
+ const resolved = await io.call("resolveUpload", { selector, fallback: fallbackSelector(spec.target), name: spec.target.name, files: files.length });
388
388
  if (!("ok" in resolved)) throw new ActError(resolved.error.code, resolved.error.message, resolved.error.hint, resolved.error.candidates ? { candidates: resolved.error.candidates } : void 0);
389
389
  if (!io.setFiles) throw new ActError("unsupported", "This runtime cannot upload files");
390
390
  await io.setFiles(files);
@@ -400,7 +400,7 @@ async function performDomClick(io, spec) {
400
400
  const started = Date.now();
401
401
  const before = await readActivity(io, true);
402
402
  const clicked = Date.now();
403
- const res = await io.call("domClick", { selector, fallback: fallbackSelector(spec.target) });
403
+ const res = await io.call("domClick", { selector, fallback: fallbackSelector(spec.target), name: spec.target.name });
404
404
  if (!res || res.ok !== true) {
405
405
  const e = res?.error ?? { code: "action_failed", message: "DOM click failed" };
406
406
  throw new ActError(e.code, e.message, e.hint, e.candidates ? { candidates: e.candidates } : void 0);
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "BrowserMCP Connector",
4
- "version": "0.0.28",
4
+ "version": "0.0.29",
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": [
@@ -139,10 +139,43 @@
139
139
  }
140
140
  }
141
141
  var candidate = (el) => ({ ref: ariaRefOf(el), role: roleOf(el), name: nameOf(el).replace(/\s+/g, " ").trim().slice(0, 80), within: regionOf(el), tag: el.tagName.toLowerCase(), text: text(el).slice(0, 80), visible: is(el, "visible"), box: box(el) });
142
- function ambiguity(n, selector, visibleN, matches) {
142
+ function frameHint() {
143
+ const n = query("css=iframe,frame").length;
144
+ return n ? { hint: `This document contains ${n} frame${n > 1 ? "s" : ""} (more may be nested inside them), and a locator does not search inside frames. For a target in a frame, use its ref from observe (refs route to their frame) or pass target.frame from observe().frames[].frame.` } : {};
145
+ }
146
+ function exactName(matches, name) {
147
+ if (name === void 0) return null;
148
+ const norm = (v) => v.replace(/\s+/g, " ").trim().toLowerCase();
149
+ const want = norm(name);
150
+ if (!want) return null;
151
+ const names = matches.map((m) => norm(nameOf(m)));
152
+ const equal = matches.filter((_, i) => names[i] === want);
153
+ if (equal.length) return equal.length === 1 ? equal[0] : null;
154
+ const phrase = new RegExp(`(?:^|[^\\p{L}\\p{N}])${want.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(?:$|[^\\p{L}\\p{N}])`, "u");
155
+ const whole = matches.filter((_, i) => phrase.test(names[i]));
156
+ return whole.length === 1 ? whole[0] : null;
157
+ }
158
+ function ambiguity(n, selector, visibleN, matches, name) {
143
159
  const candidates = matches.slice(0, 8).map(candidate);
144
160
  const list = candidates.map((c) => `[ref=${c.ref}] ${c.role || c.tag}${c.name ? ` "${c.name}"` : ""} in ${c.within}${c.visible ? "" : " (hidden)"}`).join("; ");
145
- return { code: "selector_ambiguous", message: `${n} elements match ${selector}${visibleN ? ` (${visibleN} visible)` : ""}: ${list}${n > 8 ? `; \u2026${n - 8} more` : ""}`, hint: "Act on one of these refs, or scope the locator with within (a container ref or selector).", candidates };
161
+ const substring = name !== void 0 ? ` A name matches by case-insensitive substring and no single one of these is named "${name}".` : "";
162
+ return { code: "selector_ambiguous", message: `${n} elements match ${selector}${visibleN ? ` (${visibleN} visible)` : ""}: ${list}${n > 8 ? `; \u2026${n - 8} more` : ""}`, hint: `Act on one of these refs, or scope the locator with within (a container ref or selector).${substring}`, candidates };
163
+ }
164
+ function singleTarget(matches, selector, name) {
165
+ if (!matches.length) return { error: { code: "not_found", message: `no element matches ${selector}`, ...frameHint() }, retry: true };
166
+ if (matches.length === 1) return matches[0];
167
+ const visible = matches.filter((el) => is(el, "visible"));
168
+ const pool = visible.length ? visible : matches;
169
+ const selected = pool.length === 1 ? pool[0] : exactName(pool, name);
170
+ return selected ?? { error: ambiguity(matches.length, selector, visible.length, pool, name), retry: false };
171
+ }
172
+ function requireSingleTarget(matches, selector, name) {
173
+ const result = singleTarget(matches, selector, name);
174
+ if ("error" in result) {
175
+ const e = result.error;
176
+ throw pageError(e.code, e.message, e.hint ?? "", e.candidates ? { candidates: e.candidates } : void 0);
177
+ }
178
+ return result;
146
179
  }
147
180
  var actionElement = null;
148
181
  function actionTarget() {
@@ -165,13 +198,8 @@
165
198
  usedSelector = fallback;
166
199
  matches = query(fallback);
167
200
  }
168
- if (!matches.length) return { error: { code: "not_found", message: `no element matches ${selector}` }, retry: true };
169
- let el = matches[0];
170
- if (matches.length > 1 && strict) {
171
- const visible = matches.filter((m) => is(m, "visible"));
172
- if (visible.length === 1) el = visible[0];
173
- else return { error: ambiguity(matches.length, selector, visible.length, visible.length > 1 ? visible : matches), retry: false };
174
- }
201
+ const el = strict ? singleTarget(matches, selector, args.name) : matches[0] ?? singleTarget(matches, selector, args.name);
202
+ if ("error" in el) return el;
175
203
  for (const st of states) {
176
204
  const r = stateOf(el, st);
177
205
  if (r.received === "error:notconnected") return { error: { code: "stale_ref", message: "element detached during resolution" }, retry: true };
@@ -308,9 +336,8 @@
308
336
  function resolveUpload(args) {
309
337
  let matches = query(args.selector);
310
338
  if (!matches.length && args.fallback) matches = query(args.fallback);
311
- if (!matches.length) return { error: { code: "not_found", message: "Upload target was not found. Observe again for a fresh file-input ref." } };
312
- if (matches.length !== 1) return { error: { code: "selector_ambiguous", message: `${matches.length} upload targets match`, candidates: matches.slice(0, 8).map(candidate) } };
313
- const el = matches[0];
339
+ const el = singleTarget(matches, args.selector, args.name);
340
+ if ("error" in el) return el;
314
341
  const direct = el instanceof HTMLInputElement && el.type === "file" ? [el] : [];
315
342
  const controlled = el instanceof HTMLLabelElement && el.control instanceof HTMLInputElement && el.control.type === "file" ? [el.control] : [];
316
343
  const nested = [...el.querySelectorAll("input[type=file]")];
@@ -492,13 +519,8 @@
492
519
  function domClick(args) {
493
520
  let matches = query(args.selector);
494
521
  if (!matches.length && args.fallback) matches = query(args.fallback);
495
- if (!matches.length) return { error: { code: "not_found", message: `no element matches ${args.selector}` }, retry: true };
496
- let el = matches[0];
497
- if (matches.length > 1) {
498
- const visible = matches.filter((m) => is(m, "visible"));
499
- if (visible.length === 1) el = visible[0];
500
- else return { error: ambiguity(matches.length, args.selector, visible.length, visible.length > 1 ? visible : matches), retry: false };
501
- }
522
+ const el = singleTarget(matches, args.selector, args.name);
523
+ if ("error" in el) return el;
502
524
  const enabled = stateOf(el, "enabled");
503
525
  if (!enabled.matches) return { error: { code: "not_enabled", message: `element is not enabled${enabled.received.startsWith("error:") ? ` (${enabled.received.slice(6)})` : ""}`, candidates: [candidate(el)] }, retry: true };
504
526
  rememberActionTarget(el);
@@ -722,16 +744,7 @@
722
744
  if (!args.selector) return document;
723
745
  let matches = query(args.selector);
724
746
  if (!matches.length && args.fallback) matches = query(args.fallback);
725
- if (!matches.length) throw pageError("not_found", `No element matches ${args.selector}`, "Observe the page or find the container again.");
726
- if (matches.length > 1) {
727
- const visible = matches.filter((el) => is(el, "visible"));
728
- if (visible.length !== 1) {
729
- const a = ambiguity(matches.length, args.selector, visible.length, visible.length > 1 ? visible : matches);
730
- throw pageError(a.code, a.message, a.hint, { candidates: a.candidates });
731
- }
732
- matches = visible;
733
- }
734
- return matches[0];
747
+ return requireSingleTarget(matches, args.selector, args.name);
735
748
  }
736
749
  var SLOT_TAGS = /* @__PURE__ */ new Set(["P", "SPAN", "DIV", "DD", "TD", "EM", "STRONG", "B", "SMALL", "LABEL", "TIME", "DATA", "OUTPUT"]);
737
750
  function isEmptySlot(el) {
@@ -887,13 +900,8 @@ Focused: [ref=${focusRef}]` : "");
887
900
  function readElement(args) {
888
901
  let matches = query(args.selector);
889
902
  if (!matches.length && args.fallback) matches = query(args.fallback);
890
- if (!matches.length) return { error: { code: "not_found", message: `no element matches ${args.selector}`, hint: "Observe or find the target again." } };
891
- if (matches.length > 1) {
892
- const visible = matches.filter((el2) => is(el2, "visible"));
893
- if (visible.length !== 1) return { error: ambiguity(matches.length, args.selector, visible.length, visible.length > 1 ? visible : matches) };
894
- matches = visible;
895
- }
896
- const el = matches[0];
903
+ const el = singleTarget(matches, args.selector, args.name);
904
+ if ("error" in el) return el;
897
905
  return { ref: ariaRefOf(el), tag: el.tagName.toLowerCase(), name: nameOf(el), text: isCredentialField(el) ? "<redacted>" : el.innerText ?? el.textContent ?? "", attrs: domAttributes(el) };
898
906
  }
899
907
  var describe = (el, i) => {
@@ -978,15 +986,7 @@ Focused: [ref=${focusRef}]` : "");
978
986
  if (args.selector !== void 0) {
979
987
  let matches = query(args.selector);
980
988
  if (!matches.length && args.fallback) matches = query(args.fallback);
981
- if (matches.length > 1) {
982
- const visible = matches.filter((el) => is(el, "visible"));
983
- if (visible.length !== 1) {
984
- const a = ambiguity(matches.length, args.selector, visible.length, visible.length > 1 ? visible : matches);
985
- throw Object.assign(new Error(a.message), { code: a.code, hint: a.hint, data: { candidates: a.candidates } });
986
- }
987
- matches = visible;
988
- }
989
- element = matches[0];
989
+ element = matches.length ? requireSingleTarget(matches, args.selector, args.targetName) : void 0;
990
990
  actual.visible = !!element && shownElement(element) && (args.targetText === void 0 || fold(shownText(element)).includes(fold(args.targetText)));
991
991
  const visibilityOnly = ["text", "notText", "value", "checked", "selected", "enabled"].every((key) => args[key] === void 0);
992
992
  if (args.visible !== void 0 || visibilityOnly) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jackwener/browsermcp",
3
- "version": "0.0.40",
3
+ "version": "0.0.41-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
  }