cbrowser 19.4.2 → 19.4.3

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/cli.js CHANGED
@@ -339,10 +339,12 @@ PERFORMANCE REGRESSION (v6.4.0)
339
339
  cbrowser perf-regression "https://example.com" homepage --sensitivity strict
340
340
  cbrowser perf-regression "https://example.com" homepage --threshold-lcp 30
341
341
 
342
- NETWORK / HAR
343
- har start Start recording HAR
342
+ NETWORK / HAR (need the daemon: each command is its own process)
343
+ daemon start Start the daemon first; it holds the browser between commands
344
+ har start Start recording HAR in the daemon's browser
344
345
  har stop [output] Stop and save HAR file
345
- network list List captured network requests
346
+ network list List network requests the daemon's browser captured
347
+ network clear Clear that list
346
348
 
347
349
  VISUAL REGRESSION (v2.5.0)
348
350
  visual save <name> Save baseline screenshot
@@ -4381,32 +4383,83 @@ Documentation: https://github.com/alexandriashai/cbrowser/wiki
4381
4383
  // =========================================================================
4382
4384
  case "har": {
4383
4385
  const subcommand = args[0];
4384
- switch (subcommand) {
4385
- case "start": {
4386
- browser.startHarRecording();
4387
- console.log("✓ HAR recording started");
4388
- console.log(" Navigate and interact with pages, then run 'cbrowser har stop'");
4389
- break;
4386
+ if (subcommand !== "start" && subcommand !== "stop") {
4387
+ console.error("Usage: cbrowser har [start|stop]");
4388
+ break;
4389
+ }
4390
+ // A recording has to span several commands, and each cbrowser command is
4391
+ // its own process: only the daemon's browser outlives them. Recorded here,
4392
+ // start, navigate and stop were three processes and every HAR was empty,
4393
+ // with or without a daemon, while this printed "started" and "saved".
4394
+ // (2026-10-12)
4395
+ if (!(await isDaemonRunning())) {
4396
+ console.error("Error: HAR recording spans several commands, and each cbrowser command is its own process,");
4397
+ console.error(" so nothing records between them. Start the daemon first:");
4398
+ console.error(" cbrowser daemon start -> cbrowser har start -> navigate/click... -> cbrowser har stop [file]");
4399
+ process.exit(1);
4400
+ }
4401
+ const response = subcommand === "start"
4402
+ ? await sendToDaemon("harStart", {})
4403
+ : await sendToDaemon("harStop", {});
4404
+ if (!response.success) {
4405
+ console.error(`✗ Daemon error: ${response.error}`);
4406
+ process.exit(1);
4407
+ }
4408
+ if (subcommand === "start") {
4409
+ console.log("✓ HAR recording started in the daemon");
4410
+ console.log(" Navigate and interact with pages, then run 'cbrowser har stop'");
4411
+ }
4412
+ else {
4413
+ // The daemon writes only its own har directory; a chosen path is written here,
4414
+ // with this process's permissions.
4415
+ const { file, har } = response.result;
4416
+ if (args[1]) {
4417
+ const out = resolve(args[1]);
4418
+ writeFileSync(out, har);
4419
+ console.log(`✓ HAR saved: ${out}`);
4390
4420
  }
4391
- case "stop": {
4392
- const output = args[1];
4393
- const filename = await browser.exportHar(output);
4394
- console.log(`✓ HAR saved: ${filename}`);
4395
- break;
4421
+ else {
4422
+ console.log(`✓ HAR saved: ${file}`);
4396
4423
  }
4397
- default:
4398
- console.error("Usage: cbrowser har [start|stop]");
4399
4424
  }
4400
- break;
4425
+ process.exit(0);
4401
4426
  }
4402
4427
  // =========================================================================
4403
4428
  // Network
4404
4429
  // =========================================================================
4405
4430
  case "network": {
4406
4431
  const subcommand = args[0];
4432
+ if (subcommand !== "list" && subcommand !== "clear") {
4433
+ console.error("Usage: cbrowser network [list|clear]");
4434
+ break;
4435
+ }
4436
+ // Same reason as har: the request log lives in a browser, and only the
4437
+ // daemon's browser outlives a command. A fresh process always listed
4438
+ // nothing and said "Navigate to a page first", even right after a
4439
+ // navigate. (2026-10-12)
4440
+ if (!(await isDaemonRunning())) {
4441
+ console.error("Error: the network log only spans commands in the daemon's browser; each cbrowser command is");
4442
+ console.error(" its own process. Start the daemon first:");
4443
+ console.error(" cbrowser daemon start -> navigate/click... -> cbrowser network list");
4444
+ process.exit(1);
4445
+ }
4446
+ if (subcommand === "clear") {
4447
+ const cleared = await sendToDaemon("networkClear", {});
4448
+ if (!cleared.success) {
4449
+ console.error(`✗ Daemon error: ${cleared.error}`);
4450
+ process.exit(1);
4451
+ }
4452
+ console.log("✓ Network history cleared");
4453
+ process.exit(0);
4454
+ }
4455
+ const listed = await sendToDaemon("networkList", {});
4456
+ if (!listed.success) {
4457
+ console.error(`✗ Daemon error: ${listed.error}`);
4458
+ process.exit(1);
4459
+ }
4407
4460
  switch (subcommand) {
4408
4461
  case "list": {
4409
- const requests = browser.getNetworkRequests();
4462
+ const requests = listed.result.requests;
4410
4463
  if (requests.length === 0) {
4411
4464
  console.log("No network requests captured");
4412
4465
  console.log("Navigate to a page first to capture requests");
@@ -4423,15 +4476,8 @@ Documentation: https://github.com/alexandriashai/cbrowser/wiki
4423
4476
  }
4424
4477
  break;
4425
4478
  }
4426
- case "clear": {
4427
- browser.clearNetworkHistory();
4428
- console.log("✓ Network history cleared");
4429
- break;
4430
- }
4431
- default:
4432
- console.error("Usage: cbrowser network [list|clear]");
4433
4479
  }
4434
- break;
4480
+ process.exit(0);
4435
4481
  }
4436
4482
  // =========================================================================
4437
4483
  // Visual Regression (Tier 2)