@capybara-hq/plugin-browser 0.1.0-rc.12 → 0.1.0-rc.13

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.12",
4
+ "version": "0.1.0-rc.13",
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.12",
20
+ "version": "0.1.0-rc.13",
21
21
  "sdk": "^0.1.0-rc.83",
22
22
  "provides": [],
23
23
  "requires": [],
package/README.md CHANGED
@@ -83,6 +83,12 @@ A real browser in the person's device for agents (browser use spec,
83
83
  nothing larger is downloaded). First start there: one download into the install directory (about 377 MB, 16 s on a fast
84
84
  link), one restart, then about 2 s to launch. Nothing spoofs a fingerprint, solves a CAPTCHA or
85
85
  hides automation beyond Playwright's own flags (`navigator.webdriver` stays true).
86
+ - Chromium runs with `--no-sandbox` (Playwright's default, `chromiumSandbox: false`) on Linux devices.
87
+ This is a decision (plugins#286): the device container is the isolation boundary (`CapDrop: ALL`,
88
+ `no-new-privileges`, Docker's default seccomp profile, egress through the proxy), and the agent can
89
+ already run arbitrary commands in that container, so a renderer escape gains nothing beyond what
90
+ the agent has. Chromium's sandbox would need user namespaces or a custom seccomp profile for every
91
+ command in the device (rejected), or a separate browser container (not planned now).
86
92
  - Where the browser comes from (plugins#209: never from a place the service or an agent command
87
93
  could write once it runs): the provider's install directory `CAPYBARA_SERVICE_INSTALL`
88
94
  (device-local) is filled on the first start, sealed with `.sealed`, and the daemon answers
package/dist/index.mjs CHANGED
@@ -1514,7 +1514,7 @@ function registerBrowserTools(ctx, deps) {
1514
1514
  // src/index.ts
1515
1515
  var index_default = defineExtension({
1516
1516
  name: "browser",
1517
- version: "0.1.0-rc.12",
1517
+ version: "0.1.0-rc.13",
1518
1518
  sdk: "^0.1.0-rc.83",
1519
1519
  provides: [],
1520
1520
  ui: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/plugin-browser",
3
- "version": "0.1.0-rc.12",
3
+ "version": "0.1.0-rc.13",
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",
@@ -1787,8 +1787,6 @@ var BrowserSession = class {
1787
1787
  * kept in this process's memory only, never in a reply, note, log, viewer message or file.
1788
1788
  */
1789
1789
  credentials = /* @__PURE__ */ new Map();
1790
- /** Whether the credential route is installed (only while credentials exist). */
1791
- authRouted = false;
1792
1790
  /** Pages whose main frame got a sign-in challenge (a 401 with WWW-Authenticate). */
1793
1791
  challenged = /* @__PURE__ */ new WeakSet();
1794
1792
  /** Requests the route signed (a 401 to one of them means the credentials are wrong). */
@@ -1852,7 +1850,22 @@ var BrowserSession = class {
1852
1850
  });
1853
1851
  });
1854
1852
  for (const p of ctx.pages()) this.track(p);
1855
- this.ready = this.installPermissionReports();
1853
+ this.ready = Promise.all([this.installPermissionReports(), this.installAuthRoute()]).then(
1854
+ () => void 0
1855
+ );
1856
+ }
1857
+ /**
1858
+ * The credential route, installed for the session's lifetime (plugins#292): it signs the
1859
+ * requests {@link authHeaderFor} allows, and while any route exists Playwright answers every
1860
+ * site challenge itself, cancelling one no credentials match (the patched playwright-core,
1861
+ * patches/), so a page's fetch, XHR or subresource that gets a Basic challenge completes with
1862
+ * its 401 instead of hanging in the full build. Never fails the session.
1863
+ */
1864
+ async installAuthRoute() {
1865
+ try {
1866
+ await this.ctx.route((u) => this.credentials.has(u.origin), this.onAuthRoute);
1867
+ } catch {
1868
+ }
1856
1869
  }
1857
1870
  /**
1858
1871
  * The permission report (dialogs spec §6): an init script wraps the request APIs and calls the
@@ -2501,7 +2514,7 @@ var BrowserSession = class {
2501
2514
  const origin = h.view.origin;
2502
2515
  if (origin === void 0 || typeof m.username !== "string" || typeof m.password !== "string")
2503
2516
  return;
2504
- await this.signIn(origin, m.username, m.password);
2517
+ this.signIn(origin, m.username, m.password);
2505
2518
  for (const [id, x] of [...this.held])
2506
2519
  if (x.view.kind === "auth" && x.view.origin === origin) this.clearHeld(id);
2507
2520
  this.noteTo(h.owner.owner, `The user signed in to ${origin} (HTTP auth).`);
@@ -2557,22 +2570,15 @@ var BrowserSession = class {
2557
2570
  signInAsked(page, e) {
2558
2571
  return firstLine(e).includes("ERR_INVALID_AUTH_CREDENTIALS") && this.challenged.has(page);
2559
2572
  }
2560
- /** Stores the person's credentials for exactly `origin` and routes them (memory only). */
2561
- async signIn(origin, username, password) {
2573
+ /** Stores the person's credentials for exactly `origin` (memory only; the route signs). */
2574
+ signIn(origin, username, password) {
2562
2575
  this.credentials.set(
2563
2576
  origin,
2564
2577
  `Basic ${Buffer.from(`${username}:${password}`, "utf8").toString("base64")}`
2565
2578
  );
2566
- if (this.authRouted) return;
2567
- this.authRouted = true;
2568
- await this.ctx.route((u) => this.credentials.has(u.origin), this.onAuthRoute).catch(() => {
2569
- this.authRouted = false;
2570
- });
2571
2579
  }
2572
2580
  forgetCredentials(origin) {
2573
- if (!this.credentials.delete(origin) || this.credentials.size > 0 || !this.authRouted) return;
2574
- this.authRouted = false;
2575
- void this.ctx.unroute(() => true, this.onAuthRoute).catch(() => void 0);
2581
+ this.credentials.delete(origin);
2576
2582
  }
2577
2583
  onAuthRoute = async (route) => {
2578
2584
  const r = route.request();
@@ -2586,10 +2592,13 @@ var BrowserSession = class {
2586
2592
  };
2587
2593
  /**
2588
2594
  * The Authorization value a request gets, only where a browser's own page would send it: a
2589
- * request to the signed-in origin from a page whose top-level document has that origin, or a
2590
- * top-level navigation to it that this page started from that origin or that the daemon runs
2595
+ * request to the signed-in origin from a frame whose own document has that origin inside a page
2596
+ * whose top-level document has it too (an iframe's navigation: its parent frame's document), or
2597
+ * a top-level navigation to it that this page started from that origin or that the daemon runs
2591
2598
  * (the agent's or the person's address bar, history, reload). Never a service worker's request,
2592
- * a cross-site page's request (fetch, image, form post) or a redirect into the origin.
2599
+ * a cross-site page's or embedded cross-origin frame's request (fetch, image, form post), or a
2600
+ * redirect into the origin. A redirect out of the origin drops the header on every later hop
2601
+ * (the patched playwright-core, which replays a route's headers on redirects).
2593
2602
  */
2594
2603
  authHeaderFor(r) {
2595
2604
  const origin = originOf(r.url());
@@ -2603,12 +2612,16 @@ var BrowserSession = class {
2603
2612
  }
2604
2613
  const page = frame.page();
2605
2614
  const top = originOf(page.mainFrame().url());
2606
- if (!(r.isNavigationRequest() && frame === page.mainFrame())) {
2607
- return top === origin ? value : void 0;
2608
- }
2609
2615
  let root = r;
2610
2616
  for (let f = r.redirectedFrom(); f !== null; f = f.redirectedFrom()) root = f;
2611
2617
  if (originOf(root.url()) !== origin) return void 0;
2618
+ if (!r.isNavigationRequest()) {
2619
+ return top === origin && originOf(frame.url()) === origin ? value : void 0;
2620
+ }
2621
+ if (frame !== page.mainFrame()) {
2622
+ const parent = frame.parentFrame();
2623
+ return top === origin && parent !== null && originOf(parent.url()) === origin ? value : void 0;
2624
+ }
2612
2625
  if (top === origin || (this.ownNavs.get(page) ?? 0) > 0) return value;
2613
2626
  return void 0;
2614
2627
  }
@@ -37903,6 +37903,11 @@ var init_crNetworkManager = __esm({
37903
37903
  } else if (credentials) {
37904
37904
  response2 = "ProvideCredentials";
37905
37905
  this._attemptedAuthentications.add(attemptKey);
37906
+ } else if (!isProxy) {
37907
+ // capybara patch (plugins#292): no site credentials match, so cancel the challenge and let
37908
+ // the request complete with its 401; "Default" leaves a subresource's challenge hanging in
37909
+ // headless Chromium
37910
+ response2 = "CancelAuth";
37906
37911
  }
37907
37912
  const { username, password } = credentials || { username: void 0, password: void 0 };
37908
37913
  sessionInfo.session._sendMayFail("Fetch.continueWithAuth", {
@@ -37926,8 +37931,12 @@ var init_crNetworkManager = __esm({
37926
37931
  const existingRequest = this._requestIdToRequest.get(requestId);
37927
37932
  const alreadyContinuedParams = existingRequest?._originalRequestRoute?._alreadyContinuedParams;
37928
37933
  if (alreadyContinuedParams && !event.redirectedRequestId) {
37934
+ // capybara patch (plugins#292 review): a redirect hop paused before its
37935
+ // requestWillBeSent lands here too (a subresource's hop carries no redirectedRequestId)
37936
+ const headers = alreadyContinuedParams.headers && crossedOrigin(existingRequest.request, event.request.url) ? alreadyContinuedParams.headers.filter((h) => h.name.toLowerCase() !== "authorization") : alreadyContinuedParams.headers;
37929
37937
  sessionInfo.session._sendMayFail("Fetch.continueRequest", {
37930
37938
  ...alreadyContinuedParams,
37939
+ headers,
37931
37940
  requestId: event.requestId
37932
37941
  });
37933
37942
  return;
@@ -37988,6 +37997,11 @@ var init_crNetworkManager = __esm({
37988
37997
  if (headersOverride) {
37989
37998
  const originalHeaders = Object.entries(requestPausedEvent.request.headers).map(([name, value2]) => ({ name, value: value2 }));
37990
37999
  headersOverride = removeCookieHeader(applyHeadersOverrides(originalHeaders, headersOverride));
38000
+ // capybara patch (plugins#292 review): the route's headers are replayed on every
38001
+ // redirect hop; once the chain leaves the origin of its first request, an
38002
+ // Authorization header is never sent again (as a browser drops it)
38003
+ if (redirectedFrom && crossedOrigin(redirectedFrom.request, requestWillBeSentEvent.request.url))
38004
+ headersOverride = headersOverride.filter((h) => h.name.toLowerCase() !== "authorization");
37991
38005
  }
37992
38006
  requestPausedSessionInfo.session._sendMayFail("Fetch.continueRequest", { requestId: requestPausedEvent.requestId, headers: headersOverride });
37993
38007
  } else {
@@ -53329,6 +53343,22 @@ function validateBrowserContextOptions(options, browserOptions) {
53329
53343
  throw new Error(`"recordVideo.fps" must be a positive number, got ${options.recordVideo.fps}`);
53330
53344
  verifyGeolocation(options.geolocation);
53331
53345
  }
53346
+ // capybara patch (plugins#292 review): whether a redirect chain (its last hop `request`, then
53347
+ // `nextUrl`) has left the origin of its first request
53348
+ function crossedOrigin(request2, nextUrl) {
53349
+ const originOf = (u) => {
53350
+ try {
53351
+ return new URL(u).origin;
53352
+ } catch {
53353
+ return void 0;
53354
+ }
53355
+ };
53356
+ const urls = [nextUrl];
53357
+ for (let r = request2; r; r = r.redirectedFrom())
53358
+ urls.push(r.url());
53359
+ const first = originOf(urls[urls.length - 1]);
53360
+ return first === void 0 || urls.some((u) => originOf(u) !== first);
53361
+ }
53332
53362
  function findMatchingHttpCredentials(credentials, url3) {
53333
53363
  const origin = new URL(url3).origin.toLowerCase();
53334
53364
  return credentials?.find((c) => !c.origin || c.origin.toLowerCase() === origin);