cdp-toolkit 3.4.0 → 3.6.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.
package/dist/mcp.js CHANGED
@@ -323,6 +323,9 @@ function leaseTtlMs() {
323
323
  function markLongLivedProcess(value = true) {
324
324
  longLived = value;
325
325
  }
326
+ function isLongLivedProcess() {
327
+ return longLived;
328
+ }
326
329
  function requireLease() {
327
330
  if (!longLived)
328
331
  return false;
@@ -588,6 +591,15 @@ var init_leases = __esm(() => {
588
591
  LEASE_FILE_RE = new RegExp(`^lease-(${BACKEND_KEY_SOURCE})-(.+)\\.json$`);
589
592
  });
590
593
 
594
+ // src/focusPolicy.ts
595
+ function focusDenied() {
596
+ return TRUTHY.has((process.env.CDP_DENY_FOCUS ?? "").trim().toLowerCase());
597
+ }
598
+ var TRUTHY;
599
+ var init_focusPolicy = __esm(() => {
600
+ TRUTHY = new Set(["1", "true", "yes", "on"]);
601
+ });
602
+
591
603
  // src/origins.ts
592
604
  import { mkdir as mkdir2, readFile as readFile2, readdir as readdir2, unlink as unlink2, writeFile as writeFile2 } from "node:fs/promises";
593
605
  import { join as join2 } from "node:path";
@@ -687,7 +699,7 @@ async function originIndex(backend, liveIds) {
687
699
  return index;
688
700
  }
689
701
  async function newTrackedPage(driver, backend, opts = {}) {
690
- const page = await driver.newPage(opts.url, { focus: opts.focus === true });
702
+ const page = await driver.newPage(opts.url, { focus: opts.focus === true && !focusDenied() });
691
703
  await recordOrigin(backend, page.id, { label: opts.label });
692
704
  return page;
693
705
  }
@@ -714,6 +726,7 @@ async function resolveLiveLabel(backend, label, liveIds) {
714
726
  }
715
727
  var ORIGIN_FILE_RE;
716
728
  var init_origins = __esm(() => {
729
+ init_focusPolicy();
717
730
  init_leases();
718
731
  ORIGIN_FILE_RE = new RegExp(`^origin-(${BACKEND_KEY_SOURCE})-(.+)\\.json$`);
719
732
  });
@@ -1001,6 +1014,165 @@ var init_session = __esm(() => {
1001
1014
  init_endpoint();
1002
1015
  });
1003
1016
 
1017
+ // src/cdp/hiddenTabs.ts
1018
+ function hiddenTabsRequested() {
1019
+ return TRUTHY2.has((process.env.CDP_HIDDEN_TABS ?? "").trim().toLowerCase());
1020
+ }
1021
+ function hiddenTabsMax() {
1022
+ const raw = Number(process.env.CDP_HIDDEN_TABS_MAX);
1023
+ return Number.isFinite(raw) && raw >= 1 ? Math.floor(raw) : DEFAULT_HIDDEN_TABS_MAX;
1024
+ }
1025
+
1026
+ class HiddenTabOwner {
1027
+ deps;
1028
+ conn;
1029
+ connecting;
1030
+ tabs = new Map;
1031
+ reserved = 0;
1032
+ constructor(deps) {
1033
+ this.deps = deps;
1034
+ }
1035
+ sweep() {
1036
+ if (this.conn && !this.conn.isOpen) {
1037
+ this.conn = undefined;
1038
+ this.tabs.clear();
1039
+ }
1040
+ }
1041
+ has(id) {
1042
+ this.sweep();
1043
+ return this.tabs.has(id);
1044
+ }
1045
+ ids() {
1046
+ this.sweep();
1047
+ return [...this.tabs.keys()];
1048
+ }
1049
+ async owner() {
1050
+ this.sweep();
1051
+ if (this.conn)
1052
+ return this.conn;
1053
+ if (!this.connecting) {
1054
+ this.connecting = (async () => {
1055
+ const conn = await this.deps.connect();
1056
+ conn.on("Target.targetDestroyed", (params) => {
1057
+ const id = params.targetId;
1058
+ if (typeof id === "string")
1059
+ this.tabs.delete(id);
1060
+ });
1061
+ this.conn = conn;
1062
+ return conn;
1063
+ })().finally(() => {
1064
+ this.connecting = undefined;
1065
+ });
1066
+ }
1067
+ return this.connecting;
1068
+ }
1069
+ async create(url) {
1070
+ this.sweep();
1071
+ const max = (this.deps.max ?? hiddenTabsMax)();
1072
+ if (this.tabs.size + this.reserved >= max)
1073
+ throw new HiddenTabCapError(max, [...this.tabs.keys()]);
1074
+ this.reserved++;
1075
+ try {
1076
+ const conn = await this.owner();
1077
+ const id = await this.deps.createSettled(conn, url, { hidden: true });
1078
+ try {
1079
+ const { sessionId } = await conn.send("Target.attachToTarget", { targetId: id, flatten: true }, { timeoutMs: OWNER_COMMAND_TIMEOUT_MS });
1080
+ const dpr = await conn.send("Runtime.evaluate", { expression: "devicePixelRatio", returnByValue: true }, { sessionId, timeoutMs: OWNER_COMMAND_TIMEOUT_MS }).then((r) => r.result?.value).catch(() => {
1081
+ return;
1082
+ });
1083
+ await conn.send("Emulation.setDeviceMetricsOverride", {
1084
+ width: HIDDEN_TAB_VIEWPORT.width,
1085
+ height: HIDDEN_TAB_VIEWPORT.height,
1086
+ deviceScaleFactor: typeof dpr === "number" && Number.isFinite(dpr) && dpr > 0 ? dpr : FALLBACK_DEVICE_SCALE_FACTOR,
1087
+ mobile: false
1088
+ }, { sessionId, timeoutMs: OWNER_COMMAND_TIMEOUT_MS });
1089
+ this.tabs.set(id, sessionId);
1090
+ return id;
1091
+ } catch (e) {
1092
+ await conn.send("Target.closeTarget", { targetId: id }, { timeoutMs: OWNER_COMMAND_TIMEOUT_MS }).catch(() => {
1093
+ return;
1094
+ });
1095
+ throw e;
1096
+ }
1097
+ } finally {
1098
+ this.reserved--;
1099
+ }
1100
+ }
1101
+ async close(id) {
1102
+ this.sweep();
1103
+ const conn = this.conn;
1104
+ const held = this.tabs.delete(id);
1105
+ if (!conn || !held)
1106
+ return { success: false };
1107
+ const res = await conn.send("Target.closeTarget", { targetId: id }, { timeoutMs: OWNER_COMMAND_TIMEOUT_MS });
1108
+ return { success: res.success ?? true };
1109
+ }
1110
+ async dispose() {
1111
+ const conn = this.conn;
1112
+ const ids = [...this.tabs.keys()];
1113
+ this.tabs.clear();
1114
+ this.conn = undefined;
1115
+ if (!conn)
1116
+ return;
1117
+ if (conn.isOpen) {
1118
+ await Promise.all(ids.map((targetId) => conn.send("Target.closeTarget", { targetId }, { timeoutMs: OWNER_COMMAND_TIMEOUT_MS }).catch(() => {
1119
+ return;
1120
+ })));
1121
+ }
1122
+ conn.close();
1123
+ }
1124
+ }
1125
+ function hiddenTabOwner(base, deps) {
1126
+ let owner = owners.get(base);
1127
+ if (!owner) {
1128
+ owner = new HiddenTabOwner(deps());
1129
+ owners.set(base, owner);
1130
+ }
1131
+ return owner;
1132
+ }
1133
+ function existingHiddenTabOwner(base) {
1134
+ return owners.get(base);
1135
+ }
1136
+ function markHiddenTargets(base, targets) {
1137
+ const owner = owners.get(base);
1138
+ if (!owner)
1139
+ return targets;
1140
+ const hidden = new Set(owner.ids());
1141
+ if (hidden.size === 0)
1142
+ return targets;
1143
+ const visible = [];
1144
+ const marked = [];
1145
+ for (const t of targets) {
1146
+ if (hidden.has(t.id))
1147
+ marked.push({ ...t, type: "page", hidden: true });
1148
+ else
1149
+ visible.push(t);
1150
+ }
1151
+ return marked.length ? [...visible, ...marked] : targets;
1152
+ }
1153
+ async function disposeHiddenTabs() {
1154
+ const all = [...owners.values()];
1155
+ owners.clear();
1156
+ await Promise.all(all.map((o) => o.dispose()));
1157
+ }
1158
+ var DEFAULT_HIDDEN_TABS_MAX = 20, HIDDEN_TAB_VIEWPORT, FALLBACK_DEVICE_SCALE_FACTOR = 2, OWNER_COMMAND_TIMEOUT_MS = 5000, TRUTHY2, HiddenTabCapError, owners;
1159
+ var init_hiddenTabs = __esm(() => {
1160
+ HIDDEN_TAB_VIEWPORT = { width: 1280, height: 800 };
1161
+ TRUTHY2 = new Set(["1", "true", "yes", "on"]);
1162
+ HiddenTabCapError = class HiddenTabCapError extends Error {
1163
+ max;
1164
+ openIds;
1165
+ code = "page-error";
1166
+ constructor(max, openIds) {
1167
+ super(`hidden-tab cap reached: ${openIds.length} hidden tabs are open (CDP_HIDDEN_TABS_MAX=${max}). ` + `Close one with close_page (open hidden tabs, oldest first: ${openIds.join(", ")}), ` + `or pass focus:true to open a visible tab instead.`);
1168
+ this.max = max;
1169
+ this.openIds = openIds;
1170
+ this.name = "HiddenTabCapError";
1171
+ }
1172
+ };
1173
+ owners = new Map;
1174
+ });
1175
+
1004
1176
  // src/client.ts
1005
1177
  class CdpConnection {
1006
1178
  wsUrl;
@@ -1119,6 +1291,9 @@ class CdpConnection {
1119
1291
  });
1120
1292
  });
