@capybara-hq/plugin-browser 0.1.0-rc.10 → 0.1.0-rc.11

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
3
  "name": "browser",
4
- "version": "0.1.0-rc.10",
4
+ "version": "0.1.0-rc.11",
5
5
  "publisher": "Capybara",
6
6
  "description": {
7
7
  "en": "A real browser in the conversation owner's device for agents: navigate, read and act on pages through tools, with a live view in the conversation panel and takeover by the person",
@@ -17,7 +17,7 @@
17
17
  "entry": "./dist/index.mjs",
18
18
  "manifest": {
19
19
  "name": "browser",
20
- "version": "0.1.0-rc.10",
20
+ "version": "0.1.0-rc.11",
21
21
  "sdk": "^0.1.0-rc.75",
22
22
  "provides": [],
23
23
  "requires": [],
package/dist/index.mjs CHANGED
@@ -1150,7 +1150,7 @@ function registerBrowserTools(ctx, deps) {
1150
1150
  // src/index.ts
1151
1151
  var index_default = defineExtension({
1152
1152
  name: "browser",
1153
- version: "0.1.0-rc.10",
1153
+ version: "0.1.0-rc.11",
1154
1154
  sdk: "^0.1.0-rc.75",
1155
1155
  provides: [],
1156
1156
  ui: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/plugin-browser",
3
- "version": "0.1.0-rc.10",
3
+ "version": "0.1.0-rc.11",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "description": "A real browser in the person's device for agents: navigate, read and act on pages through tools, with a live view in the conversation and takeover by the person",
@@ -1,6 +1,6 @@
1
1
  // @capybara-hq/plugin-browser daemon (generated by daemon/build.ts)
2
2
 
3
- // ../../node_modules/.pnpm/@capybara-hq+plugin-sdk@0.1.0-rc.77/node_modules/@capybara-hq/plugin-sdk/dist/device-provider.js
3
+ // ../../node_modules/.pnpm/@capybara-hq+plugin-sdk@0.1.0-rc.78/node_modules/@capybara-hq/plugin-sdk/dist/device-provider.js
4
4
  var MAX_PATH_LENGTH = 4096;
5
5
  var DEFAULT_SANDBOX_ROOTS = Object.freeze({
6
6
  workspace: "/workspace",
@@ -43,7 +43,7 @@ var STOPS = /* @__PURE__ */ new Set([
43
43
  "path must not contain empty segments"
44
44
  ]);
45
45
 
46
- // ../../node_modules/.pnpm/@capybara-hq+plugin-sdk@0.1.0-rc.77/node_modules/@capybara-hq/plugin-sdk/dist/device-service.js
46
+ // ../../node_modules/.pnpm/@capybara-hq+plugin-sdk@0.1.0-rc.78/node_modules/@capybara-hq/plugin-sdk/dist/device-service.js
47
47
  var DEVICE_SERVICE_SOCKET_ENV = "CAPYBARA_SERVICE_SOCKET";
48
48
  var DEVICE_SERVICE_STATE_ENV = "CAPYBARA_SERVICE_STATE";
49
49
  var DEVICE_SERVICE_MACH_ENV = "CAPYBARA_SERVICE_MACH";
@@ -872,9 +872,14 @@ var PROXY_FAILURE_RE = /ERR_TUNNEL_CONNECTION_FAILED|ERR_PROXY_CONNECTION_FAILED
872
872
  var NETWORK_ERROR_RE = /^ERR_(TIMED_OUT|CONNECTION_[A-Z_]+|NAME_NOT_RESOLVED|NAME_RESOLUTION_FAILED|ADDRESS_UNREACHABLE|EMPTY_RESPONSE|NETWORK_[A-Z_]+|SOCKET_NOT_CONNECTED)$/;
873
873
  var NO_TAB_TO_WAIT_ON = "This conversation has no browser tab to wait on; call browser_navigate to open a page first.";
874
874
  var ERROR_PAGE_INTERRUPT_RE = /is interrupted by another navigation to "chrome-error:/;
875
- var NETWORK_CHANGED_ATTEMPTS = 4;
875
+ var INTERRUPTED_BY_RE = /is interrupted by another navigation to "([^"]*)"/;
876
876
  var ERROR_PAGE_WAIT_MS = 2e3;
877
877
  var isTimeout = (e) => e instanceof Error && e.name === "TimeoutError";
878
+ function timeoutError(message) {
879
+ const e = new Error(message);
880
+ e.name = "TimeoutError";
881
+ return e;
882
+ }
878
883
  var NET_ERROR_MEANINGS = {
879
884
  ERR_NAME_NOT_RESOLVED: "the host name does not resolve",
880
885
  ERR_CONNECTION_REFUSED: "the host refused the connection",
@@ -899,6 +904,37 @@ function docUrl(raw) {
899
904
  return raw;
900
905
  }
901
906
  }
907
+ async function pastNetworkChanges(run, follow, deadline, now = Date.now) {
908
+ for (; ; ) {
909
+ try {
910
+ return await run();
911
+ } catch (e) {
912
+ if (!firstLine(e).includes("net::ERR_NETWORK_CHANGED")) throw e;
913
+ const out = await follow();
914
+ if (out.kind === "loaded") return out.response;
915
+ if (out.kind === "failed" && !out.error.includes("ERR_NETWORK_CHANGED"))
916
+ throw new Error(`${out.error} at ${out.url}`);
917
+ if (now() >= deadline) throw timeoutError(`${firstLine(e)}, past the navigation's deadline`);
918
+ }
919
+ }
920
+ }
921
+ async function pastInterrupts(run, follow, url, deadline, now = Date.now) {
922
+ for (; ; ) {
923
+ try {
924
+ return await run();
925
+ } catch (e) {
926
+ const msg = firstLine(e);
927
+ const by = INTERRUPTED_BY_RE.exec(msg)?.[1];
928
+ const sameAddress = by !== void 0 && docUrl(by) === docUrl(url);
929
+ if (!ERROR_PAGE_INTERRUPT_RE.test(msg) && !sameAddress) throw e;
930
+ const out = await follow();
931
+ if (out.kind === "loaded") return out.response;
932
+ if (out.kind === "failed" && !out.error.includes("net::ERR_ABORTED"))
933
+ throw new Error(`${out.error} at ${out.url}`);
934
+ if (now() >= deadline) throw timeoutError(`${msg}, past the navigation's deadline`);
935
+ }
936
+ }
937
+ }
902
938
  var NavWatch = class {
903
939
  constructor(page, url, pending) {
904
940
  this.page = page;
@@ -2322,48 +2358,27 @@ var BrowserSession = class {
2322
2358
  }
2323
2359
  await page.waitForLoadState("load", { timeout: LOAD_GRACE_MS }).catch(() => void 0);
2324
2360
  }
2325
- /**
2326
- * `goto` past a change of the device's network (an interface came or went: Wi-Fi, a VPN, a
2327
- * container network): Chromium answers net::ERR_NETWORK_CHANGED and may keep or restart the
2328
- * navigation itself, so it is followed first (like one another navigation took over) and run
2329
- * again only when none goes on, at most {@link NETWORK_CHANGED_ATTEMPTS} times, within the
2330
- * navigation's deadline.
2331
- */
2332
- async gotoPastNetworkChange(page, url, watch, deadline) {
2333
- for (let attempt = 1; ; attempt++) {
2334
- try {
2335
- return await this.gotoPastLateErrorPage(page, url, watch, deadline);
2336
- } catch (e) {
2337
- if (!firstLine(e).includes("net::ERR_NETWORK_CHANGED")) throw e;
2338
- const out = await watch.follow(deadline);
2339
- if (out.kind === "loaded") return out.response;
2340
- if (out.kind === "failed" && !out.error.includes("ERR_NETWORK_CHANGED"))
2341
- throw new Error(`${out.error} at ${out.url}`);
2342
- if (attempt >= NETWORK_CHANGED_ATTEMPTS || Date.now() >= deadline) throw e;
2343
- }
2344
- }
2361
+ /** `goto` past changes of the device's network ({@link pastNetworkChanges}). */
2362
+ gotoPastNetworkChange(page, url, watch, deadline) {
2363
+ return pastNetworkChanges(
2364
+ () => this.gotoPastLateErrorPage(page, url, watch, deadline),
2365
+ () => watch.follow(deadline),
2366
+ deadline
2367
+ );
2345
2368
  }
2346
- /**
2347
- * `page.goto`, past the late error page of the tab's previous failed or stopped navigation:
2348
- * Chromium can commit that page after Playwright reported the failure (the Linux full build),
2349
- * and its commit interrupts a navigation started meanwhile. Then this navigation is followed
2350
- * when it went on in Chromium, and otherwise started once more (the error page is in now),
2351
- * within the navigation's own deadline.
2352
- */
2353
- async gotoPastLateErrorPage(page, url, watch, deadline) {
2354
- try {
2355
- return await page.goto(url, { waitUntil: "domcontentloaded" });
2356
- } catch (e) {
2357
- if (!ERROR_PAGE_INTERRUPT_RE.test(firstLine(e))) throw e;
2358
- const out = await watch.follow(deadline);
2359
- if (out.kind === "loaded") return out.response;
2360
- if (out.kind === "failed" && !out.error.includes("net::ERR_ABORTED"))
2361
- throw new Error(`${out.error} at ${out.url}`);
2362
- return page.goto(url, {
2369
+ /** `page.goto`, past the late error page of the tab's previous navigation ({@link pastInterrupts}). */
2370
+ gotoPastLateErrorPage(page, url, watch, deadline) {
2371
+ return pastInterrupts(
2372
+ // a run after an interrupt or a network change gets what is left of the navigation's
2373
+ // time, not all of it
2374
+ () => page.goto(url, {
2363
2375
  waitUntil: "domcontentloaded",
2364
2376
  timeout: Math.max(1, deadline - Date.now())
2365
- });
2366
- }
2377
+ }),
2378
+ () => watch.follow(deadline),
2379
+ url,
2380
+ deadline
2381
+ );
2367
2382
  }
2368
2383
  /**
2369
2384
  * The error of a navigation that failed with Chromium's net error `error`: a host the proxy