@browserbasehq/browse-cli 0.5.0-alpha-34598b9 → 0.5.0-alpha-a4ca430

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.
Files changed (3) hide show
  1. package/README.md +0 -1
  2. package/dist/index.js +181 -8
  3. package/package.json +2 -1
package/README.md CHANGED
@@ -239,7 +239,6 @@ browse status
239
239
  |----------|-------------|
240
240
  | `BROWSE_SESSION` | Default session name (alternative to `--session`) |
241
241
  | `BROWSERBASE_API_KEY` | Browserbase API key (required for `browse env remote`) |
242
- | `BROWSERBASE_PROJECT_ID` | Browserbase project ID (optional, passed through if set) |
243
242
 
244
243
  ## Element References
245
244
 
package/dist/index.js CHANGED
@@ -14413,7 +14413,7 @@ var init_api2 = __esm({
14413
14413
  }),
14414
14414
  modelName: external_exports.string().meta({
14415
14415
  description: "Model name string with provider prefix (e.g., 'openai/gpt-5-nano')",
14416
- example: "openai/gpt-5-nano"
14416
+ example: "openai/gpt-5.4-mini"
14417
14417
  }),
14418
14418
  apiKey: external_exports.string().optional().meta({
14419
14419
  description: "API key for the model provider",
@@ -14556,7 +14556,7 @@ var init_api2 = __esm({
14556
14556
  SessionStartRequestSchema = external_exports.object({
14557
14557
  modelName: external_exports.string().meta({
14558
14558
  description: "Model name to use for AI operations",
14559
- example: "openai/gpt-4o"
14559
+ example: "openai/gpt-5.4-mini"
14560
14560
  }),
14561
14561
  domSettleTimeoutMs: external_exports.number().optional().meta({
14562
14562
  description: "Timeout in ms to wait for DOM to settle",
@@ -161660,9 +161660,6 @@ var StagehandAPIClient = class {
161660
161660
  browserbaseSessionID
161661
161661
  // browser, TODO for local browsers
161662
161662
  }) {
161663
- if (!modelApiKey) {
161664
- throw new StagehandAPIError("modelApiKey is required");
161665
- }
161666
161663
  this.modelApiKey = modelApiKey;
161667
161664
  this.modelProvider = modelName?.includes("/") ? modelName.split("/")[0] : void 0;
161668
161665
  this.region = browserbaseSessionCreateParams?.region;
@@ -161943,7 +161940,7 @@ var StagehandAPIClient = class {
161943
161940
  const apiKey = provider && provider !== this.modelProvider ? loadApiKeyFromEnv(provider, this.logger) ?? this.modelApiKey : this.modelApiKey;
161944
161941
  return {
161945
161942
  modelName: model,
161946
- apiKey
161943
+ ...apiKey ? { apiKey } : {}
161947
161944
  };
161948
161945
  }
161949
161946
  if (!model.apiKey) {
@@ -161951,7 +161948,7 @@ var StagehandAPIClient = class {
161951
161948
  const apiKey = provider && provider !== this.modelProvider ? loadApiKeyFromEnv(provider, this.logger) ?? this.modelApiKey : this.modelApiKey;
161952
161949
  return {
161953
161950
  ...model,
161954
- apiKey
161951
+ ...apiKey ? { apiKey } : {}
161955
161952
  };
161956
161953
  }
161957
161954
  return model;
@@ -162078,7 +162075,7 @@ var StagehandAPIClient = class {
162078
162075
  "x-bb-session-id": this.sessionId,
162079
162076
  // we want real-time logs, so we stream the response
162080
162077
  "x-stream-response": "true",
162081
- "x-model-api-key": this.modelApiKey,
162078
+ ...this.modelApiKey ? { "x-model-api-key": this.modelApiKey } : {},
162082
162079
  "x-language": "typescript",
162083
162080
  "x-sdk-version": STAGEHAND_VERSION
162084
162081
  };
@@ -164650,6 +164647,7 @@ var os3 = __toESM(require("os"));
164650
164647
  var net2 = __toESM(require("net"));
164651
164648
  var import_child_process4 = require("child_process");
164652
164649
  var readline = __toESM(require("readline"));
164650
+ var import_ws3 = __toESM(require("ws"));
164653
164651
 
164654
164652
  // package.json
164655
164653
  var version3 = "0.5.0";
@@ -166807,6 +166805,181 @@ networkCmd.command("clear").description("Clear all captured requests").action(as
166807
166805
  process.exit(1);
166808
166806
  }
166809
166807
  });
166808
+ var CDP_DEFAULT_DOMAINS = ["Network", "Console", "Runtime", "Log", "Page"];
166809
+ program.command("cdp <url|port>").description(
166810
+ "Attach to a CDP target and stream DevTools protocol events as NDJSON.\nAccepts a WebSocket URL (ws://...) or a bare port number (e.g. 9222).\nOutput is one JSON object per line, suitable for piping to files or jq."
166811
+ ).option(
166812
+ "--domain <domains...>",
166813
+ `CDP domains to enable (repeatable). Default: ${CDP_DEFAULT_DOMAINS.join(",")}`
166814
+ ).option("--pretty", "Human-readable output instead of JSON").action(
166815
+ async (target, cmdOpts) => {
166816
+ const wsUrl = await resolveWsTarget(target);
166817
+ const domains = cmdOpts.domain ?? CDP_DEFAULT_DOMAINS;
166818
+ const usePretty = cmdOpts.pretty ?? process.stdout.isTTY ?? false;
166819
+ let messageId = 1;
166820
+ const pendingIds = /* @__PURE__ */ new Set();
166821
+ const targetSessionMap = /* @__PURE__ */ new Map();
166822
+ function sendCDP(ws, method, params = {}, sessionId) {
166823
+ const id = messageId++;
166824
+ pendingIds.add(id);
166825
+ const msg = { id, method, params };
166826
+ if (sessionId) msg.sessionId = sessionId;
166827
+ ws.send(JSON.stringify(msg));
166828
+ return id;
166829
+ }
166830
+ function enableDomainsForSession(ws, sessionId) {
166831
+ for (const domain2 of domains) {
166832
+ if (domain2 === "Network") {
166833
+ sendCDP(
166834
+ ws,
166835
+ "Network.enable",
166836
+ { maxTotalBufferSize: 1e6, maxResourceBufferSize: 1e5 },
166837
+ sessionId
166838
+ );
166839
+ } else {
166840
+ sendCDP(ws, `${domain2}.enable`, {}, sessionId);
166841
+ }
166842
+ }
166843
+ }
166844
+ function writeEvent(message) {
166845
+ try {
166846
+ process.stdout.write(JSON.stringify(message) + "\n");
166847
+ } catch (err) {
166848
+ if (err.code === "EPIPE") process.exit(0);
166849
+ throw err;
166850
+ }
166851
+ }
166852
+ function writePrettyEvent(message) {
166853
+ if (!message.method) return;
166854
+ const params = message.params;
166855
+ let line = `[${message.method}]`;
166856
+ try {
166857
+ switch (message.method) {
166858
+ case "Network.requestWillBeSent": {
166859
+ const req = params?.request;
166860
+ if (req) line += ` ${req.method ?? "?"} ${req.url ?? ""}`;
166861
+ break;
166862
+ }
166863
+ case "Network.responseReceived": {
166864
+ const resp = params?.response;
166865
+ if (resp) line += ` ${resp.status ?? "?"} ${resp.url ?? ""}`;
166866
+ break;
166867
+ }
166868
+ case "Network.loadingFailed": {
166869
+ const errorText = params?.errorText ?? (params?.canceled ? "Canceled" : "Unknown");
166870
+ line += ` ${errorText}`;
166871
+ break;
166872
+ }
166873
+ case "Runtime.consoleAPICalled": {
166874
+ const type = params?.type ?? "log";
166875
+ const args = params?.args ?? [];
166876
+ const text2 = args.map((a2) => a2.description ?? a2.value ?? "").join(" ");
166877
+ line += ` [${type}] ${text2}`;
166878
+ break;
166879
+ }
166880
+ case "Runtime.exceptionThrown": {
166881
+ const detail = params?.exceptionDetails;
166882
+ line += ` ${detail?.exception?.description ?? detail?.text ?? "Unknown exception"}`;
166883
+ break;
166884
+ }
166885
+ case "Page.frameNavigated": {
166886
+ const url2 = params?.frame?.url ?? "";
166887
+ if (url2) line += ` ${url2}`;
166888
+ break;
166889
+ }
166890
+ case "Target.attachedToTarget": {
166891
+ const info = params?.targetInfo;
166892
+ if (info) line += ` [${info.type ?? "?"}] ${info.url ?? ""}`;
166893
+ break;
166894
+ }
166895
+ default:
166896
+ break;
166897
+ }
166898
+ } catch {
166899
+ }
166900
+ try {
166901
+ process.stdout.write(line + "\n");
166902
+ } catch (err) {
166903
+ if (err.code === "EPIPE") process.exit(0);
166904
+ throw err;
166905
+ }
166906
+ }
166907
+ const emit = usePretty ? writePrettyEvent : writeEvent;
166908
+ await new Promise((resolve4) => {
166909
+ const ws = new import_ws3.default(wsUrl);
166910
+ let closed = false;
166911
+ function cleanup() {
166912
+ if (closed) return;
166913
+ closed = true;
166914
+ if (ws.readyState === import_ws3.default.OPEN || ws.readyState === import_ws3.default.CONNECTING) {
166915
+ ws.close();
166916
+ }
166917
+ resolve4();
166918
+ }
166919
+ process.on("SIGINT", cleanup);
166920
+ process.on("SIGTERM", cleanup);
166921
+ ws.on("open", () => {
166922
+ if (usePretty) {
166923
+ process.stderr.write(`Connected to ${wsUrl}
166924
+ `);
166925
+ }
166926
+ sendCDP(ws, "Target.setAutoAttach", {
166927
+ autoAttach: true,
166928
+ flatten: true,
166929
+ waitForDebuggerOnStart: false,
166930
+ filter: [{ type: "page" }]
166931
+ });
166932
+ sendCDP(ws, "Target.setDiscoverTargets", {
166933
+ discover: true,
166934
+ filter: [{ type: "page" }]
166935
+ });
166936
+ });
166937
+ ws.on("message", (raw) => {
166938
+ let data;
166939
+ try {
166940
+ data = JSON.parse(raw.toString());
166941
+ } catch {
166942
+ return;
166943
+ }
166944
+ if (data.id !== void 0 && pendingIds.has(data.id)) {
166945
+ pendingIds.delete(data.id);
166946
+ if (data.error) {
166947
+ process.stderr.write(
166948
+ `CDP error (id=${data.id}): ${data.error.message}
166949
+ `
166950
+ );
166951
+ }
166952
+ return;
166953
+ }
166954
+ if (data.method === "Target.attachedToTarget" && data.params) {
166955
+ const p2 = data.params;
166956
+ if (p2.targetInfo?.type === "page") {
166957
+ targetSessionMap.set(p2.targetInfo.targetId, p2.sessionId);
166958
+ enableDomainsForSession(ws, p2.sessionId);
166959
+ }
166960
+ }
166961
+ if (data.method === "Target.detachedFromTarget" && data.params) {
166962
+ const p2 = data.params;
166963
+ const targetId = p2.targetId ?? [...targetSessionMap.entries()].find(
166964
+ ([, sid]) => sid === p2.sessionId
166965
+ )?.[0];
166966
+ if (targetId) targetSessionMap.delete(targetId);
166967
+ }
166968
+ emit(data);
166969
+ });
166970
+ ws.on("error", (err) => {
166971
+ process.stderr.write(`Error: ${err.message}
166972
+ `);
166973
+ });
166974
+ ws.on("close", () => {
166975
+ if (!closed && usePretty) {
166976
+ process.stderr.write("Disconnected.\n");
166977
+ }
166978
+ cleanup();
166979
+ });
166980
+ });
166981
+ }
166982
+ );
166810
166983
  program.parse();
166811
166984
  /*! Bundled license information:
166812
166985
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@browserbasehq/browse-cli",
3
- "version": "0.5.0-alpha-34598b9",
3
+ "version": "0.5.0-alpha-a4ca430",
4
4
  "description": "Browser automation CLI for AI agents, built on Stagehand",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",
@@ -52,6 +52,7 @@
52
52
  },
53
53
  "devDependencies": {
54
54
  "@types/node": "^20.11.30",
55
+ "@types/ws": "^8.5.13",
55
56
  "devtools-protocol": "^0.0.1464554",
56
57
  "eslint": "^10.0.2",
57
58
  "tsup": "^8.2.1",