@edlsh/browse-core 0.2.0 → 0.2.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/README.md CHANGED
@@ -24,7 +24,7 @@ Stagehand is pinned to 4.3.0 and used unmodified. `overrides` forces zod 4.6.7 b
24
24
 
25
25
  New browsers start locally unless the host or the profile's `/browse backend` setting chooses Browserbase.
26
26
 
27
- A persistent profile (`localUserDataDir`) and an attached browser (`cdpUrl` or a named endpoint) are shared: any number of conversations, in one process or several (omp, pi, and Hermes at once), drive the same browser without closing it under each other. Stagehand's in-browser runtime admits one client, so the first conversation starts a broker (`dist/broker.js`, one detached process per browser, socket under `$XDG_RUNTIME_DIR` or the temp directory, mode 0600) that owns the browser and runs every conversation's calls on it. Each conversation keeps its own tabs, refs, and selected tab. Another conversation's tabs are hidden from `tabs` and `tab_select`, and `har_start` records only its own. A `browse_ai` call runs on the caller's own inference, one call at a time. `close` closes only the caller's tabs. The last conversation to leave quits a launched profile (so its cookies are written) or disconnects from an attached browser, and the broker exits 30 s after its last client.
27
+ A persistent profile (`localUserDataDir`) and an attached browser (`cdpUrl` or a named endpoint) are shared: any number of conversations, in one process or several (omp, pi, and Hermes at once), drive the same browser without closing it under each other. Stagehand's in-browser runtime admits one client, so the first conversation starts a broker (`dist/broker.js`, one detached process per browser, socket under `$XDG_RUNTIME_DIR` or the temp directory, mode 0600) that owns the browser and runs every conversation's calls on it. Each conversation works in a tab of its own (the launcher takes a launched profile's first tab), with its own refs and selected tab. In an attached browser the user's tabs are left alone unless a conversation selects one by `tabId`. Another conversation's tabs are hidden from `tabs` and `tab_select`, and `har_start` records only its own. A `browse_ai` call runs on the caller's own inference, one call at a time. `close` closes only the caller's tabs. The last conversation to leave quits a launched profile (so its cookies are written) or disconnects from an attached browser, and the broker exits 30 s after its last client.
28
28
 
29
29
  Conversations sharing a browser must agree on its launch options: a `start` asking for a different `headless` mode, or different allowed or blocked domains, gets `shared_browser`. Temporary-profile launches stay private to their conversation. `BrowseSessionOptions.profileBroker: false` keeps shared browsers in-process (the broker uses this for itself).
30
30
 
package/dist/session.d.ts CHANGED
@@ -219,11 +219,7 @@ export declare class BrowseSession {
219
219
  private current;
220
220
  private start;
221
221
  private initialize;
222
- /**
223
- * Joins the browser this process shares for a persistent profile or an attached browser, opening it first if needed.
224
- * The launching conversation takes Chrome's first tab and later ones open their own; in an attached browser the
225
- * user's tabs stay available and a conversation claims one on first use.
226
- */
222
+ /** Joins the browser this process shares for a persistent profile or an attached browser, opening it first if needed. */
227
223
  private joinShared;
228
224
  /** Launches a persistent profile or attaches to a browser, with one Stagehand whose default inference follows the AI turn. */
229
225
  private openShared;
package/dist/session.js CHANGED
@@ -896,11 +896,7 @@ export class BrowseSession {
896
896
  throw error;
897
897
  }
898
898
  }
899
- /**
900
- * Joins the browser this process shares for a persistent profile or an attached browser, opening it first if needed.
901
- * The launching conversation takes Chrome's first tab and later ones open their own; in an attached browser the
902
- * user's tabs stay available and a conversation claims one on first use.
903
- */
899
+ /** Joins the browser this process shares for a persistent profile or an attached browser, opening it first if needed. */
904
900
  async joinShared(context, config, p, domainPolicy, attach, userDataDir) {
905
901
  const key = attach ? `attach:${attach.cdpUrl}` : `launch:${userDataDir}`;
906
902
  let shared;
@@ -938,19 +934,14 @@ export class BrowseSession {
938
934
  endpoint: shared.endpoint, headless: shared.headless, debugPort: shared.debugPort, snapshots: new Map(), keepAlive: false,
939
935
  domainPolicy: shared.domainPolicy, shared, ownedTabs: new Set(), createdTabs: new Set(),
940
936
  };
937
+ // Every conversation works in a tab of its own, which close removes: the launcher takes Chrome's first tab, and
938
+ // in an attached browser the user's tabs stay untouched unless a conversation selects one by id.
941
939
  const first = shared.firstTab;
942
940
  shared.firstTab = undefined;
943
- if (first || !attach) {
944
- const tab = first ?? (await shared.browser.context.newPage("about:blank")).pageId;
945
- session.ownedTabs.add(tab);
946
- session.createdTabs.add(tab);
947
- session.tabId = tab;
948
- }
949
- else {
950
- const active = await shared.browser.context.activePage();
951
- if (active && !this.ownedByOther(session, active.pageId))
952
- session.tabId = active.pageId;
953
- }
941
+ const tab = first ?? (await shared.browser.context.newPage("about:blank")).pageId;
942
+ session.ownedTabs.add(tab);
943
+ session.createdTabs.add(tab);
944
+ session.tabId = tab;
954
945
  shared.users.add(session);
955
946
  this.session = session;
956
947
  return session;
@@ -1204,9 +1195,12 @@ export class BrowseSession {
1204
1195
  async page(session, tabId) {
1205
1196
  const pages = await this.visiblePages(session);
1206
1197
  const id = tabId ?? session.tabId;
1207
- const page = id ? pages.find(page => page.pageId === id) : pages.find(page => session.ownedTabs.has(page.pageId)) ?? pages[0];
1198
+ // In a shared browser only a tab chosen by id is taken over; no conversation drifts into the user's or a closed one.
1199
+ const page = id ? pages.find(page => page.pageId === id) : pages.find(page => session.ownedTabs.has(page.pageId)) ?? (session.shared ? undefined : pages[0]);
1208
1200
  if (!page) {
1209
- throw new BrowseToolError("tab_missing", `The target tab is closed or missing${session.shared ? ", or another conversation sharing this browser uses it" : ""}. List tabs, select an existing tab, or create a new one.`);
1201
+ throw new BrowseToolError("tab_missing", session.shared
1202
+ ? "This conversation has no tab here, or the target tab is closed or another conversation's. Open one with tab_new, or select one of the listed tabs by tabId."
1203
+ : "The target tab is closed or missing. List tabs, select an existing tab, or create a new one.");
1210
1204
  }
1211
1205
  if (!session.tabId)
1212
1206
  session.tabId = page.pageId;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edlsh/browse-core",
3
- "version": "0.2.0",
3
+ "version": "0.2.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",