@cydm/pie 4.7.0 → 4.8.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.
@@ -40,7 +40,16 @@ dimensions and screenshot pixels. Emulation changes may reload a page.
40
40
  When an action opens a JavaScript dialog, `DIALOG_PENDING` means it was
41
41
  interrupted after delivery. Do not replay the action or reopen the session.
42
42
  Use `dialog accept`/`dialog dismiss` in that same session, then read the fresh
43
- snapshot. Keep the named session on every command.
43
+ snapshot. If a second dialog opens immediately (e.g. page confirm + `beforeunload`),
44
+ `dialog` reports `nextDialogPending: true` — handle it again before snapshotting.
45
+ Keep the named session on every command.
46
+
47
+ ## Verification & Approval Rules
48
+
49
+ - **Never equate "action sent" with "saved/persisted"**: clicking Save only confirms the click was dispatched — it never guarantees async form state settled or the backend persisted the intended value. Before clicking Save, wait for loading indicators (`wait "Loading..." --absent`) and confirm the visible selected value (`wait "<value>" --visible`); after clicking Save, verify the submit request/response (`network --type fetch --preserved --full` / `network-get <id> --full`) and/or read back after reload.
50
+ - **Ignore hidden/closed dropdown DOM**: use `wait "<text>" --visible` when waiting for UI options or confirmations.
51
+ - **Virtualized lists requiring trusted wheel input**: `scroll --wheel` dispatches a synthetic DOM `WheelEvent` (`isTrusted=false`, because `chrome-devtools-mcp` exposes no native mouse-wheel tool). If a virtual list ignores untrusted wheel events, focus the container and use `press PageDown`/`ArrowDown` (real CDP keyboard input, `isTrusted=true`), or use `computer-use-axi` (native CDP `mouseWheel` / OS wheel, `isTrusted=true`).
52
+ - **Do not restart the bridge while waiting for Chrome's approval dialog**: in default `--autoConnect` mode, the CLI prints a waiting notice to stderr while Chrome asks the user to click Allow. Let it complete instead of running `stop`/retrying concurrently.
44
53
 
45
54
  Agent-ergonomic interface for controlling a real Chrome browser session (Chrome DevTools Protocol). Prefer this over other browser automation approaches. Skip it when a plain `fetch`/`curl` or the `web_fetch`/`web_research` tools suffice - only open a browser when you actually need rendering, interaction, or session state.
46
55
 
@@ -6,10 +6,11 @@ import {
6
6
  clearSelectedPageId,
7
7
  inspectProcessIdentity,
8
8
  readSelfStartTime,
9
+ resolveSessionLogFile,
9
10
  resolveSessionName,
10
11
  resolveSessionPidFile,
11
12
  resolveSessionPort
12
- } from "./chunk-WOGAQ4P5.js";
13
+ } from "./chunk-Z2A5LA5A.js";
13
14
  import {
14
15
  __commonJS,
15
16
  __export,
@@ -19790,7 +19791,44 @@ async function handleCallRequest(client, req, res, onPageIdentityChanged) {
19790
19791
  }
19791
19792
  writeJson(res, 200, { result: text });
19792
19793
  }