1121
1293
  }
1294
+ get isOpen() {
1295
+ return !this.closed && this.ws !== undefined;
1296
+ }
1122
1297
  close() {
1123
1298
  this.closed = true;
1124
1299
  this.rejectAll(new CdpError("closed by caller"));
@@ -1147,11 +1322,11 @@ async function getTargetsOverBrowserWs() {
1147
1322
  async function listTargets() {
1148
1323
  const base = currentEndpoint().base;
1149
1324
  if (knownTransports.get(base) === "browser-ws")
1150
- return getTargetsOverBrowserWs();
1325
+ return markHiddenTargets(base, await getTargetsOverBrowserWs());
1151
1326
  try {
1152
1327
  const listing = await httpJson("/json/list");
1153
1328
  knownTransports.set(base, "http");
1154
- return listing;
1329
+ return markHiddenTargets(base, listing);
1155
1330
  } catch (httpError) {
1156
1331
  const detected = await detectEndpoint().catch(() => {
1157
1332
  return;
@@ -1162,7 +1337,7 @@ async function listTargets() {
1162
1337
  throw httpError;
1163
1338
  });
1164
1339
  knownTransports.set(base, "browser-ws");
1165
- return targets;
1340
+ return markHiddenTargets(base, targets);
1166
1341
  }
1167
1342
  }
1168
1343
  async function browserWsUrl() {
@@ -1275,6 +1450,7 @@ var init_client = __esm(() => {
1275
1450
  init_frames();
1276
1451
  init_endpoint();
1277
1452
  init_session();
1453
+ init_hiddenTabs();
1278
1454
  init_session();
1279
1455
  BASE = (() => {
1280
1456
  try {
@@ -1726,7 +1902,10 @@ var init_driver = __esm(() => {
1726
1902
  focus_emulation: ["emulate.focus"],
1727
1903
  click_focus_gated: ["emulate.focus"],
1728
1904
  wait_for_download: ["browser.downloads"],
1729
- grant_permissions: ["browser.permissions"]
1905
+ grant_permissions: ["browser.permissions"],
1906
+ list_tab_groups: ["browser.tabGroups"],
1907
+ group_tabs: ["browser.tabGroups"],
1908
+ ungroup_tabs: ["browser.tabGroups"]
1730
1909
  };
1731
1910
  });
1732
1911
 
@@ -2244,16 +2423,16 @@ var init_client2 = __esm(() => {
2244
2423
  });
2245
2424
 
2246
2425
  // src/bidi/session-lease.ts
2247
- import { mkdir as mkdir13, readFile as readFile9, rename as rename3, unlink as unlink5, writeFile as writeFile10 } from "node:fs/promises";
2248
- import { join as join12 } from "node:path";
2426
+ import { mkdir as mkdir14, readFile as readFile10, rename as rename3, unlink as unlink5, writeFile as writeFile11 } from "node:fs/promises";
2427
+ import { join as join13 } from "node:path";
2249
2428
  function safeEndpoint(endpoint) {
2250
2429
  return endpoint.replace(/[^A-Za-z0-9._-]/g, "_");
2251
2430
  }
2252
2431
  function sessionSlotFile(endpoint) {
2253
- return join12(leaseDir(), `ff-session-${safeEndpoint(endpoint)}.json`);
2432
+ return join13(leaseDir(), `ff-session-${safeEndpoint(endpoint)}.json`);
2254
2433
  }
2255
2434
  function muxDaemonLogFile(endpoint) {
2256
- return join12(leaseDir(), `ff-mux-${safeEndpoint(endpoint)}.log`);
2435
+ return join13(leaseDir(), `ff-mux-${safeEndpoint(endpoint)}.log`);
2257
2436
  }
2258
2437
  function sessionWaitMs() {
2259
2438
  const raw = Number(process.env.CDP_FIREFOX_SESSION_WAIT_MS);
@@ -2262,7 +2441,7 @@ function sessionWaitMs() {
2262
2441
  async function readSessionSlot(endpoint) {
2263
2442
  let raw;
2264
2443
  try {
2265
- raw = await readFile9(sessionSlotFile(endpoint), "utf8");
2444
+ raw = await readFile10(sessionSlotFile(endpoint), "utf8");
2266
2445
  } catch (err) {
2267
2446
  if (err.code === "ENOENT")
2268
2447
  return;
@@ -2291,7 +2470,7 @@ async function acquireSessionSlot(endpoint, opts) {
2291
2470
  record.marionettePort = opts.marionettePort;
2292
2471
  const handle = { endpoint, pid: process.pid, createdAt };
2293
2472
  const payload = JSON.stringify(record);
2294
- await mkdir13(leaseDir(), { recursive: true });
2473
+ await mkdir14(leaseDir(), { recursive: true });
2295
2474
  const deadline = Date.now() + waitMs;
2296
2475
  const maxAttempts = Math.max(100, Math.ceil(waitMs / pollMs) + 100);
2297
2476
  let attempts = 0;
@@ -2301,7 +2480,7 @@ async function acquireSessionSlot(endpoint, opts) {
2301
2480
  throw new SessionSlotBusyError(endpoint, lastLiveHolder);
2302
2481
  attempts++;
2303
2482
  try {
2304
- await writeFile10(file, payload, { flag: "wx" });
2483
+ await writeFile11(file, payload, { flag: "wx" });
2305
2484
  return { handle };
2306
2485
  } catch (err) {
2307
2486
  if (err.code !== "EEXIST")
@@ -2315,7 +2494,7 @@ async function acquireSessionSlot(endpoint, opts) {
2315
2494
  return;
2316
2495
  });
2317
2496
  try {
2318
- await writeFile10(file, payload, { flag: "wx" });
2497
+ await writeFile11(file, payload, { flag: "wx" });
2319
2498
  return { handle, staleHolder: holder };
2320
2499
  } catch (err) {
2321
2500
  if (err.code !== "EEXIST")
@@ -2343,7 +2522,7 @@ async function advertiseMux(handle, muxEndpoint) {
2343
2522
  const tmp = `${file}.tmp-${process.pid}`;
2344
2523
  const next = { ...current, muxEndpoint };
2345
2524
  try {
2346
- await writeFile10(tmp, JSON.stringify(next), "utf8");
2525
+ await writeFile11(tmp, JSON.stringify(next), "utf8");
2347
2526
  await rename3(tmp, file);
2348
2527
  } catch {
2349
2528
  await unlink5(tmp).catch(() => {
@@ -2389,9 +2568,9 @@ var init_session_lease = __esm(() => {
2389
2568
 
2390
2569
  // src/bidi/mux.ts
2391
2570
  import { createServer } from "node:net";
2392
- import { createHash } from "node:crypto";
2571
+ import { createHash as createHash2 } from "node:crypto";
2393
2572
  function acceptKey(key) {
2394
- return createHash("sha1").update(key + WS_GUID).digest("base64");
2573
+ return createHash2("sha1").update(key + WS_GUID).digest("base64");
2395
2574
  }
2396
2575
  function encodeFrame(opcode, payload) {
2397
2576
  const len = payload.length;
@@ -4543,6 +4722,7 @@ init_client();
4543
4722
  init_session();
4544
4723
  init_frontApp();
4545
4724
  init_leases();
4725
+ init_hiddenTabs();
4546
4726
  init_endpoints();
4547
4727
  init_activity();
4548
4728
 
@@ -5053,6 +5233,7 @@ var CDP_CAPABILITIES = new Set([
5053
5233
  "emulate.focus",
5054
5234
  "browser.downloads",
5055
5235
  "browser.permissions",
5236
+ "browser.tabGroups",
5056
5237
  "worker.targets",
5057
5238
  "frame.targets"
5058
5239
  ]);
@@ -5743,8 +5924,10 @@ async function createSettledTarget(conn, url, settleMs = NEW_TARGET_SETTLE_MS, o
5743
5924
  await conn.send("Target.setDiscoverTargets", { discover: true }).catch(() => {
5744
5925
  return;
5745
5926
  });
5746
- const create = () => conn.send("Target.createTarget", { url, background: opts.focus !== true });
5747
- const { targetId } = opts.focus === true ? await create() : await keepFrontApp(create);
5927
+ const hidden = opts.hidden === true;
5928
+ const params = hidden ? { url, background: true, hidden: true } : { url, background: opts.focus !== true };
5929
+ const create = () => conn.send("Target.createTarget", params);
5930
+ const { targetId } = opts.focus === true || hidden ? await create() : await keepFrontApp(create);
5748
5931
  if (!targetId)
5749
5932
  throw driverError("page-error", "Target.createTarget returned no targetId");
5750
5933
  id = targetId;
@@ -5762,6 +5945,19 @@ async function createSettledTarget(conn, url, settleMs = NEW_TARGET_SETTLE_MS, o
5762
5945
  off();
5763
5946
  }
5764
5947
  }
5948
+ function hiddenTabsEnabled() {
5949
+ return hiddenTabsRequested() && isLongLivedProcess();
5950
+ }
5951
+ function currentHiddenOwner() {
5952
+ return hiddenTabOwner(currentEndpoint().base, () => ({
5953
+ connect: () => openBrowser(),
5954
+ createSettled: (conn, url, opts) => createSettledTarget(conn, url, NEW_TARGET_SETTLE_MS, opts)
5955
+ }));
5956
+ }
5957
+ function hiddenOwnerOf(id) {
5958
+ const owner = existingHiddenTabOwner(currentEndpoint().base);
5959
+ return owner?.has(id) ? owner : undefined;
5960
+ }
5765
5961
 
5766
5962
  class CdpBrowserDriver {
5767
5963
  scheme = "cdp";
@@ -5772,15 +5968,26 @@ class CdpBrowserDriver {
5772
5968
  async listPages(opts) {
5773
5969
  const targets = await listTargets();
5774
5970
  const filtered = opts?.all ? targets : targets.filter((t) => t.type === "page");
5775
- return filtered.map((t) => ({ id: t.id, url: t.url, title: t.title, type: t.type }));
5971
+ return filtered.map((t) => ({ id: t.id, url: t.url, title: t.title, type: t.type, ...t.hidden ? { hidden: true } : {} }));
5776
5972
  }
5777
5973
  async newPage(url, opts) {
5974
+ if (opts?.focus !== true && hiddenTabsEnabled()) {
5975
+ const id = await currentHiddenOwner().create(url ?? "about:blank");
5976
+ return { id, url: url ?? "about:blank", title: "", hidden: true };
5977
+ }
5778
5978
  return withBrowserConn(async (conn) => {
5779
5979
  const targetId = await createSettledTarget(conn, url ?? "about:blank", NEW_TARGET_SETTLE_MS, { focus: opts?.focus === true });
5780
5980
  return { id: targetId, url: url ?? "about:blank", title: "" };
5781
5981
  });
5782
5982
  }
5783
5983
  async closePage(id) {
5984
+ const owner = hiddenOwnerOf(id);
5985
+ if (owner) {
5986
+ const res = await owner.close(id);
5987
+ if (res.success)
5988
+ beaconSessions.drop(beaconKey(id));
5989
+ return res;
5990
+ }
5784
5991
  return withBrowserConn(async (conn) => {
5785
5992
  const res = await keepFrontApp(() => conn.send("Target.closeTarget", { targetId: id }));
5786
5993
  if (res.success !== false)
@@ -5790,6 +5997,16 @@ class CdpBrowserDriver {
5790
5997
  }
5791
5998
  async activatePage(id) {
5792
5999
  const target = await resolveTarget(id).catch(noSuchTarget);
6000
+ const owner = hiddenOwnerOf(target.id);
6001
+ if (owner) {
6002
+ const url = target.url || "about:blank";
6003
+ const newId = await withBrowserConn((conn) => createSettledTarget(conn, url, NEW_TARGET_SETTLE_MS, { focus: true }));
6004
+ await owner.close(target.id).catch(() => {
6005
+ return;
6006
+ });
6007
+ beaconSessions.drop(beaconKey(target.id));
6008
+ return { id: newId, url, title: target.title, revealedFrom: target.id };
6009
+ }
5793
6010
  await withBrowserConn((conn) => conn.send("Target.activateTarget", { targetId: target.id }));
5794
6011
  return { id: target.id, url: target.url, title: target.title };
5795
6012
  }
@@ -5863,6 +6080,7 @@ class CdpBrowserDriver {
5863
6080
  }
5864
6081
  async dispose() {
5865
6082
  beaconSessions.clear();
6083
+ await disposeHiddenTabs();
5866
6084
  }
5867
6085
  }
5868
6086
  function createCdpDriver() {
@@ -5928,6 +6146,7 @@ async function reapStaleAgentTabs(driver, backend) {
5928
6146
  }
5929
6147
 
5930
6148
  // src/shared-tools.ts
6149
+ init_focusPolicy();
5931
6150
  init_driver();
5932
6151
  import { mkdir as mkdir5, writeFile as writeFile4 } from "node:fs/promises";
5933
6152
  import { dirname as dirname2, join as join5 } from "node:path";
@@ -6611,16 +6830,20 @@ async function listPagesOne(driver, args = {}) {
6611
6830
  async function newPage(driver, args = {}) {
6612
6831
  const label = typeof args.label === "string" && args.label.length ? args.label : defaultLabel();
6613
6832
  const p = await newTrackedPage(driver, backendOf(driver), { url: args.url, label, focus: args.focus === true });
6833
+ const hidden = {
6834
+ ...p.hidden === true ? { hidden: true } : {},
6835
+ ...args.focus === true && focusDenied() ? { focusDenied: true } : {}
6836
+ };
6614
6837
  const explicit = args.claim === true;
6615
6838
  if (!explicit && !requireLease())
6616
- return { targetId: p.id, url: p.url };
6839
+ return { targetId: p.id, url: p.url, ...hidden };
6617
6840
  const { record, token } = await claimLease(backendOf(driver), p.id, {
6618
6841
  label,
6619
6842
  ttlMs: typeof args.ttlMs === "number" && args.ttlMs > 0 ? args.ttlMs : leaseTtlMs(),
6620
6843
  auto: !explicit
6621
6844
  });
6622
6845
  await installBeacon(driver, p.id);
6623
- return { targetId: p.id, url: p.url, lease: token, label: record.label, expiresAt: record.lastUsedAt + record.ttlMs };
6846
+ return { targetId: p.id, url: p.url, ...hidden, lease: token, label: record.label, expiresAt: record.lastUsedAt + record.ttlMs };
6624
6847
  }
6625
6848
  async function closePage(driver, args) {
6626
6849
  if (args.target === undefined || args.target === "")
@@ -6641,9 +6864,33 @@ async function selectPage(driver, args) {
6641
6864
  if (args.target === undefined || args.target === "")
6642
6865
  throw new SharedToolError("select_page requires an explicit target");
6643
6866
  const p = await resolvePage(driver, args.target);
6644
- const id = args.focus === true ? (await driver.activatePage(p.id)).id : p.id;
6645
- await writeSelectedFile(id);
6646
- return { selected: id, focused: args.focus === true };
6867
+ if (args.focus !== true || focusDenied()) {
6868
+ await writeSelectedFile(p.id);
6869
+ return { selected: p.id, focused: false, ...args.focus === true ? { focusDenied: true } : {} };
6870
+ }
6871
+ const shown = await driver.activatePage(p.id);
6872
+ if (shown.revealedFrom === undefined || shown.id === p.id) {
6873
+ await writeSelectedFile(shown.id);
6874
+ return { selected: shown.id, focused: true };
6875
+ }
6876
+ const moved = await moveRevealedTab(backendOf(driver), shown.revealedFrom, shown.id);
6877
+ await writeSelectedFile(shown.id);
6878
+ return { selected: shown.id, focused: true, revealedFrom: shown.revealedFrom, ...moved.lease ? { lease: moved.lease } : {} };
6879
+ }
6880
+ async function moveRevealedTab(backend, fromId, toId) {
6881
+ const origin = await readOrigin(backend, fromId).catch(() => {
6882
+ return;
6883
+ });
6884
+ if (origin)
6885
+ await recordOrigin(backend, toId, { label: origin.label, now: origin.createdAt });
6886
+ const lease = await readLease(backend, fromId).catch(() => {
6887
+ return;
6888
+ });
6889
+ if (!lease)
6890
+ return {};
6891
+ await releaseLeaseFor(backend, fromId);
6892
+ const { token } = await claimLease(backend, toId, { label: lease.label, ttlMs: lease.ttlMs, auto: lease.auto === true });
6893
+ return { lease: token };
6647
6894
  }
6648
6895
  function toLegacyWaitedFor(w) {
6649
6896
  if (w === "committed")
@@ -7054,7 +7301,7 @@ async function pressKey(driver, args) {
7054
7301
  pressed: args.key,
7055
7302
  modifiers,
7056
7303
  delivered: false,
7057
- note: "the page saw no keydown: a background tab gets no trusted keyboard input. A click on the tab's page (click tool) usually gives it focus so keys land; or open the tab with new_page focus:true. A key handled inside a cross-origin iframe also reads as not delivered."
7304
+ note: "the page saw no keydown: a background tab gets no trusted keyboard input. A click on the tab's page (click tool) usually gives it focus so keys land; or open the tab with new_page focus:true (which raises the browser over the user's work; refused under CDP_DENY_FOCUS). A key handled inside a cross-origin iframe also reads as not delivered."
7058
7305
  };
7059
7306
  }
7060
7307
  return { pressed: args.key, modifiers };
@@ -7309,6 +7556,7 @@ async function claimPage(driver, args = {}) {
7309
7556
  let targetId;
7310
7557
  let url;
7311
7558
  let opened;
7559
+ let hidden = false;
7312
7560
  if (hasTarget) {
7313
7561
  const hit = await pickPage(driver, pages, args.target).catch((err) => {
7314
7562
  throw new LeaseToolError(`claim_page: no open tab matches target '${args.target}' (${err.message}). No tab was opened: claim_page never creates one when 'target' is given.`);
@@ -7328,6 +7576,7 @@ async function claimPage(driver, args = {}) {
7328
7576
  targetId = page.id;
7329
7577
  url = page.url;
7330
7578
  opened = true;
7579
+ hidden = page.hidden === true;
7331
7580
  }
7332
7581
  const humanMs = opened ? null : await readHumanActiveMs(driver, backend, targetId);
7333
7582
  const liveIds = [...pages.map((p) => p.id), targetId];
@@ -7346,6 +7595,7 @@ async function claimPage(driver, args = {}) {
7346
7595
  ttlMs: record.ttlMs,
7347
7596
  expiresAt: record.lastUsedAt + record.ttlMs,
7348
7597
  opened,
7598
+ ...hidden ? { hidden: true } : {},
7349
7599
  ...beaconSupported(driver) ? { humanActiveMs: humanMs } : {},
7350
7600
  ...contention !== undefined ? { contention } : {}
7351
7601
  };
@@ -8053,6 +8303,7 @@ async function performanceAnalyzeInsight(args = {}) {
8053
8303
  }
8054
8304
 
8055
8305
  // src/tools/screencast.ts
8306
+ init_focusPolicy();
8056
8307
  init_client();
8057
8308
  import { spawn } from "node:child_process";
8058
8309
  import { mkdir as mkdir8, rm as rm2, stat as stat2, writeFile as writeFile7 } from "node:fs/promises";
@@ -8353,7 +8604,7 @@ async function startScreenRecording(args = {}) {
8353
8604
  });
8354
8605
  try {
8355
8606
  await conn.send("Page.enable");
8356
- if (args.bringToFront)
8607
+ if (args.bringToFront && !focusDenied())
8357
8608
  await conn.send("Page.bringToFront").catch(() => {});
8358
8609
  const params = { format };
8359
8610
  if (format === "jpeg" && args.quality !== undefined)
@@ -8999,11 +9250,302 @@ async function grantPermissions(args = {}) {
8999
9250
  return { granted: [...permissions], origin, ...reset ? { reset: true } : {}, target };
9000
9251
  }
9001
9252
 
9002
- // src/tools/extract.ts
9253
+ // src/tools/tab-groups.ts
9003
9254
  init_client();
9004
- import { mkdir as mkdir12, writeFile as writeFile9 } from "node:fs/promises";
9005
- import { dirname as dirname3, join as join11 } from "node:path";
9255
+ import { createHash } from "node:crypto";
9256
+ import { mkdir as mkdir12, readFile as readFile9, writeFile as writeFile9 } from "node:fs/promises";
9257
+ import { join as join11 } from "node:path";
9006
9258
  var ARTIFACT_DIR7 = process.env.CDP_ARTIFACT_DIR ?? "/tmp/cdp-toolkit";
9259
+ var HELPER_DIR = join11(ARTIFACT_DIR7, "tab-groups-helper");
9260
+ var TAB_GROUP_COLORS = ["grey", "blue", "red", "yellow", "green", "pink", "purple", "cyan", "orange"];
9261
+ var HELPER_KEY = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqesYyi7LmBxzWP7VFJGlH2khinCz0uU2z3KNDvZ3Kb8gTLPpthgRWp27pu5/Wk2nvQJdcrunf6u5vqomH2xhvXIqjgXtth2o1GrE6oJMWRUqEoC7I4YUXdSieRpxAxtG37KiSFOyFOU59Som3gGOM2j1qlQIsID0QwRCeRs095SLoTtkA6YwZxtOETgvZAhbbpkmYwkXjTzgY85sS1JfMYj67cmfyz/Nt6yfORSJYEmWAfGCjQnvtOn9TjCazZvmoASUhsKZNZVWckAg+Md+ZKBPbl14/UUwLmWHQ7SDcJozHZtFeLFXySwvmBm3NhP1rK5vd/v+modsQY3M3DbqLQIDAQAB";
9262
+ var HELPER_MANIFEST = {
9263
+ manifest_version: 3,
9264
+ name: "cdp-toolkit tab groups",
9265
+ description: "Helper installed by cdp-toolkit's tab-group tools (list_tab_groups, group_tabs, ungroup_tabs). No UI, no state.",
9266
+ version: "1.0.0",
9267
+ key: HELPER_KEY,
9268
+ permissions: ["tabs", "tabGroups", "debugger"],
9269
+ background: { service_worker: "sw.js" }
9270
+ };
9271
+ function extensionIdFromKey(keyBase64) {
9272
+ const hex = createHash("sha256").update(Buffer.from(keyBase64, "base64")).digest("hex").slice(0, 32);
9273
+ return [...hex].map((c) => String.fromCharCode(97 + parseInt(c, 16))).join("");
9274
+ }
9275
+ var HELPER_EXTENSION_ID = extensionIdFromKey(HELPER_KEY);
9276
+ var HELPER_SW_BODY = String.raw`
9277
+ const NONE = -1;
9278
+
9279
+ async function targetIdsByTab() {
9280
+ const m = new Map();
9281
+ try {
9282
+ for (const t of await chrome.debugger.getTargets()) {
9283
+ if (t.type === "page" && typeof t.tabId === "number") m.set(t.tabId, t.id);
9284
+ }
9285
+ } catch (e) {
9286
+ // No mapping is a degraded answer (rows lack targetId), not a failure of the listing.
9287
+ }
9288
+ return m;
9289
+ }
9290
+
9291
+ function row(t, m) {
9292
+ return { tabId: t.id, targetId: m.get(t.id), index: t.index, url: t.url || t.pendingUrl || "", title: t.title || "" };
9293
+ }
9294
+
9295
+ const byPlace = (a, b) => a.windowId - b.windowId || a.index - b.index;
9296
+
9297
+ async function list(args) {
9298
+ const q = args && args.windowId !== undefined ? { windowId: args.windowId } : {};
9299
+ const [tabs, groups, m] = await Promise.all([chrome.tabs.query(q), chrome.tabGroups.query(q), targetIdsByTab()]);
9300
+ const wins = new Map();
9301
+ for (const t of tabs.slice().sort(byPlace)) {
9302
+ let w = wins.get(t.windowId);
9303
+ if (!w) wins.set(t.windowId, (w = { windowId: t.windowId, tabCount: 0, ungrouped: 0, groups: [] }));
9304
+ w.tabCount++;
9305
+ if (t.groupId === NONE || t.groupId === undefined) {
9306
+ w.ungrouped++;
9307
+ if (args && args.includeUngrouped) (w.ungroupedTabs || (w.ungroupedTabs = [])).push(row(t, m));
9308
+ continue;
9309
+ }
9310
+ let g = w.groups.find((x) => x.groupId === t.groupId);
9311
+ if (!g) {
9312
+ const info = groups.find((x) => x.id === t.groupId) || {};
9313
+ g = { groupId: t.groupId, title: info.title || "", color: info.color, collapsed: !!info.collapsed, tabs: [] };
9314
+ w.groups.push(g);
9315
+ }
9316
+ g.tabs.push(row(t, m));
9317
+ }
9318
+ const windows = [...wins.values()];
9319
+ return {
9320
+ windows,
9321
+ groupCount: windows.reduce((n, w) => n + w.groups.length, 0),
9322
+ tabCount: tabs.length,
9323
+ };
9324
+ }
9325
+
9326
+ async function selectTabs(args, m) {
9327
+ if (Array.isArray(args.tabIds)) {
9328
+ const out = [];
9329
+ for (const id of args.tabIds) {
9330
+ try { out.push(await chrome.tabs.get(id)); }
9331
+ catch (e) { throw new Error("no tab with tabId " + id + " (tab ids come from list_tab_groups)"); }
9332
+ }
9333
+ return out;
9334
+ }
9335
+ if (Array.isArray(args.targetIds)) {
9336
+ const byTarget = new Map([...m].map(([tabId, targetId]) => [targetId, tabId]));
9337
+ const out = [];
9338
+ for (const tid of args.targetIds) {
9339
+ const id = byTarget.get(tid);
9340
+ if (id === undefined) throw new Error("no tab with targetId " + tid + " (a page's CDP target id, as list_pages shows it)");
9341
+ out.push(await chrome.tabs.get(id));
9342
+ }
9343
+ return out;
9344
+ }
9345
+ const all = (await chrome.tabs.query({})).sort(byPlace);
9346
+ if (typeof args.urlMatch === "string") {
9347
+ const hit = all.filter((t) => (t.url || "").includes(args.urlMatch) || (t.pendingUrl || "").includes(args.urlMatch));
9348
+ if (!hit.length) throw new Error("urlMatch " + JSON.stringify(args.urlMatch) + " matched no tab");
9349
+ return hit;
9350
+ }
9351
+ if (typeof args.groupId === "number") {
9352
+ await chrome.tabGroups.get(args.groupId).catch(() => { throw new Error("no tab group with groupId " + args.groupId); });
9353
+ return all.filter((t) => t.groupId === args.groupId);
9354
+ }
9355
+ throw new Error("no tab selector given");
9356
+ }
9357
+
9358
+ async function group(args) {
9359
+ const m = await targetIdsByTab();
9360
+ const tabs = await selectTabs(args, m);
9361
+ let win;
9362
+ if (args.groupId !== undefined) {
9363
+ win = (await chrome.tabGroups.get(args.groupId).catch(() => { throw new Error("no tab group with groupId " + args.groupId); })).windowId;
9364
+ } else if (args.windowId !== undefined) {
9365
+ win = args.windowId;
9366
+ } else {
9367
+ const ws = [...new Set(tabs.map((t) => t.windowId))];
9368
+ if (ws.length > 1) {
9369
+ throw new Error(
9370
+ "the selected tabs are in " + ws.length + " windows (" + ws.join(", ") + "); pass windowId to name the window the group goes in " +
9371
+ "(tabs from other windows are moved there). Without it Chrome would move them all into the last-focused window.",
9372
+ );
9373
+ }
9374
+ win = ws[0];
9375
+ }
9376
+ const moved = tabs.filter((t) => t.windowId !== win).map((t) => ({ tabId: t.id, fromWindowId: t.windowId }));
9377
+ const opts = { tabIds: tabs.map((t) => t.id) };
9378
+ if (args.groupId !== undefined) opts.groupId = args.groupId;
9379
+ else opts.createProperties = { windowId: win };
9380
+ const gid = await chrome.tabs.group(opts);
9381
+ const upd = {};
9382
+ if (args.title !== undefined) upd.title = args.title;
9383
+ if (args.color !== undefined) upd.color = args.color;
9384
+ if (args.collapsed !== undefined) upd.collapsed = args.collapsed;
9385
+ const g = Object.keys(upd).length ? await chrome.tabGroups.update(gid, upd) : await chrome.tabGroups.get(gid);
9386
+ const members = g.windowId > 0 ? (await chrome.tabs.query({ windowId: g.windowId })).filter((t) => t.groupId === gid).sort(byPlace) : [];
9387
+ if (members.length === 0) {
9388
+ // Vivaldi answers chrome.tabs.group with an id but keeps its own tab stacks: the "group" has
9389
+ // windowId -1 and no tabs. Fail loudly rather than report a group that does not exist.
9390
+ throw new Error("the browser accepted chrome.tabs.group but created no visible group (windowId " + g.windowId + ", 0 tabs); this browser does not support Chrome tab groups (Vivaldi uses its own tab stacks)");
9391
+ }
9392
+ return { groupId: gid, windowId: g.windowId, title: g.title || "", color: g.color, collapsed: !!g.collapsed, tabs: members.map((t) => row(t, m)), moved };
9393
+ }
9394
+
9395
+ async function ungroup(args) {
9396
+ const m = await targetIdsByTab();
9397
+ const tabs = await selectTabs(args, m);
9398
+ const grouped = tabs.filter((t) => t.groupId !== NONE && t.groupId !== undefined);
9399
+ if (grouped.length) await chrome.tabs.ungroup(grouped.map((t) => t.id));
9400
+ return {
9401
+ ungrouped: grouped.map((t) => Object.assign(row(t, m), { fromGroupId: t.groupId })),
9402
+ alreadyUngrouped: tabs.filter((t) => !grouped.includes(t)).map((t) => t.id),
9403
+ };
9404
+ }
9405
+
9406
+ self.cdpToolkitTabGroups = { version: VERSION, list, group, ungroup };
9407
+ `;
9408
+ var HELPER_VERSION = createHash("sha256").update(HELPER_SW_BODY).digest("hex").slice(0, 12);
9409
+ var HELPER_SW_SOURCE = `"use strict";
9410
+ const VERSION = ${JSON.stringify(HELPER_VERSION)};
9411
+ ${HELPER_SW_BODY}`;
9412
+ var isInt = (v) => typeof v === "number" && Number.isInteger(v);
9413
+ function checkInt(tool, name, v) {
9414
+ if (v !== undefined && !isInt(v))
9415
+ throw new Error(`${tool}: '${name}' must be an integer (got ${JSON.stringify(v)})`);
9416
+ }
9417
+ function checkSelector(tool, a, withGroupId) {
9418
+ const given = [
9419
+ a.tabIds !== undefined && "tabIds",
9420
+ a.targetIds !== undefined && "targetIds",
9421
+ typeof a.urlMatch === "string" && a.urlMatch !== "" && "urlMatch",
9422
+ withGroupId && a.groupId !== undefined && "groupId"
9423
+ ].filter(Boolean);
9424
+ const names = withGroupId ? "tabIds, targetIds, urlMatch or groupId" : "tabIds, targetIds or urlMatch";
9425
+ if (given.length !== 1)
9426
+ throw new Error(`${tool}: give exactly one of ${names} (got ${given.length ? given.join(" + ") : "none"})`);
9427
+ if (a.tabIds !== undefined) {
9428
+ if (!Array.isArray(a.tabIds) || a.tabIds.length === 0 || !a.tabIds.every(isInt)) {
9429
+ throw new Error(`${tool}: 'tabIds' must be a non-empty array of integer chrome tab ids (got ${JSON.stringify(a.tabIds)})`);
9430
+ }
9431
+ }
9432
+ if (a.targetIds !== undefined) {
9433
+ if (!Array.isArray(a.targetIds) || a.targetIds.length === 0 || !a.targetIds.every((t) => typeof t === "string" && t !== "")) {
9434
+ throw new Error(`${tool}: 'targetIds' must be a non-empty array of CDP target id strings (got ${JSON.stringify(a.targetIds)})`);
9435
+ }
9436
+ }
9437
+ }
9438
+ function validateListTabGroupsArgs(a) {
9439
+ checkInt("list_tab_groups", "windowId", a.windowId);
9440
+ if (a.includeUngrouped !== undefined && typeof a.includeUngrouped !== "boolean") {
9441
+ throw new Error("list_tab_groups: 'includeUngrouped' must be a boolean");
9442
+ }
9443
+ }
9444
+ function validateGroupTabsArgs(a) {
9445
+ const tool = "group_tabs";
9446
+ checkSelector(tool, a, false);
9447
+ checkInt(tool, "groupId", a.groupId);
9448
+ checkInt(tool, "windowId", a.windowId);
9449
+ if (a.groupId !== undefined && a.windowId !== undefined) {
9450
+ throw new Error(`${tool}: give groupId (add to that group, in its window) or windowId (new group in that window), not both`);
9451
+ }
9452
+ if (a.title !== undefined && typeof a.title !== "string")
9453
+ throw new Error(`${tool}: 'title' must be a string`);
9454
+ if (a.collapsed !== undefined && typeof a.collapsed !== "boolean")
9455
+ throw new Error(`${tool}: 'collapsed' must be a boolean`);
9456
+ if (a.color !== undefined && !TAB_GROUP_COLORS.includes(a.color)) {
9457
+ throw new Error(`${tool}: 'color' must be one of ${TAB_GROUP_COLORS.join(", ")} (got ${JSON.stringify(a.color)})`);
9458
+ }
9459
+ }
9460
+ function validateUngroupTabsArgs(a) {
9461
+ checkSelector("ungroup_tabs", a, true);
9462
+ checkInt("ungroup_tabs", "groupId", a.groupId);
9463
+ }
9464
+ var SW_URL_PREFIX = `chrome-extension://${HELPER_EXTENSION_ID}/`;
9465
+ var WORKER_WAIT_MS = 5000;
9466
+ async function helperWorker() {
9467
+ return (await listTargets()).find((t) => t.type === "service_worker" && t.url.startsWith(SW_URL_PREFIX));
9468
+ }
9469
+ async function writeHelper() {
9470
+ await mkdir12(HELPER_DIR, { recursive: true });
9471
+ const files = {
9472
+ "manifest.json": JSON.stringify(HELPER_MANIFEST, null, 2),
9473
+ "sw.js": HELPER_SW_SOURCE
9474
+ };
9475
+ for (const [name, body] of Object.entries(files)) {
9476
+ const path = join11(HELPER_DIR, name);
9477
+ const current = await readFile9(path, "utf8").catch(() => {
9478
+ return;
9479
+ });
9480
+ if (current !== body)
9481
+ await writeFile9(path, body);
9482
+ }
9483
+ }
9484
+ async function evalIn(workerId, expression) {
9485
+ return withPage(workerId, async (conn) => {
9486
+ const r = await conn.send("Runtime.evaluate", { expression, awaitPromise: true, returnByValue: true });
9487
+ if (r.exceptionDetails) {
9488
+ const d = r.exceptionDetails.exception?.description ?? r.exceptionDetails.text ?? "error";
9489
+ throw new Error(d.split(`
9490
+ `)[0].replace(/^Error: /, ""));
9491
+ }
9492
+ return r.result?.value;
9493
+ });
9494
+ }
9495
+ async function currentHelperWorker() {
9496
+ const w = await helperWorker();
9497
+ if (!w)
9498
+ return;
9499
+ const v = await evalIn(w.id, "self.cdpToolkitTabGroups && self.cdpToolkitTabGroups.version").catch(() => {
9500
+ return;
9501
+ });
9502
+ return v === HELPER_VERSION ? w.id : undefined;
9503
+ }
9504
+ async function ensureHelper() {
9505
+ const existing = await currentHelperWorker();
9506
+ if (existing)
9507
+ return existing;
9508
+ await writeHelper();
9509
+ const conn = await openBrowser();
9510
+ try {
9511
+ await conn.send("Extensions.loadUnpacked", { path: HELPER_DIR });
9512
+ } catch (e) {
9513
+ const msg = e instanceof Error ? e.message : String(e);
9514
+ throw new CdpError(`tab-group tools could not install their helper extension (Extensions.loadUnpacked: ${msg}). ` + `They need a Chromium that allows loadUnpacked over CDP, with ${HELPER_DIR} on the browser's own machine.`);
9515
+ } finally {
9516
+ conn.close();
9517
+ }
9518
+ const deadline = Date.now() + WORKER_WAIT_MS;
9519
+ while (Date.now() < deadline) {
9520
+ const id = await currentHelperWorker();
9521
+ if (id)
9522
+ return id;
9523
+ await new Promise((r) => setTimeout(r, 100));
9524
+ }
9525
+ throw new CdpError(`the tab-groups helper extension installed but its service worker did not start within ${WORKER_WAIT_MS} ms`);
9526
+ }
9527
+ async function callHelper(op, args) {
9528
+ const id = await ensureHelper();
9529
+ return await evalIn(id, `self.cdpToolkitTabGroups.${op}(${JSON.stringify(args)})`);
9530
+ }
9531
+ async function listTabGroups(args = {}) {
9532
+ validateListTabGroupsArgs(args);
9533
+ return callHelper("list", { windowId: args.windowId, includeUngrouped: args.includeUngrouped });
9534
+ }
9535
+ async function groupTabs(args = {}) {
9536
+ validateGroupTabsArgs(args);
9537
+ return callHelper("group", args);
9538
+ }
9539
+ async function ungroupTabs(args = {}) {
9540
+ validateUngroupTabsArgs(args);
9541
+ return callHelper("ungroup", args);
9542
+ }
9543
+
9544
+ // src/tools/extract.ts
9545
+ init_client();
9546
+ import { mkdir as mkdir13, writeFile as writeFile10 } from "node:fs/promises";
9547
+ import { dirname as dirname3, join as join12 } from "node:path";
9548
+ var ARTIFACT_DIR8 = process.env.CDP_ARTIFACT_DIR ?? "/tmp/cdp-toolkit";
9007
9549
  var DEFAULT_BASE_URL = "http://127.0.0.1:8090/v1";
9008
9550
  var DEFAULT_MODEL = "schematron";
9009
9551
  var DEFAULT_TIMEOUT_MS2 = 90000;
@@ -9403,10 +9945,10 @@ async function extractPage(driver, args) {
9403
9945
  };
9404
9946
  if (args.savePath === undefined || args.savePath === "")
9405
9947
  return result;
9406
- const path = args.savePath.startsWith("/") ? args.savePath : join11(ARTIFACT_DIR7, args.savePath);
9407
- await mkdir12(dirname3(path), { recursive: true });
9948
+ const path = args.savePath.startsWith("/") ? args.savePath : join12(ARTIFACT_DIR8, args.savePath);
9949
+ await mkdir13(dirname3(path), { recursive: true });
9408
9950
  const json = JSON.stringify(result, null, 2);
9409
- await writeFile9(path, json, "utf8");
9951
+ await writeFile10(path, json, "utf8");
9410
9952
  const saved = {
9411
9953
  path,
9412
9954
  bytes: Buffer.byteLength(json, "utf8"),
@@ -9469,6 +10011,9 @@ var TOOLS = {
9469
10011
  click_focus_gated: clickFocusGated,
9470
10012
  wait_for_download: waitForDownload,
9471
10013
  grant_permissions: grantPermissions,
10014
+ list_tab_groups: listTabGroups,
10015
+ group_tabs: groupTabs,
10016
+ ungroup_tabs: ungroupTabs,
9472
10017
  extract_page: onCdp(extractPage),
9473
10018
  claim_page: onCdp(LEASE_TOOLS.claim_page),
9474
10019
  release_page: onCdp(LEASE_TOOLS.release_page),
@@ -10274,6 +10819,130 @@ var MANIFEST = [
10274
10819
  additionalProperties: false
10275
10820
  }
10276
10821
  },
10822
+ {
10823
+ name: "list_tab_groups",
10824
+ description: "List tab groups per window with member tabs (Chrome only, via a helper extension).",
10825
+ inputSchema: {
10826
+ type: "object",
10827
+ properties: {
10828
+ endpoint: {
10829
+ type: "string",
10830
+ description: "Named CDP endpoint (CDP_ENDPOINTS); default endpoint when omitted."
10831
+ },
10832
+ windowId: {
10833
+ type: "integer",
10834
+ description: "Only this window."
10835
+ },
10836
+ includeUngrouped: {
10837
+ type: "boolean",
10838
+ description: "Also list ungrouped tabs per window."
10839
+ }
10840
+ },
10841
+ required: [],
10842
+ additionalProperties: false
10843
+ }
10844
+ },
10845
+ {
10846
+ name: "group_tabs",
10847
+ description: "Group tabs (new or existing group) and set title/color/collapsed (Chrome only).",
10848
+ inputSchema: {
10849
+ type: "object",
10850
+ properties: {
10851
+ endpoint: {
10852
+ type: "string",
10853
+ description: "Named CDP endpoint (CDP_ENDPOINTS); default endpoint when omitted."
10854
+ },
10855
+ tabIds: {
10856
+ type: "array",
10857
+ items: {
10858
+ type: "integer"
10859
+ },
10860
+ description: "Chrome tab ids (from list_tab_groups)."
10861
+ },
10862
+ targetIds: {
10863
+ type: "array",
10864
+ items: {
10865
+ type: "string"
10866
+ },
10867
+ description: "CDP target ids (list_pages ids)."
10868
+ },
10869
+ urlMatch: {
10870
+ type: "string",
10871
+ description: "URL substring; matches tabs in every window."
10872
+ },
10873
+ title: {
10874
+ type: "string",
10875
+ description: "Group title."
10876
+ },
10877
+ color: {
10878
+ type: "string",
10879
+ enum: [
10880
+ "grey",
10881
+ "blue",
10882
+ "red",
10883
+ "yellow",
10884
+ "green",
10885
+ "pink",
10886
+ "purple",
10887
+ "cyan",
10888
+ "orange"
10889
+ ],
10890
+ description: "Group color."
10891
+ },
10892
+ collapsed: {
10893
+ type: "boolean",
10894
+ description: "Collapse the group."
10895
+ },
10896
+ groupId: {
10897
+ type: "integer",
10898
+ description: "Add to this existing group."
10899
+ },
10900
+ windowId: {
10901
+ type: "integer",
10902
+ description: "Window for the new group; tabs elsewhere move there."
10903
+ }
10904
+ },
10905
+ required: [],
10906
+ additionalProperties: false
10907
+ }
10908
+ },
10909
+ {
10910
+ name: "ungroup_tabs",
10911
+ description: "Remove tabs from their tab groups (Chrome only).",
10912
+ inputSchema: {
10913
+ type: "object",
10914
+ properties: {
10915
+ endpoint: {
10916
+ type: "string",
10917
+ description: "Named CDP endpoint (CDP_ENDPOINTS); default endpoint when omitted."
10918
+ },
10919
+ tabIds: {
10920
+ type: "array",
10921
+ items: {
10922
+ type: "integer"
10923
+ },
10924
+ description: "Chrome tab ids (from list_tab_groups)."
10925
+ },
10926
+ targetIds: {
10927
+ type: "array",
10928
+ items: {
10929
+ type: "string"
10930
+ },
10931
+ description: "CDP target ids (list_pages ids)."
10932
+ },
10933
+ urlMatch: {
10934
+ type: "string",
10935
+ description: "URL substring; matches tabs in every window."
10936
+ },
10937
+ groupId: {
10938
+ type: "integer",
10939
+ description: "Ungroup every tab of this group."
10940
+ }
10941
+ },
10942
+ required: [],
10943
+ additionalProperties: false
10944
+ }
10945
+ },
10277
10946
  {
10278
10947
  name: "fill",
10279
10948
  description: "Replace an element contents; provide exactly one of UID or selector.",
@@ -11327,7 +11996,7 @@ import { spawn as spawn4 } from "node:child_process";
11327
11996
  import { existsSync as existsSync2, mkdtempSync, readFileSync as readFileSync2, rmSync, writeFileSync } from "node:fs";
11328
11997
  import { createConnection, createServer as createServer2 } from "node:net";
11329
11998
  import { tmpdir } from "node:os";
11330
- import { join as join13 } from "node:path";
11999
+ import { join as join14 } from "node:path";
11331
12000
  function resolveBinary() {
11332
12001
  const candidates = [
11333
12002
  process.env.FIREFOX_BIN,
@@ -11407,7 +12076,7 @@ var LAUNCH_USER_JS_PREFS = {
11407
12076
  "dom.file.createInChild": true
11408
12077
  };
11409
12078
  function writeLaunchUserJs(profilePath) {
11410
- const target = join13(profilePath, "user.js");
12079
+ const target = join14(profilePath, "user.js");
11411
12080
  const existing = existsSync2(target) ? readFileSync2(target, "utf8") : "";
11412
12081
  const present = new Set;
11413
12082
  for (const line of existing.split(`
@@ -11429,7 +12098,7 @@ async function launchFirefox(opts = {}) {
11429
12098
  const binary = resolveBinary();
11430
12099
  const port = await pickPort(opts.port);
11431
12100
  const isThrowaway = opts.profilePath === undefined;
11432
- const profilePath = opts.profilePath ?? mkdtempSync(join13(tmpdir(), "cdp-toolkit-ff-profile-"));
12101
+ const profilePath = opts.profilePath ?? mkdtempSync(join14(tmpdir(), "cdp-toolkit-ff-profile-"));
11433
12102
  if (isThrowaway)
11434
12103
  writeLaunchUserJs(profilePath);
11435
12104
  const args = ["--profile", profilePath, "--remote-debugging-port", String(port), "--no-remote"];
@@ -11594,6 +12263,9 @@ async function disposeFirefoxSession() {
11594
12263
  });
11595
12264
  }
11596
12265
 
12266
+ // src/mcp.ts
12267
+ init_hiddenTabs();
12268
+
11597
12269
  // src/capabilities.ts
11598
12270
  init_driver2();
11599
12271
  init_driver();
@@ -11799,8 +12471,8 @@ var BIDI_ONLY_TOOLS = {
11799
12471
 
11800
12472
  // src/bidi-browser-tools.ts
11801
12473
  init_driver2();
11802
- import { mkdir as mkdir14, readdir as readdir4, realpath, rename as rename4, stat as stat5 } from "node:fs/promises";
11803
- import { basename as basename2, dirname as dirname4, join as join14, resolve } from "node:path";
12474
+ import { mkdir as mkdir15, readdir as readdir4, realpath, rename as rename4, stat as stat5 } from "node:fs/promises";
12475
+ import { basename as basename2, dirname as dirname4, join as join15, resolve } from "node:path";
11804
12476
  function unsupported(message) {
11805
12477
  return Object.assign(new Error(message), { code: "unsupported" });
11806
12478
  }
@@ -11819,7 +12491,7 @@ async function targetOf(driver, target) {
11819
12491
  await page.release();
11820
12492
  }
11821
12493
  }
11822
- var FIREFOX_DOWNLOAD_STAGING_DIR = join14(dirname4(DOWNLOADS_DIR), "downloads-firefox-staging");
12494
+ var FIREFOX_DOWNLOAD_STAGING_DIR = join15(dirname4(DOWNLOADS_DIR), "downloads-firefox-staging");
11823
12495
  var downloadStates = new WeakMap;
11824
12496
  function downloadId(p) {
11825
12497
  const v = p.download ?? p.navigation;
@@ -11863,7 +12535,7 @@ function downloadStateFor(conn) {
11863
12535
  if (!state.stagingDirs.has(resolve(dirname4(p.filepath))))
11864
12536
  return;
11865
12537
  rec.url ??= p.url;
11866
- const held = join14(dirname4(p.filepath), `${id.replace(/[^A-Za-z0-9-]/g, "_")}.download`);
12538
+ const held = join15(dirname4(p.filepath), `${id.replace(/[^A-Za-z0-9-]/g, "_")}.download`);
11867
12539
  rename4(p.filepath, held).then(() => {
11868
12540
  rec.filePath = held;
11869
12541
  }, () => {
@@ -11873,8 +12545,8 @@ function downloadStateFor(conn) {
11873
12545
  return state;
11874
12546
  }
11875
12547
  async function armFirefoxDownloads(conn, s, scope) {
11876
- await mkdir14(FIREFOX_DOWNLOAD_STAGING_DIR, { recursive: true });
11877
- await mkdir14(DOWNLOADS_DIR, { recursive: true });
12548
+ await mkdir15(FIREFOX_DOWNLOAD_STAGING_DIR, { recursive: true });
12549
+ await mkdir15(DOWNLOADS_DIR, { recursive: true });
11878
12550
  s.stagingDirs.add(resolve(await realpath(FIREFOX_DOWNLOAD_STAGING_DIR)));
11879
12551
  scope.setDisposeHook("browser.downloads", async (c) => {
11880
12552
  await c.send("browser.setDownloadBehavior", { downloadBehavior: null });
@@ -11932,7 +12604,7 @@ async function waitForDownloadFirefox(driver, args = {}) {
11932
12604
  const taken = new Set(await readdir4(DOWNLOADS_DIR).catch(() => []));
11933
12605
  taken.delete(basename2(rec.filePath));
11934
12606
  const finalName = nextFreeName(suggestedFilename, taken);
11935
- const path = join14(DOWNLOADS_DIR, finalName);
12607
+ const path = join15(DOWNLOADS_DIR, finalName);
11936
12608
  await rename4(rec.filePath, path);
11937
12609
  const bytes = (await stat5(path)).size;
11938
12610
  return { path, suggestedFilename, bytes, ...rec.url ? { url: rec.url } : {}, target };
@@ -12049,7 +12721,8 @@ var TOOL_GROUPS = [
12049
12721
  "permissions",
12050
12722
  "dialogs",
12051
12723
  "downloads",
12052
- "extraction"
12724
+ "extraction",
12725
+ "tabs"
12053
12726
  ];
12054
12727
  var GROUP_TOOLS = {
12055
12728
  core: [
@@ -12095,7 +12768,8 @@ var GROUP_TOOLS = {
12095
12768
  permissions: ["grant_permissions"],
12096
12769
  dialogs: ["handle_dialog"],
12097
12770
  downloads: ["wait_for_download"],
12098
- extraction: ["extract_page"]
12771
+ extraction: ["extract_page"],
12772
+ tabs: ["list_tab_groups", "group_tabs", "ungroup_tabs"]
12099
12773
  };
12100
12774
  var TOOL_GROUP = {};
12101
12775
  for (const group of TOOL_GROUPS) {
@@ -12147,7 +12821,7 @@ function resolveProfile(spec) {
12147
12821
  // src/toolDocs.ts
12148
12822
  var TOOL_DOCS = {
12149
12823
  list_pages: {
12150
- description: "Enumerate browser page targets (GET /json/list); page-type tabs only unless all=true, which also lists workers and out-of-process (OOPIF) iframes. Each entry carries its targetId plus an origin field: 'agent' means this toolkit created it (also carries the creating label/createdAt, and stays 'agent' after the lease is released or the creator dies, making stray agent tabs findable), 'unknown' means no creation record - it never says 'human', the honest word for any tab it did not create; a record that exists but won't read adds originUnreadable. An entry under an active, readable lease also carries a 'lease' object {label,pid,idleMs,expiresAt,stale}, with idleMs and expiresAt computed fresh every call (never off disk), independent of probe. Under CDP_REQUIRE_LEASE this call also reaps abandoned agent tabs into an additive reaped array - but a lease reads reclaimable the moment its TTL elapses, while the tab is CLOSED only after a further grace (CDP_REAP_GRACE_MS, default 2700000ms/45min, so 60min total after last use); a dead-pid lease is reaped at once, a tab with no lease never. With probe, each page-type entry also gets 'responsive' (and humanActiveMs where human input is seen); both are absent, never false/null, without probe.",
12824
+ description: "Enumerate browser page targets (GET /json/list); page-type tabs only unless all=true, which also lists workers and out-of-process (OOPIF) iframes. Each entry carries its targetId plus an origin field: 'agent' means this toolkit created it (also carries the creating label/createdAt, and stays 'agent' after the lease is released or the creator dies, making stray agent tabs findable), 'unknown' means no creation record - it never says 'human', the honest word for any tab it did not create; a record that exists but won't read adds originUnreadable. An entry under an active, readable lease also carries a 'lease' object {label,pid,idleMs,expiresAt,stale}, with idleMs and expiresAt computed fresh every call (never off disk), independent of probe. Under CDP_REQUIRE_LEASE this call also reaps abandoned agent tabs into an additive reaped array - but a lease reads reclaimable the moment its TTL elapses, while the tab is CLOSED only after a further grace (CDP_REAP_GRACE_MS, default 2700000ms/45min, so 60min total after last use); a dead-pid lease is reaped at once, a tab with no lease never. With probe, each page-type entry also gets 'responsive' (and humanActiveMs where human input is seen); both are absent, never false/null, without probe. Under CDP_HIDDEN_TABS=1 (MCP server, Chrome), a tab this server opened hidden carries hidden:true: it is live and drivable but in no browser window, so the user cannot see it (select_page focus:true reveals it); hidden tabs are listed after the visible ones.",
12151
12825
  params: {
12152
12826
  lease: "Lease token from claim_page. Omit for a tab this process holds; required for a tab held by another process or one claimed explicitly. Auto-acquired under CDP_REQUIRE_LEASE (then pass target, not lease). See server instructions.",
12153
12827
  all: "Include non-page targets (service/shared workers, background pages, out-of-process (OOPIF) iframes); default false lists page-type tabs only. A returned non-page targetId is accepted as a bare id by any tool's `target` param.",
@@ -12157,7 +12831,7 @@ var TOOL_DOCS = {
12157
12831
  }
12158
12832
  },
12159
12833
  new_page: {
12160
- description: "Open a new browser tab via Target.createTarget and return {targetId,url}. The tab opens in the BACKGROUND (createTarget background:true; browsingContext.create background:true on Firefox), so the user's visible tab and keyboard focus stay put (on macOS the user's frontmost app is put back if the browser app came forward; CDP_RESTORE_FRONT_APP=0 turns that off); pass focus:true to open it in the foreground. Defaults to about:blank; navigation is not awaited here (use navigate_page to load and wait).",
12834
+ description: "Open a new browser tab via Target.createTarget and return {targetId,url}. The tab opens in the BACKGROUND (createTarget background:true; browsingContext.create background:true on Firefox), so the user's visible tab and keyboard focus stay put (on macOS the user's frontmost app is put back if the browser app came forward; CDP_RESTORE_FRONT_APP=0 turns that off); pass focus:true to open it in the foreground. Under CDP_HIDDEN_TABS=1 (MCP server, Chrome; ignored by the CLI) a non-focus new_page opens a HIDDEN tab instead (createTarget hidden:true): the browser app never comes forward, the result carries hidden:true, the tab is fully drivable (1280x800 emulated viewport, screenshots, clicks, typing, same cookies/logins) but the user cannot see it, it dies if this server or the browser restarts (later calls on its id fail no-such-target), and at most CDP_HIDDEN_TABS_MAX (default 20) may be open at once (new_page then refuses and names them; close_page frees one). Use select_page focus:true to show one to the user. Defaults to about:blank; navigation is not awaited here (use navigate_page to load and wait).",
12161
12835
  params: {
12162
12836
  lease: "Lease token from claim_page. Omit for a tab this process holds; required for a tab held by another process or one claimed explicitly. Auto-acquired under CDP_REQUIRE_LEASE (then pass target, not lease). See server instructions.",
12163
12837
  url: "URL to open in the new tab; defaults to about:blank.",
@@ -12165,22 +12839,22 @@ var TOOL_DOCS = {
12165
12839
  claim: "Claim the new tab atomically and return a lease token alongside {targetId,url}. Under CDP_REQUIRE_LEASE the tab is claimed and a lease returned even without claim:true; claim:true makes it an EXPLICIT lease that demands its token on every later call, even from this process. Default false.",
12166
12840
  label: "Agent label recorded on the lease when the tab is claimed; surfaced in conflict errors and list_leases. Defaults to pid-<pid>.",
12167
12841
  ttlMs: "How long a claimed lease survives without use before it is reclaimable. Defaults to CDP_LEASE_TTL_MS, else 900000 (15min); every checked call refreshes it. Ignored when not claiming.",
12168
- focus: "Open the tab in the foreground, switching the user's visible tab and taking focus. Default false: the tab opens in the background."
12842
+ focus: "Open the tab in the foreground, switching the user's visible tab and taking focus. Default false: the tab opens in the background (a hidden tab under CDP_HIDDEN_TABS=1)."
12169
12843
  }
12170
12844
  },
12171
12845
  close_page: {
12172
- description: "Close a page target via Target.closeTarget. Requires an explicit, resolvable target; errors rather than guessing when the selector matches nothing.",
12846
+ description: "Close a page target via Target.closeTarget. Requires an explicit, resolvable target; errors rather than guessing when the selector matches nothing. A hidden tab (CDP_HIDDEN_TABS) is closed over the connection that keeps it alive, and closing it never brings the browser forward.",
12173
12847
  params: {
12174
12848
  lease: "Lease token from claim_page. Omit for a tab this process holds; required for a tab held by another process or one claimed explicitly. Auto-acquired under CDP_REQUIRE_LEASE (then pass target, not lease). See server instructions.",
12175
12849
  target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Prefix any of these with 'endpoint:<name>/' for a named CDP endpoint (Chrome only). Grammar: see server instructions."
12176
12850
  }
12177
12851
  },
12178
12852
  select_page: {
12179
- description: "Persist a page target's bare targetId to the selected-state file (CDP_STATE_DIR/selected) and return {selected,focused}. By default it does NOT raise the tab: the user's visible tab and window focus stay put. focus:true also activates it (Target.activateTarget; browsingContext.activate on Firefox), which was the old default. Requires an explicit, resolvable target.",
12853
+ description: "Persist a page target's bare targetId to the selected-state file (CDP_STATE_DIR/selected) and return {selected,focused}. By default it does NOT raise the tab: the user's visible tab and window focus stay put. focus:true also activates it (Target.activateTarget; browsingContext.activate on Firefox), which was the old default. focus:true on a hidden tab (list_pages hidden:true, CDP_HIDDEN_TABS) cannot raise it in place: its current URL is opened in a new VISIBLE foreground tab, the hidden tab is closed, and the result's selected is the NEW targetId with revealedFrom naming the old one (its label moves along; a lease moves too and its new token comes back as lease). In-page state the URL does not carry (form input, scroll position) is lost. Requires an explicit, resolvable target.",
12180
12854
  params: {
12181
12855
  lease: "Lease token from claim_page. Omit for a tab this process holds; required for a tab held by another process or one claimed explicitly. Auto-acquired under CDP_REQUIRE_LEASE (then pass target, not lease). See server instructions.",
12182
12856
  target: "Page selector: 'active' (default), 'index:N', 'url:<substr>', 'title:<substr>', 'label:<name>', or a 32-hex '<targetId>'. Prefix any of these with 'endpoint:<name>/' for a named CDP endpoint (Chrome only). Grammar: see server instructions.",
12183
- focus: "Also raise the tab and take window focus (Target.activateTarget / browsingContext.activate). Default false: selection only."
12857
+ focus: "Also raise the tab and take window focus (Target.activateTarget / browsingContext.activate); a hidden tab is reopened visibly under a new targetId instead. Default false: selection only."
12184
12858
  }
12185
12859
  },
12186
12860
  navigate_page: {
@@ -12361,6 +13035,38 @@ var TOOL_DOCS = {
12361
13035
  reset: "Clear this server's previous permission grants (Browser.resetPermissions). With 'permissions' it resets FIRST and then grants, so the result is exactly the listed permissions; on its own it is a reset-only call answering {reset:true}. Not scoped to 'origin': CDP resets every origin at once."
12362
13036
  }
12363
13037
  },
13038
+ list_tab_groups: {
13039
+ description: "Lists the browser's tab groups, per window: {windows:[{windowId,tabCount,ungrouped,groups:[{groupId,title,color,collapsed,tabs:[{tabId,targetId,index,url,title}]}]}],groupCount,tabCount}; includeUngrouped:true adds each window's ungroupedTabs rows. targetId is the tab's CDP target id (the id list_pages shows), so a row can be driven by the other tools directly. CDP has no tab-group domain, so the three tab-group tools run chrome.tabGroups inside a tiny helper extension: the first call writes it under the artifact dir (tab-groups-helper/) and installs it with Extensions.loadUnpacked, and it stays installed in the profile afterwards (no UI, no state). That needs the helper directory on the browser's own machine and a Chromium that allows loadUnpacked over CDP (measured: Chromium 156-158, Helium, Vivaldi). Classified as changing state for read-only endpoints because of that install. Chrome only (capability 'browser.tabGroups'): absent under Firefox, whose BiDi cannot reach an extension background context.",
13040
+ params: {
13041
+ endpoint: "Name of a CDP endpoint configured with CDP_ENDPOINTS (Chrome only); acts on that browser instead of the default. These tools take no target.",
13042
+ windowId: "Only this chrome window id (from an earlier listing).",
13043
+ includeUngrouped: "Also return each window's ungrouped tabs as ungroupedTabs rows (same shape as group members), not just the ungrouped count. Default false."
13044
+ }
13045
+ },
13046
+ group_tabs: {
13047
+ description: "Puts tabs in a tab group and names it. Select tabs with EXACTLY ONE of tabIds (chrome tab ids from list_tab_groups), targetIds (CDP target ids, as list_pages shows them) or urlMatch (URL substring, matched in every window); a selection that matches nothing, or an unknown id, is an error and nothing is grouped. Without groupId a NEW group is created; with groupId the tabs join that existing group (its title/color are kept unless given). WINDOWS: a group lives in one window. If the selected tabs span several windows the call is REFUSED unless windowId names the destination, because Chrome would otherwise move them all into the last-focused window; with windowId, tabs from other windows are moved there and listed in 'moved'. groupId and windowId are mutually exclusive. title, color (grey|blue|red|yellow|green|pink|purple|cyan|orange) and collapsed are applied after grouping. Returns {groupId,windowId,title,color,collapsed,tabs,moved}. Never raises or focuses a window. Does not consult tab leases: grouping moves a tab in the tab strip, not the page. Helper-extension install and limits: see list_tab_groups. Chrome only (capability 'browser.tabGroups').",
13048
+ params: {
13049
+ endpoint: "Name of a CDP endpoint configured with CDP_ENDPOINTS (Chrome only). These tools take no target.",
13050
+ tabIds: "Chrome tab ids to group, from list_tab_groups. Non-empty.",
13051
+ targetIds: "CDP target ids to group (the ids list_pages shows). Non-empty.",
13052
+ urlMatch: "Substring of the tab URL; every matching tab in every window is selected.",
13053
+ title: "Group title shown on the tab strip.",
13054
+ color: "One of grey, blue, red, yellow, green, pink, purple, cyan, orange.",
13055
+ collapsed: "Collapse (true) or expand (false) the group.",
13056
+ groupId: "Add the tabs to this existing group instead of creating one. Not with windowId.",
13057
+ windowId: "Window the new group goes in; selected tabs in other windows are moved there. Required when the selection spans windows. Not with groupId."
13058
+ }
13059
+ },
13060
+ ungroup_tabs: {
13061
+ description: "Removes tabs from their tab groups; a group left with no tabs disappears. Select with EXACTLY ONE of tabIds, targetIds, urlMatch (as group_tabs) or groupId (every tab of that group). Tabs stay where they are in the window. Returns {ungrouped:[{tabId,targetId,index,url,title,fromGroupId}],alreadyUngrouped:[tabId]}; selected tabs that were in no group are listed in alreadyUngrouped rather than treated as an error. Helper-extension install and limits: see list_tab_groups. Chrome only (capability 'browser.tabGroups').",
13062
+ params: {
13063
+ endpoint: "Name of a CDP endpoint configured with CDP_ENDPOINTS (Chrome only). These tools take no target.",
13064
+ tabIds: "Chrome tab ids to ungroup.",
13065
+ targetIds: "CDP target ids to ungroup.",
13066
+ urlMatch: "Substring of the tab URL; matching tabs in every window are ungrouped.",
13067
+ groupId: "Ungroup every tab of this group."
13068
+ }
13069
+ },
12364
13070
  fill: {
12365
13071
  description: `Fills an element by focusing it, clearing existing content, then inserting value via Input.insertText (atomic paste-like commit, not per-character keystrokes, so it won't fire per-keypress handlers). Give exactly one of uid or selector. Returns {filled,element,value}; element names the field (textbox "Email"). On a background tab (Chrome), which gets no trusted keyboard input, the commit is verified and falls back in-page (execCommand insertText, else the native value setter plus input/change events); the result then carries inputPath. The tab is never raised.`,
12366
13072
  params: {
@@ -12704,6 +13410,9 @@ var MUTATING_TOOLS = new Set([
12704
13410
  "click_focus_gated",
12705
13411
  "wait_for_download",
12706
13412
  "grant_permissions",
13413
+ "list_tab_groups",
13414
+ "group_tabs",
13415
+ "ungroup_tabs",
12707
13416
  "claim_page",
12708
13417
  "release_page"
12709
13418
  ]);
@@ -12751,7 +13460,7 @@ function toolAnnotations(name) {
12751
13460
  }
12752
13461
 
12753
13462
  // src/version.ts
12754
- var VERSION = "3.4.0";
13463
+ var VERSION = "3.6.0";
12755
13464
 
12756
13465
  // src/mcp.ts
12757
13466
  function isDirectRun() {
@@ -13060,6 +13769,9 @@ async function run3(argv) {
13060
13769
  shuttingDown = true;
13061
13770
  await disposeFirefoxSession();
13062
13771
  await disposeBrowserSession();
13772
+ await disposeHiddenTabs().catch(() => {
13773
+ return;
13774
+ });
13063
13775
  if (stdioHandle)
13064
13776
  await stdioHandle.close().catch(() => {
13065
13777
  return;