@edlsh/browse-core 0.8.0 → 0.8.1

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/dist/config.d.ts CHANGED
@@ -89,6 +89,8 @@ export interface ConfigurationContext {
89
89
  cwd: string;
90
90
  signal: AbortSignal;
91
91
  purpose: "browser" | "ai" | "jev" | "ask";
92
+ /** Read-only capability/readiness check (e.g. turn guidance or /browse status); resolvers should skip launch-time side effects. */
93
+ probe?: true;
92
94
  /** Selected browser backend; local controls do not need Browserbase credentials. */
93
95
  backend?: "browserbase" | "local";
94
96
  /**
package/dist/jev.js CHANGED
@@ -73,7 +73,7 @@ export function outlineCandidates(outline, action) {
73
73
  const depth = indent.length;
74
74
  while (ancestors.length && ancestors.at(-1).depth >= depth)
75
75
  ancestors.pop();
76
- const ref = /(?:^| )ref=(e\d+)/.exec(attributes)?.[1];
76
+ const ref = /(?:^| )ref=(e\d+|(?:f\d+)?a\d+)(?: |$)/.exec(attributes)?.[1];
77
77
  const states = attributes.split(" ").filter(state => state && !state.startsWith("ref="));
78
78
  const text = name ? `${role}: ${name}` : role;
79
79
  // fill needs a text-entry control it may change; select needs a native <select>, which lists its options.
@@ -39,11 +39,12 @@ export async function observePage(generate, page, instruction, single) {
39
39
  ? "Return the one next action that carries out the instruction, or no elements when the page offers none."
40
40
  : "Return every element the instruction is about, each with the action a person would take on it.";
41
41
  const reply = await generateJson(generate, `You choose elements on a web page for a browser agent. ${OUTLINE} ${task} Answer with JSON only.`, `${describe(page, instruction)}\n\nOutline:\n${page.outline}`, ACTIONS_SCHEMA);
42
- const refs = new Set(page.outline.match(/\bref=e\d+/g)?.map(ref => ref.slice(4)));
42
+ const refs = new Set(page.outline.match(/\bref=(?:e\d+|(?:f\d+)?a\d+)\b/g)?.map(ref => ref.slice(4)));
43
43
  return (reply.elements ?? []).flatMap(({ ref, description, method, arguments: args }) => {
44
- if (typeof ref !== "string" || !refs.has(ref) || (method !== "click" && method !== "fill" && method !== "select" && method !== "press"))
44
+ const normalized = typeof ref === "string" ? ref.replace(/^@/, "") : "";
45
+ if (!normalized || !refs.has(normalized) || (method !== "click" && method !== "fill" && method !== "select" && method !== "press"))
45
46
  return [];
46
- return [{ selector: ref, description: String(description ?? ""), method, arguments: Array.isArray(args) ? args.map(String) : [] }];
47
+ return [{ selector: normalized, description: String(description ?? ""), method, arguments: Array.isArray(args) ? args.map(String) : [] }];
47
48
  }).slice(0, single ? 1 : undefined);
48
49
  }
49
50
  /** What the page says in answer to an instruction, as JSON matching `schema`; without one, as `{ extraction }`. */
@@ -19,7 +19,7 @@ export declare class RealBrowserSession {
19
19
  private readonly release;
20
20
  readonly owner: string;
21
21
  private readonly group;
22
- private readonly allowedOrigins?;
22
+ readonly allowedOrigins?: readonly string[] | undefined;
23
23
  /** The tab this conversation's next call acts on. */
24
24
  private tab?;
25
25
  /** Whether this conversation opened a tab, so close has a group to close. */
@@ -33,6 +33,8 @@ export declare class RealBrowserSession {
33
33
  version: string;
34
34
  }, owner: string, group: string, allowedOrigins?: string[]): RealBrowserSession;
35
35
  private constructor();
36
+ /** True once this conversation opened a tab or selected a lent tab; false after a read-only pre-open `tabs` check. */
37
+ get active(): boolean;
36
38
  run(p: BrowserParams, signal: AbortSignal, timeoutMs: number): Promise<BrowserOutput>;
37
39
  /** Reads a tab for ask, JEV, and browse_ai in one script, so the outline, the text, and the viewport are of the same page. */
38
40
  read(tabId: string | undefined, image: boolean, signal: AbortSignal, timeoutMs: number): Promise<RealBrowserPage>;
@@ -7,12 +7,13 @@ function toTab(tabId) {
7
7
  return /^\d+$/.test(tabId) ? Number(tabId) : tabId;
8
8
  }
9
9
  /** The arguments a script reads from `p`. */
10
- const ARGUMENTS = ["url", "selector", "value", "values", "key", "script", "fullPage", "durationMs", "loadState", "state", "deltaX", "deltaY", "x", "y", "message", "interactive", "width", "height", "file"];
10
+ const ARGUMENTS = ["url", "selector", "force", "value", "values", "key", "script", "fullPage", "durationMs", "loadState", "state", "deltaX", "deltaY", "x", "y", "message", "interactive", "width", "height", "file"];
11
11
  /**
12
- * `el` takes a snapshot ref (e12) or a selector; a bare XPath gets the prefix Playwright-style locators need. `timeout`
13
- * ends a wait for an element or a page before the script's own deadline, whose error would not say what was missing.
12
+ * `el` takes a snapshot ref (`e12`, `@e12`, `a5`, `f2a5`, `@f2a5`) or a selector; a bare XPath gets the prefix
13
+ * Playwright-style locators need. `timeout` ends a wait for an element or a page before the script's own deadline,
14
+ * whose error would not say what was missing.
14
15
  */
15
- const PRELUDE = String.raw `const el = selector => /^e\d+$/.test(selector) ? ref(selector) : page.locator(/^\(*\/\//.test(selector) ? "xpath=" + selector : selector);
16
+ const PRELUDE = String.raw `const el = selector => /^@?(?:e\d+|(?:f\d+)?a\d+)$/.test(selector) ? ref(selector.replace(/^@/, "")) : page.locator(/^\(*\/\//.test(selector) ? "xpath=" + selector : selector);
16
17
  let data, shot, extra;`;
17
18
  /**
18
19
  * What a script hands back. OpenCode Browse returns a string as it is and anything else as JSON, and adds lines of its
@@ -27,12 +28,12 @@ const VIEW = /@@browse-core:([^@]*)@@/;
27
28
  const BODIES = {
28
29
  start: "if (p.url) await page.goto(p.url, { timeout });",
29
30
  open: "await page.goto(p.url, { timeout });",
30
- back: "await page.goBack();",
31
- forward: "await page.goForward();",
32
- reload: "await page.reload();",
31
+ back: "await page.goBack({ timeout });",
32
+ forward: "await page.goForward({ timeout });",
33
+ reload: "await page.reload({ timeout });",
33
34
  // The default of 80 lines hides most of a long page.
34
35
  snapshot: "data = String(await snapshot({ maxItems: 200, interactive: p.interactive === true }));",
35
- hover: "await el(p.selector).hover({ timeout });",
36
+ hover: "await el(p.selector).hover(p.force ? { timeout, force: true } : { timeout });",
36
37
  viewport: "await page.setViewportSize({ width: p.width, height: p.height });",
37
38
  // The relay's path-based upload would read files on the relay machine. Transfer only the caller-supplied bytes.
38
39
  upload: `await el(p.selector).evaluate((node, file) => {
@@ -41,16 +42,16 @@ const BODIES = {
41
42
  transfer.items.add(new File([Uint8Array.from(atob(file.base64), ch => ch.charCodeAt(0))], file.name, { type: file.mimeType }));
42
43
  node.files = transfer.files;
43
44
  node.dispatchEvent(new Event("input", { bubbles: true })); node.dispatchEvent(new Event("change", { bubbles: true }));
44
- }, p.file);`,
45
- click: "await el(p.selector).click({ timeout });",
46
- fill: "await el(p.selector).fill(p.value, { timeout });",
45
+ }, p.file, { timeout });`,
46
+ click: "await el(p.selector).click(p.force ? { timeout, force: true } : { timeout });",
47
+ fill: "await el(p.selector).fill(p.value, p.force ? { timeout, force: true } : { timeout });",
47
48
  select: `const select = el(p.selector);
48
49
  const reason = await select.evaluate((node, wanted) => {
49
50
  if (!(node instanceof HTMLSelectElement)) return "Expected a native select";
50
51
  if (!node.multiple && new Set(wanted).size > 1) return "Multiple values need a multi-select";
51
52
  if (node.disabled || Array.from(node.options).some(o => o.matches(":disabled") && wanted.some(v => v === o.value || v === o.label))) return "A requested option is disabled";
52
53
  return null;
53
- }, p.values);
54
+ }, p.values, { timeout });
54
55
  if (reason) throw new Error(reason + ". Nothing was selected.");
55
56
  data = { selected: await select.selectOption(p.values, { timeout }) };`,
56
57
  press: "await page.keyboard.press(p.key);",
@@ -60,7 +61,7 @@ else if (p.selector !== undefined) await el(p.selector).waitFor({ state: p.state
60
61
  else await page.waitForLoadState(p.loadState, { timeout });`,
61
62
  evaluate: "data = (await page.evaluate(p.script)) ?? null;",
62
63
  screenshot: "shot = await page.screenshot({ fullPage: p.fullPage === true });",
63
- handoff: "data = { handoff: (await handoff(p.message)) ?? null };",
64
+ handoff: "data = { handoff: (await handoff(p.message, { timeoutMs: timeout })) ?? null };",
64
65
  har_start: 'await browse.network({ action: "start" });',
65
66
  };
66
67
  /**
@@ -118,6 +119,10 @@ export class RealBrowserSession {
118
119
  this.group = group;
119
120
  this.allowedOrigins = allowedOrigins;
120
121
  }
122
+ /** True once this conversation opened a tab or selected a lent tab; false after a read-only pre-open `tabs` check. */
123
+ get active() {
124
+ return this.opened || this.tab !== undefined;
125
+ }
121
126
  async run(p, signal, timeoutMs) {
122
127
  if (p.action === "status")
123
128
  return this.output(p.action, { data: { state: this.tab === undefined ? "no_tab" : "running", realBrowser: true, group: this.group } });
@@ -127,13 +132,13 @@ export class RealBrowserSession {
127
132
  }
128
133
  if (p.action === "tabs") {
129
134
  const tabs = await this.list(signal);
130
- return this.output(p.action, { data: { tabs: tabs.map(tab => ({ tabId: String(tab.tab), url: tab.url, title: tab.title, selected: tab.tab === this.tab })) } });
135
+ return this.output(p.action, { data: { tabs: tabs.map(tab => ({ tabId: String(tab.tab), url: tab.url, title: tab.title, selected: tab.tab === this.tab, ...(tab.lent ? { lent: true } : {}) })) } });
131
136
  }
132
137
  if (p.action === "tab_select" || p.action === "tab_close") {
133
138
  const tabs = await this.list(signal);
134
139
  const found = tabs.find(tab => String(tab.tab) === p.tabId);
135
140
  if (!found)
136
- throw new BrowseToolError("tab_missing", "This conversation has no such tab in the real browser. Call tabs to list its tabs.");
141
+ throw new BrowseToolError("tab_missing", "This conversation has no such tab in the real browser, and no lent tab has that ID. Call tabs to list available tabs.");
137
142
  if (p.action === "tab_select") {
138
143
  this.tab = found.tab;
139
144
  return this.output(p.action, { url: found.url, title: found.title });
@@ -181,7 +186,7 @@ export class RealBrowserSession {
181
186
  async read(tabId, image, signal, timeoutMs) {
182
187
  const { tab, view, image: shot } = await this.script("read", tabId, { image }, READ, signal, timeoutMs);
183
188
  const { outline, text, values } = view.data;
184
- const controls = outline.replace(/ \[ref=e\d+\]/g, "").replace(/\[ref=e\d+ /g, "[");
189
+ const controls = outline.replace(/ \[ref=(?:e\d+|(?:f\d+)?a\d+)\]/g, "").replace(/\[ref=(?:e\d+|(?:f\d+)?a\d+) /g, "[");
185
190
  const readable = `${text}${values ? `\n\nField values:\n${values}` : ""}\n\nControls:\n${controls}`;
186
191
  return { tabId: String(tab), url: view.url, title: view.title, outline, text: readable, ...(shot ? { image: shot } : {}) };
187
192
  }
@@ -192,9 +197,10 @@ export class RealBrowserSession {
192
197
  throw new BrowseToolError("tab_missing", "No tab is open in the real browser. Call open with a url.");
193
198
  const code = [`const p = ${JSON.stringify(args)}, timeout = ${Math.max(500, timeoutMs - 2000)};`, PRELUDE, body, EPILOGUE].join("\n");
194
199
  const result = await this.client.call("execute", { tab, code, timeoutMs: Math.max(1500, timeoutMs - 1000) }, signal).catch(error => {
195
- // A failed script's message starts with the tab it ran in, which the caller already knows, and ends with where in the script it threw.
196
- if (error instanceof BrowseToolError && error.code === "real_browser_error")
197
- throw new BrowseToolError(error.code, error.message.replace(/^tab: \S+\s+/, "").replace(/\n\s+at .*$/s, ""));
200
+ // Strip the tab header (including `(also used: ...)`) and QuickJS stack frames, while keeping trailing Page/Warnings/Challenge lines.
201
+ if (error instanceof BrowseToolError && error.code === "real_browser_error") {
202
+ throw new BrowseToolError(error.code, error.message.replace(/^tab: [^\n]+\s+/, "").replace(/(?:\n[ \t]+at [^\n]+)+/g, "").trimEnd());
203
+ }
198
204
  throw error;
199
205
  });
200
206
  const encoded = VIEW.exec(result.text)?.[1];
@@ -285,7 +291,8 @@ export class RealBrowserSession {
285
291
  }
286
292
  }
287
293
  async list(signal) {
288
- return JSON.parse((await this.client.call("tabs", { action: "list", group: this.group }, signal)).text).tabs;
294
+ const { tabs } = JSON.parse((await this.client.call("tabs", { action: "list" }, signal)).text);
295
+ return tabs.filter(tab => tab.group === this.group || tab.lent === true);
289
296
  }
290
297
  output(action, view, tab = this.tab) {
291
298
  return { action, sessionId: null, backend: "local", origin: "connected", ...(tab === undefined ? {} : { tabId: String(tab) }), ...view };
package/dist/schema.d.ts CHANGED
@@ -17,6 +17,7 @@ declare const batchStepFields: z.ZodObject<{
17
17
  }>;
18
18
  url: z.ZodOptional<z.ZodURL>;
19
19
  selector: z.ZodOptional<z.ZodString>;
20
+ force: z.ZodOptional<z.ZodBoolean>;
20
21
  value: z.ZodOptional<z.ZodString>;
21
22
  values: z.ZodOptional<z.ZodArray<z.ZodString>>;
22
23
  key: z.ZodOptional<z.ZodString>;
@@ -83,6 +84,7 @@ export declare const browserParameters: z.ZodObject<{
83
84
  domains: z.ZodOptional<z.ZodArray<z.ZodString>>;
84
85
  profile: z.ZodOptional<z.ZodString>;
85
86
  selector: z.ZodOptional<z.ZodString>;
87
+ force: z.ZodOptional<z.ZodBoolean>;
86
88
  target: z.ZodOptional<z.ZodString>;
87
89
  visual: z.ZodOptional<z.ZodBoolean>;
88
90
  value: z.ZodOptional<z.ZodString>;
@@ -212,6 +214,7 @@ export declare const browserBatchParameters: z.ZodObject<{
212
214
  domains: z.ZodOptional<z.ZodArray<z.ZodString>>;
213
215
  profile: z.ZodOptional<z.ZodString>;
214
216
  selector: z.ZodOptional<z.ZodString>;
217
+ force: z.ZodOptional<z.ZodBoolean>;
215
218
  target: z.ZodOptional<z.ZodString>;
216
219
  visual: z.ZodOptional<z.ZodBoolean>;
217
220
  value: z.ZodOptional<z.ZodString>;
@@ -315,6 +318,7 @@ export declare const browserBatchParameters: z.ZodObject<{
315
318
  }>;
316
319
  url: z.ZodOptional<z.ZodURL>;
317
320
  selector: z.ZodOptional<z.ZodString>;
321
+ force: z.ZodOptional<z.ZodBoolean>;
318
322
  value: z.ZodOptional<z.ZodString>;
319
323
  values: z.ZodOptional<z.ZodArray<z.ZodString>>;
320
324
  key: z.ZodOptional<z.ZodString>;
package/dist/schema.js CHANGED
@@ -77,7 +77,8 @@ const browserFields = {
77
77
  browser: z.enum(BROWSER_IDS).optional().describe("For cookie_profiles and cookie_import: limit to this installed browser. Omit to consider every installed supported browser."),
78
78
  domains: z.array(z.string().min(1).max(255)).min(1).max(20).optional().describe("Required for cookie_import. Explicit bare domains, e.g. github.com, plus the identity provider the sign-in redirects to, e.g. microsoftonline.com; includes their subdomains. Never import unrelated domains."),
79
79
  profile: z.string().regex(/^(?:Default|Profile [0-9]+)$/).optional().describe("Browser profile folder for cookie_import, e.g. Profile 1. Omit to use the only profile with cookies for the domains; set it (with browser) when several match. Discover names with cookie_profiles."),
80
- selector: z.string().min(1).optional().describe("Snapshot reference such as @s1:0-24 (preferred), CSS, xpath=... or //..., or text=.... (xpath)[n] picks the nth match. `>>` enters an iframe; Playwright-only syntax (:has-text(), >> nth=) is unsupported. Required for click/fill/select unless target is used."),
80
+ selector: z.string().min(1).optional().describe("Snapshot reference (preferred: e12 or @e12 in the user's real browser; @s1:0-24 in launched/hosted browsers), CSS, xpath=... or //..., or text=.... (xpath)[n] picks the nth match. `>>` enters an iframe; Playwright-only syntax (:has-text(), >> nth=) is unsupported. Required for click/fill/select unless target is used."),
81
+ force: z.boolean().optional().describe("Only for click, hover, and fill: bypass pointer/actionability hit-testing when a benign page overlay blocks the element (used by the user's real browser)."),
81
82
  target: z.string().trim().min(1).max(500).optional().describe("JEV mode only (/browse jev on): plain-language element description for click/fill/select, used instead of selector."),
82
83
  visual: z.boolean().optional().describe("With target or ask: also send a viewport screenshot to the classifier, for elements and states that labels and page text do not convey (icon-only buttons, canvas, colors). ask uses it for bool and choice fields only. Needs an image-capable classifier; Jev on Vercel AI Gateway is text-only."),
83
84
  value: z.string().optional().describe("Text for fill; may be empty to clear the input."),
@@ -98,7 +99,7 @@ const browserFields = {
98
99
  fields: z.record(z.string().regex(/^[A-Za-z_][A-Za-z0-9_]{0,63}$/), askField).optional().describe("Required for ask: 1 to 20 named questions about the selected page. text, number, date, datetime, and duration read a value (null when the page does not say); bool answers yes/no; choice picks one of options."),
99
100
  message: z.string().trim().min(1).max(500).optional().describe("Required for handoff: what only the person can do in the selected tab, e.g. sign in or approve the 2FA prompt. The call returns once they click Continue. Only in the user's real browser."),
100
101
  path: z.string().regex(/^\/.*\.har$/, "path must be an absolute path ending in .har").optional().describe("Only for har_stop: absolute file path for the HAR, e.g. /abs/scratch/capture.har. Default: a new file in the system temp directory."),
101
- timeoutMs: z.number().int().min(1).max(120_000).optional().describe("Operation deadline; default 30000 (a fixed wait gets durationMs + 5000). Page waits and navigation time out up to 2s earlier. On the deadline the browser is kept if it still responds."),
102
+ timeoutMs: z.number().int().min(1).max(600_000).optional().describe("Operation deadline; default 30000 (fixed wait: durationMs + 5000; handoff: default 600000, maximum 600000; other actions: maximum 120000). Page waits and navigation time out up to 2s earlier. On the deadline the browser is kept if it still responds."),
102
103
  };
103
104
  /** Direct controls a batch step may run. Every other action, including a nested batch, stays a separate call. */
104
105
  const BATCH_ACTIONS = ["open", "back", "forward", "reload", "snapshot", "click", "fill", "select", "press", "scroll", "wait", "evaluate"];
@@ -106,7 +107,8 @@ const BATCH_ACTIONS = ["open", "back", "forward", "reload", "snapshot", "click",
106
107
  const batchStepFields = z.object({
107
108
  action: z.enum(BATCH_ACTIONS, `A batch step must be one of ${BATCH_ACTIONS.join(", ")}; every other action, including a nested batch, is a separate call.`),
108
109
  url: browserFields.url.describe("An http or https URL. Required for open."),
109
- selector: browserFields.selector.describe("Snapshot reference such as @s1:0-24 (preferred), CSS, xpath=... or //..., or text=.... Required for click, fill, and select; for wait, the element to wait for."),
110
+ selector: browserFields.selector.describe("Snapshot reference (preferred: e12 or @e12 in the user's real browser; @s1:0-24 in launched/hosted browsers), CSS, xpath=... or //..., or text=.... Required for click, fill, and select; for wait, the element to wait for."),
111
+ force: browserFields.force,
110
112
  value: browserFields.value,
111
113
  values: browserFields.values,
112
114
  key: browserFields.key,
@@ -127,7 +129,7 @@ const batchStepFields = z.object({
127
129
  /** The arguments each batch action reads. A step carrying any other would see it silently ignored, so it is rejected. */
128
130
  const STEP_ARGUMENTS = {
129
131
  open: { url: true }, back: {}, forward: {}, reload: {}, snapshot: { maxChars: true, offset: true, interactive: true },
130
- click: { selector: true }, fill: { selector: true, value: true }, select: { selector: true, values: true },
132
+ click: { selector: true, force: true }, fill: { selector: true, value: true, force: true }, select: { selector: true, values: true },
131
133
  press: { key: true }, scroll: { deltaX: true, deltaY: true, x: true, y: true },
132
134
  wait: { durationMs: true, selector: true, loadState: true, state: true }, evaluate: { script: true },
133
135
  };
@@ -263,6 +265,12 @@ function checkCall(p, ctx) {
263
265
  if (p.browser !== undefined && p.action !== "cookie_import" && p.action !== "cookie_profiles") {
264
266
  ctx.addIssue({ code: "custom", path: ["browser"], message: "browser is only supported for cookie_profiles and cookie_import" });
265
267
  }
268
+ if (p.force !== undefined && p.action !== "click" && p.action !== "hover" && p.action !== "fill") {
269
+ ctx.addIssue({ code: "custom", path: ["force"], message: "force is only supported for click, hover, and fill" });
270
+ }
271
+ if (p.timeoutMs !== undefined && p.action !== "handoff" && p.timeoutMs > 120_000) {
272
+ ctx.addIssue({ code: "custom", path: ["timeoutMs"], message: "timeoutMs must be at most 120000 for this action (handoff allows up to 600000)" });
273
+ }
266
274
  checkDirectArguments(p, ctx);
267
275
  // Without timeoutMs the deadline already extends past durationMs.
268
276
  if (p.action === "wait" && p.durationMs !== undefined && p.timeoutMs !== undefined && p.durationMs >= p.timeoutMs) {
@@ -291,6 +299,9 @@ export const browserBatchParameters = z.object({
291
299
  }
292
300
  if (p.steps === undefined)
293
301
  ctx.addIssue({ code: "custom", path: ["steps"], message: "steps is required for batch" });
302
+ if (p.timeoutMs !== undefined && p.timeoutMs > 120_000) {
303
+ ctx.addIssue({ code: "custom", path: ["timeoutMs"], message: "timeoutMs must be at most 120000 for batch" });
304
+ }
294
305
  for (const [field, value] of Object.entries(p)) {
295
306
  if (value !== undefined && !Object.hasOwn(BATCH_ARGUMENTS, field)) {
296
307
  ctx.addIssue({ code: "custom", path: [field], message: `${field} is not supported for batch, which takes only steps, tabId, and timeoutMs; put step arguments inside steps` });
package/dist/session.js CHANGED
@@ -271,7 +271,7 @@ export class BrowseSession {
271
271
  async readiness(context, signal) {
272
272
  const resolve = async (purpose) => {
273
273
  try {
274
- return await this.resolveConfig({ ...context, signal, purpose, backend: this.session?.backend ?? this.defaultBackend });
274
+ return await this.resolveConfig({ ...context, signal, purpose, probe: true, backend: this.session?.backend ?? this.defaultBackend });
275
275
  }
276
276
  catch {
277
277
  return undefined;
@@ -314,7 +314,15 @@ export class BrowseSession {
314
314
  if (params.action === "close")
315
315
  this.results.clear();
316
316
  // SAFETY: only browse actions open a browser, and browse_ai calls were excluded.
317
- if (!this.real && !this.delegate && !this.session && !ai && opensBrowser(params))
317
+ // A pre-open `tabs` / failed `tab_select` leaves an idle real-browser handle; release it before an opening call
318
+ // so backend switches, launch options, and domain policies are evaluated fresh.
319
+ if (!ai && this.real && !this.real.active && opensBrowser(params))
320
+ await this.closeReal();
321
+ const attachesReal = opensBrowser(params)
322
+ || params.action === "tabs"
323
+ || params.action === "tab_select"
324
+ || (params.tabId !== undefined && !["close", "status", "result_read", "cookie_profiles", "cookie_import"].includes(params.action));
325
+ if (!this.real && !this.delegate && !this.session && !ai && attachesReal)
318
326
  this.real = await this.realBrowser(params, context);
319
327
  if (this.real) {
320
328
  try {
@@ -401,6 +409,14 @@ export class BrowseSession {
401
409
  if (p.httpAuth || p.backend === "browserbase" || p.cdpUrl || p.endpoint || p.headless !== undefined) {
402
410
  throw new BrowseToolError("browser_change", "Close the current browser before changing its backend, endpoint, or launch settings.");
403
411
  }
412
+ if (p.action === "start" && (p.allowedDomains || p.blockedDomains)) {
413
+ const config = await this.config(context, "local");
414
+ const next = domainLists(config, p);
415
+ const nextOrigins = next?.allowedDomains?.flatMap(domain => [domain, `*.${domain}`]);
416
+ if (next?.blockedDomains?.length || JSON.stringify(nextOrigins) !== JSON.stringify(real.allowedOrigins)) {
417
+ throw new BrowseToolError("domain_policy_change", "Close the current browser before starting with different allowed or blocked domains.");
418
+ }
419
+ }
404
420
  // Listing the cookie sources needs no browser.
405
421
  if (p.action === "cookie_profiles")
406
422
  return this.browse(p, context);
@@ -1513,7 +1529,7 @@ export class BrowseSession {
1513
1529
  let model = session?.config.model;
1514
1530
  if (!session) {
1515
1531
  try {
1516
- model = (await this.resolveConfig({ ...context, backend: this.defaultBackend })).model;
1532
+ model = (await this.resolveConfig({ ...context, probe: true, backend: this.defaultBackend })).model;
1517
1533
  }
1518
1534
  catch { /* Status stays available before configuration exists. */ }
1519
1535
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edlsh/browse-core",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "description": "Host-neutral browser core (Browserbase, local Chrome, remote CDP, Stagehand) shared by omp-browse, pi-browse, and hermes-browse",
5
5
  "keywords": [
6
6
  "browser",