19793
- async function handleBridgeRequest(client, req, res, sessionName, logForbidden, onPageIdentityChanged) {
19794
+ var DEFAULT_DEEP_HEALTH_WAIT_MS = 2500;
19795
+ var MAX_DEEP_HEALTH_WAIT_MS = 3e4;
19796
+ function parseDeepHealthWaitMs(url2) {
19797
+ const queryStart = url2.indexOf("?");
19798
+ if (queryStart === -1) return DEFAULT_DEEP_HEALTH_WAIT_MS;
19799
+ const params = new URLSearchParams(url2.slice(queryStart + 1));
19800
+ const raw = params.get("waitMs");
19801
+ if (!raw) return DEFAULT_DEEP_HEALTH_WAIT_MS;
19802
+ const parsed = Number.parseInt(raw, 10);
19803
+ if (!Number.isFinite(parsed) || parsed < 0) return DEFAULT_DEEP_HEALTH_WAIT_MS;
19804
+ return Math.min(parsed, MAX_DEEP_HEALTH_WAIT_MS);
19805
+ }
19806
+ async function raceWithTimeout(promise, timeoutMs) {
19807
+ if (timeoutMs <= 0) {
19808
+ let settled = false;
19809
+ let value;
19810
+ await Promise.race([
19811
+ promise.then((v) => {
19812
+ settled = true;
19813
+ value = v;
19814
+ }),
19815
+ new Promise((resolve2) => setImmediate(resolve2))
19816
+ ]);
19817
+ return settled ? { settled: true, value } : { settled: false };
19818
+ }
19819
+ let timer;
19820
+ try {
19821
+ return await Promise.race([
19822
+ promise.then((value) => ({ settled: true, value })),
19823
+ new Promise((resolve2) => {
19824
+ timer = setTimeout(() => resolve2({ settled: false }), timeoutMs);
19825
+ })
19826
+ ]);
19827
+ } finally {
19828
+ if (timer) clearTimeout(timer);
19829
+ }
19830
+ }
19831
+ async function handleBridgeRequest(client, req, res, sessionName, logForbidden, onPageIdentityChanged, pendingDroppedSelectionLatch) {
19794
19832
  res.setHeader("Content-Type", "application/json");
19795
19833
  if (!isRequestAllowed(req)) {
19796
19834
  const rawOrigin = req.headers.origin;
@@ -19804,25 +19842,83 @@ async function handleBridgeRequest(client, req, res, sessionName, logForbidden,
19804
19842
  try {
19805
19843
  if (req.method === "GET" && (req.url === "/health" || req.url?.startsWith("/health?"))) {
19806
19844
  if (!await isBridgeClientConnected(client)) {
19807
- writeJson(res, 503, { status: "error", error: "Not connected" });
19845
+ writeJson(res, 503, {
19846
+ status: "error",
19847
+ error: "Not connected",
19848
+ mcpDisconnected: true,
19849
+ session: sessionName,
19850
+ pid: process.pid
19851
+ });
19808
19852
  return;
19809
19853
  }
19810
19854
  const deep = req.url.includes("deep=1");
19855
+ const statusBefore = client.getStatus?.();
19856
+ const busyBefore = client.isBusy?.() ?? false;
19857
+ const probeInFlight = statusBefore?.probeInFlight ?? false;
19811
19858
  let droppedSelection = false;
19812
- if (deep && !client.isBusy?.()) {
19813
- const probe = await isBridgeTargetReachable(client);
19814
- if (!probe.ok) {
19815
- writeJson(res, 503, {
19816
- status: "error",
19817
- error: "CDP target unreachable",
19818
- reason: probe.reason
19859
+ if (deep && (!busyBefore || probeInFlight)) {
19860
+ if (client.probeReachable) {
19861
+ const waitMs = parseDeepHealthWaitMs(req.url);
19862
+ const probePromise = client.probeReachable();
19863
+ let responded = false;
19864
+ void probePromise.then((probe2) => {
19865
+ if (!responded || !probe2.ok || !probe2.pageIdentityChanged) return;
19866
+ if (onPageIdentityChanged?.() === true && pendingDroppedSelectionLatch) {
19867
+ pendingDroppedSelectionLatch.value = true;
19868
+ }
19819
19869
  });
19820
- return;
19821
- }
19822
- if (probe.pageIdentityChanged) {
19823
- droppedSelection = onPageIdentityChanged?.() === true;
19870
+ const raced = await raceWithTimeout(probePromise, waitMs);
19871
+ if (!raced.settled) {
19872
+ responded = true;
19873
+ const currentStatus = client.getStatus?.();
19874
+ writeJson(res, 202, {
19875
+ status: "pending",
19876
+ session: sessionName,
19877
+ pid: process.pid,
19878
+ busy: true,
19879
+ cdpState: currentStatus?.cdpState ?? "awaiting_approval",
19880
+ ...currentStatus?.waitingMs !== void 0 ? { waitingMs: currentStatus.waitingMs } : {},
19881
+ logFile: resolveSessionLogFile(sessionName)
19882
+ });
19883
+ return;
19884
+ }
19885
+ const probe = raced.value;
19886
+ if (!probe.ok) {
19887
+ writeJson(res, 503, {
19888
+ status: "error",
19889
+ error: "CDP target unreachable",
19890
+ reason: probe.reason,
19891
+ cdpState: client.getStatus?.().cdpState ?? "failed",
19892
+ session: sessionName,
19893
+ pid: process.pid
19894
+ });
19895
+ return;
19896
+ }
19897
+ if (probe.pageIdentityChanged) {
19898
+ droppedSelection = onPageIdentityChanged?.() === true;
19899
+ }
19900
+ } else {
19901
+ const probe = await isBridgeTargetReachable(client);
19902
+ if (!probe.ok) {
19903
+ writeJson(res, 503, {
19904
+ status: "error",
19905
+ error: "CDP target unreachable",
19906
+ reason: probe.reason,
19907
+ session: sessionName,
19908
+ pid: process.pid
19909
+ });
19910
+ return;
19911
+ }
19912
+ if (probe.pageIdentityChanged) {
19913
+ droppedSelection = onPageIdentityChanged?.() === true;
19914
+ }
19824
19915
  }
19825
19916
  }
19917
+ if (deep && pendingDroppedSelectionLatch?.value) {
19918
+ droppedSelection = true;
19919
+ pendingDroppedSelectionLatch.value = false;
19920
+ }
19921
+ const statusAfter = client.getStatus?.();
19826
19922
  writeJson(res, 200, {
19827
19923
  status: "ok",
19828
19924
  session: sessionName,
@@ -19832,6 +19928,10 @@ async function handleBridgeRequest(client, req, res, sessionName, logForbidden,
19832
19928
  // must not authorize killing an unrelated reused PID.
19833
19929
  pid: process.pid,
19834
19930
  busy: client.isBusy?.() ?? false,
19931
+ ...statusAfter ? {
19932
+ cdpState: statusAfter.cdpState,
19933
+ dialogPending: statusAfter.dialogPending
19934
+ } : {},
19835
19935
  ...droppedSelection ? { pageIdentityChanged: true } : {}
19836
19936
  });
19837
19937
  return;
@@ -19850,7 +19950,7 @@ async function handleBridgeRequest(client, req, res, sessionName, logForbidden,
19850
19950
  }
19851
19951
  writeJson(res, 404, { error: "not found" });
19852
19952
  }
19853
- function createBridgeServer(client, sessionName) {
19953
+ function createBridgeServer(client, sessionName, pendingDroppedSelectionLatch = { value: false }) {
19854
19954
  return createServer((req, res) => {
19855
19955
  void handleBridgeRequest(
19856
19956
  client,
@@ -19858,7 +19958,8 @@ function createBridgeServer(client, sessionName) {
19858
19958
  res,
19859
19959
  sessionName,
19860
19960
  logBridgeMessage,
19861
- clearSelectedPageId
19961
+ clearSelectedPageId,
19962
+ pendingDroppedSelectionLatch
19862
19963
  );
19863
19964
  });
19864
19965
  }
@@ -19950,14 +20051,22 @@ var KEYCHAIN_ISOLATION_CHROME_ARGS = [
19950
20051
  "--use-mock-keychain",
19951
20052
  "--password-store=basic"
19952
20053
  ];
19953
- function isAttachTransportMode() {
19954
- const explicitAutoConnect = process.env.CHROME_DEVTOOLS_AXI_AUTO_CONNECT;
20054
+ function isAutoConnectMode() {
19955
20055
  const freshInstance = process.env.CHROME_DEVTOOLS_AXI_FRESH === "1";
20056
+ if (freshInstance) return false;
20057
+ if (process.env.CHROME_DEVTOOLS_AXI_MCP_SERVER_URL?.trim()) return false;
20058
+ const explicitAutoConnect = process.env.CHROME_DEVTOOLS_AXI_AUTO_CONNECT;
19956
20059
  const browserUrl = process.env.CHROME_DEVTOOLS_AXI_BROWSER_URL;
19957
20060
  const userDataDir = process.env.CHROME_DEVTOOLS_AXI_USER_DATA_DIR;
19958
20061
  const autoConnectUnset = explicitAutoConnect === void 0 || explicitAutoConnect === "";
19959
- const autoConnect = !freshInstance && (explicitAutoConnect === "1" || autoConnectUnset && !browserUrl && !userDataDir);
19960
- return autoConnect || !freshInstance && !!browserUrl;
20062
+ return explicitAutoConnect === "1" || autoConnectUnset && !browserUrl && !userDataDir;
20063
+ }
20064
+ function isAttachTransportMode() {
20065
+ const freshInstance = process.env.CHROME_DEVTOOLS_AXI_FRESH === "1";
20066
+ if (freshInstance) return false;
20067
+ if (process.env.CHROME_DEVTOOLS_AXI_MCP_SERVER_URL?.trim()) return false;
20068
+ const browserUrl = process.env.CHROME_DEVTOOLS_AXI_BROWSER_URL;
20069
+ return isAutoConnectMode() || !!browserUrl;
19961
20070
  }
19962
20071
  function resolveCdpKeepaliveMs() {
19963
20072
  const raw = Number(process.env.CHROME_DEVTOOLS_AXI_CDP_KEEPALIVE_MS);
@@ -20202,7 +20311,7 @@ function rootUrisEqual(a, b) {
20202
20311
  if (a.length !== b.length) return false;
20203
20312
  return a.every((root, i) => root.uri === b[i]?.uri);
20204
20313
  }
20205
- function createRootsAwareBridgeClient(client) {
20314
+ function createRootsAwareBridgeClient(client, opts = {}) {
20206
20315
  let currentRoots = [];
20207
20316
  let confirmedRoots = [];
20208
20317
  let onRootsFetched = null;
@@ -20259,26 +20368,90 @@ function createRootsAwareBridgeClient(client) {
20259
20368
  }
20260
20369
  let pendingCalls = 0;
20261
20370
  let dialogPending = false;
20371
+ let cdpState = "unconnected";
20372
+ let lastError;
20373
+ let probePromise = null;
20374
+ let probeStartedAt = 0;
20262
20375
  async function trackedCall(request) {
20263
20376
  const result = await client.callTool(request);
20264
20377
  const text = extractToolText(getToolContent(result));
20265
- if (/^# Open dialog\b/m.test(text)) dialogPending = true;
20266
- if (request.name === "handle_dialog" && !isToolResultError(result)) dialogPending = false;
20378
+ const isErr = isToolResultError(result);
20379
+ const hasOpenDialog = /^# Open dialog\b/m.test(text);
20380
+ if (request.name === "handle_dialog" && (!isErr || /no open dialog/i.test(text)) || !isErr && request.name !== "list_pages" && !hasOpenDialog) {
20381
+ dialogPending = false;
20382
+ }
20383
+ if (hasOpenDialog) {
20384
+ dialogPending = true;
20385
+ }
20386
+ if (!isErr) {
20387
+ cdpState = "connected";
20388
+ lastError = void 0;
20389
+ }
20267
20390
  return result;
20268
20391
  }
20392
+ function callTool(request, roots) {
20393
+ if (request.name === "handle_dialog") return trackedCall(request);
20394
+ pendingCalls++;
20395
+ return enqueue(async () => {
20396
+ if (roots) await applyRootsNow(roots);
20397
+ return trackedCall(request);
20398
+ }).finally(() => {
20399
+ pendingCalls--;
20400
+ });
20401
+ }
20402
+ function probeReachable() {
20403
+ if (probePromise) return probePromise;
20404
+ probeStartedAt = Date.now();
20405
+ if (cdpState !== "connected") {
20406
+ cdpState = opts.autoConnect ? "awaiting_approval" : "connecting";
20407
+ }
20408
+ let current = null;
20409
+ current = (async () => {
20410
+ try {
20411
+ const result = await callTool({ name: "list_pages", arguments: {} });
20412
+ if (isToolResultError(result)) {
20413
+ const reason = extractToolText(getToolContent(result)) || 'Tool "list_pages" failed';
20414
+ cdpState = "failed";
20415
+ lastError = reason;
20416
+ return { ok: false, reason };
20417
+ }
20418
+ cdpState = "connected";
20419
+ lastError = void 0;
20420
+ return {
20421
+ ok: true,
20422
+ pageIdentityChanged: didMcpPageIdentityChange(result)
20423
+ };
20424
+ } catch (error2) {
20425
+ const reason = getErrorMessage(error2);
20426
+ cdpState = "failed";
20427
+ lastError = reason;
20428
+ return { ok: false, reason };
20429
+ } finally {
20430
+ if (probePromise === current) {
20431
+ probePromise = null;
20432
+ probeStartedAt = 0;
20433
+ }
20434
+ }
20435
+ })();
20436
+ probePromise = current;
20437
+ return current;
20438
+ }
20269
20439
  return {
20270
20440
  isBusy: () => pendingCalls > 0 || dialogPending,
20271
- listTools: () => client.listTools(),
20272
- callTool: (request, roots) => {
20273
- if (request.name === "handle_dialog") return trackedCall(request);
20274
- pendingCalls++;
20275
- return enqueue(async () => {
20276
- if (roots) await applyRootsNow(roots);
20277
- return trackedCall(request);
20278
- }).finally(() => {
20279
- pendingCalls--;
20280
- });
20441
+ getStatus: () => ({
20442
+ cdpState,
20443
+ dialogPending,
20444
+ probeInFlight: probePromise !== null,
20445
+ ...probeStartedAt > 0 ? { waitingMs: Date.now() - probeStartedAt } : {},
20446
+ ...lastError !== void 0 ? { lastError } : {}
20447
+ }),
20448
+ probeReachable,
20449
+ markDisconnected: (reason) => {
20450
+ cdpState = "failed";
20451
+ lastError = reason;
20281
20452
  },
20453
+ listTools: () => client.listTools(),
20454
+ callTool,
20282
20455
  close: () => client.close(),
20283
20456
  applyRoots: (dirs) => enqueue(() => applyRootsNow(dirs))
20284
20457
  };
@@ -20295,27 +20468,43 @@ async function closeServer(server) {
20295
20468
  });
20296
20469
  }
20297
20470
  async function runBridge(port = resolveSessionPort()) {
20471
+ const attachMode = isAttachTransportMode();
20472
+ const autoConnect = isAutoConnectMode();
20298
20473
  const bridgeTransport = createTransport();
20299
20474
  const client = createBridgeClient();
20300
- const bridgeClient = createRootsAwareBridgeClient(client);
20475
+ const bridgeClient = createRootsAwareBridgeClient(client, { autoConnect });
20301
20476
  await client.connect(bridgeTransport.transport);
20302
20477
  logBridgeMessage("Connected to chrome-devtools-mcp");
20303
- const attachMode = isAttachTransportMode();
20478
+ const pendingDroppedSelectionLatch = { value: false };
20479
+ let keepalive;
20304
20480
  if (attachMode) {
20305
20481
  const keepaliveMs = resolveCdpKeepaliveMs();
20306
- const keepalive = setInterval(() => {
20482
+ keepalive = setInterval(() => {
20307
20483
  if (bridgeClient.isBusy?.()) return;
20308
- bridgeClient.callTool({ name: "list_pages", arguments: {} }).then(
20309
- () => void 0,
20310
- (error2) => logBridgeMessage(
20311
- `CDP keepalive probe failed: ${getErrorMessage(error2)}`
20312
- )
20484
+ if (bridgeClient.getStatus?.().cdpState !== "connected") return;
20485
+ void bridgeClient.probeReachable?.().then(
20486
+ (probe) => {
20487
+ if (!probe.ok) {
20488
+ logBridgeMessage(`CDP keepalive probe failed: ${probe.reason}`);
20489
+ } else if (probe.pageIdentityChanged && clearSelectedPageId()) {
20490
+ pendingDroppedSelectionLatch.value = true;
20491
+ }
20492
+ },
20493
+ (error2) => {
20494
+ const msg = getErrorMessage(error2);
20495
+ bridgeClient.markDisconnected?.(msg);
20496
+ logBridgeMessage(`CDP keepalive probe failed: ${msg}`);
20497
+ }
20313
20498
  );
20314
20499
  }, keepaliveMs);
20315
20500
  keepalive.unref?.();
20316
20501
  }
20317
20502
  const sessionName = resolveSessionName();
20318
- const server = createBridgeServer(bridgeClient, sessionName);
20503
+ const server = createBridgeServer(
20504
+ bridgeClient,
20505
+ sessionName,
20506
+ pendingDroppedSelectionLatch
20507
+ );
20319
20508
  const lifecycle = createBridgeLifecycle(() => shutdown(), {
20320
20509
  anchor: parseSupervisorAnchor2()
20321
20510
  });
@@ -20332,6 +20521,7 @@ async function runBridge(port = resolveSessionPort()) {
20332
20521
  const shutdown = async () => {
20333
20522
  if (shuttingDown) return;
20334
20523
  shuttingDown = true;
20524
+ if (keepalive) clearInterval(keepalive);
20335
20525
  lifecycle.dispose();
20336
20526
  removePidFile();
20337
20527
  await closeServer(server);
@@ -21,6 +21,6 @@ function tryFastPath(argv, options) {
21
21
 
22
22
  // vendor/chrome-devtools-axi/bin/chrome-devtools-axi.ts
23
23
  if (!tryFastPath(process.argv.slice(2), { version: VERSION })) {
24
- const { main } = await import("./cli-NLPMVDGG.js");
24
+ const { main } = await import("./cli-ZE754CTH.js");
25
25
  await main(process.argv.slice(2));
26
26
  }
@@ -251,6 +251,12 @@ function resolveSessionStateDir(name = resolveSessionName()) {
251
251
  function resolveSessionPidFile(name = resolveSessionName()) {
252
252
  return join(resolveSessionStateDir(name), "bridge.pid");
253
253
  }
254
+ function resolveSessionLogFile(name = resolveSessionName()) {
255
+ return join(resolveSessionStateDir(name), "bridge.log");
256
+ }
257
+ function resolveSessionStartLockFile(name = resolveSessionName()) {
258
+ return join(resolveSessionStateDir(name), "bridge.start.lock");
259
+ }
254
260
 
255
261
  // vendor/chrome-devtools-axi/src/selected-page.ts
256
262
  function selectedPageFile() {
@@ -390,6 +396,8 @@ export {
390
396
  resolveSessionPort,
391
397
  resolveSessionStateDir,
392
398
  resolveSessionPidFile,
399
+ resolveSessionLogFile,
400
+ resolveSessionStartLockFile,
393
401
  getSelectedPageId,
394
402
  setSelectedPageId,
395
403
  clearSelectedPageId,