bb-browser 0.8.2 → 0.8.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
@@ -73,6 +73,10 @@ function findBrowserExecutable() {
73
73
  if (process.platform === "darwin") {
74
74
  const candidates = [
75
75
  "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
76
+ "/Applications/Google Chrome Dev.app/Contents/MacOS/Google Chrome Dev",
77
+ "/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary",
78
+ "/Applications/Google Chrome Beta.app/Contents/MacOS/Google Chrome Beta",
79
+ "/Applications/Arc.app/Contents/MacOS/Arc",
76
80
  "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge",
77
81
  "/Applications/Brave Browser.app/Contents/MacOS/Brave Browser"
78
82
  ];
@@ -1186,9 +1190,6 @@ async function sendCommand2(request) {
1186
1190
  import { fileURLToPath as fileURLToPath2 } from "url";
1187
1191
  import { dirname, resolve } from "path";
1188
1192
  import { existsSync as existsSync2 } from "fs";
1189
- async function isDaemonRunning() {
1190
- return await discoverCdpPort() !== null;
1191
- }
1192
1193
  async function ensureDaemonRunning() {
1193
1194
  try {
1194
1195
  await ensureCdpConnection();
@@ -2435,123 +2436,6 @@ async function scrollCommand(direction, pixels, options = {}) {
2435
2436
  }
2436
2437
  }
2437
2438
 
2438
- // packages/cli/src/commands/daemon.ts
2439
- async function statusCommand(options = {}) {
2440
- const running = await isDaemonRunning();
2441
- if (options.json) {
2442
- console.log(JSON.stringify({ running }));
2443
- } else {
2444
- console.log(running ? "\u6D4F\u89C8\u5668\u8FD0\u884C\u4E2D" : "\u6D4F\u89C8\u5668\u672A\u8FD0\u884C");
2445
- }
2446
- }
2447
-
2448
- // packages/cli/src/commands/reload.ts
2449
- import WebSocket2 from "ws";
2450
- var EXTENSION_NAME = "bb-browser";
2451
- async function reloadCommand(options = {}) {
2452
- const port = options.port || 9222;
2453
- try {
2454
- const listRes = await fetch(`http://127.0.0.1:${port}/json/list`);
2455
- if (!listRes.ok) {
2456
- throw new Error(`CDP \u672A\u542F\u7528\u3002\u8BF7\u7528 --remote-debugging-port=${port} \u542F\u52A8 Chrome`);
2457
- }
2458
- const list = await listRes.json();
2459
- const extPage = list.find(
2460
- (t) => t.type === "page" && t.url.includes("chrome://extensions")
2461
- );
2462
- if (!extPage) {
2463
- throw new Error("\u8BF7\u5148\u6253\u5F00 chrome://extensions \u9875\u9762");
2464
- }
2465
- const result = await new Promise((resolve2, reject) => {
2466
- const ws = new WebSocket2(extPage.webSocketDebuggerUrl);
2467
- let resolved = false;
2468
- const timeout = setTimeout(() => {
2469
- if (!resolved) {
2470
- resolved = true;
2471
- ws.close();
2472
- reject(new Error("CDP \u8FDE\u63A5\u8D85\u65F6"));
2473
- }
2474
- }, 1e4);
2475
- ws.on("open", () => {
2476
- const script = `
2477
- (async function() {
2478
- if (!chrome || !chrome.developerPrivate) {
2479
- return { error: 'developerPrivate API not available' };
2480
- }
2481
-
2482
- try {
2483
- const exts = await chrome.developerPrivate.getExtensionsInfo();
2484
- const bbExt = exts.find(e => e.name === '${EXTENSION_NAME}');
2485
-
2486
- if (!bbExt) {
2487
- return { error: '${EXTENSION_NAME} \u6269\u5C55\u672A\u5B89\u88C5' };
2488
- }
2489
-
2490
- if (bbExt.state !== 'ENABLED') {
2491
- return { error: '${EXTENSION_NAME} \u6269\u5C55\u5DF2\u7981\u7528' };
2492
- }
2493
-
2494
- await chrome.developerPrivate.reload(bbExt.id, {failQuietly: true});
2495
- return { success: true, extensionId: bbExt.id };
2496
- } catch (e) {
2497
- return { error: e.message };
2498
- }
2499
- })()
2500
- `;
2501
- ws.send(JSON.stringify({
2502
- id: 1,
2503
- method: "Runtime.evaluate",
2504
- params: {
2505
- expression: script,
2506
- awaitPromise: true,
2507
- returnByValue: true
2508
- }
2509
- }));
2510
- });
2511
- ws.on("message", (data) => {
2512
- const msg = JSON.parse(data.toString());
2513
- if (msg.id === 1) {
2514
- clearTimeout(timeout);
2515
- resolved = true;
2516
- ws.close();
2517
- const value = msg.result?.result?.value;
2518
- if (value?.success) {
2519
- resolve2({
2520
- success: true,
2521
- message: "\u6269\u5C55\u5DF2\u91CD\u8F7D",
2522
- extensionId: value.extensionId
2523
- });
2524
- } else if (value?.error) {
2525
- reject(new Error(value.error));
2526
- } else {
2527
- reject(new Error(`\u91CD\u8F7D\u5931\u8D25: ${JSON.stringify(value)}`));
2528
- }
2529
- }
2530
- });
2531
- ws.on("error", (err) => {
2532
- clearTimeout(timeout);
2533
- if (!resolved) {
2534
- resolved = true;
2535
- reject(new Error(`CDP \u8FDE\u63A5\u5931\u8D25: ${err.message}`));
2536
- }
2537
- });
2538
- });
2539
- if (options.json) {
2540
- console.log(JSON.stringify(result));
2541
- } else {
2542
- console.log(`${result.message} (${result.extensionId})`);
2543
- }
2544
- } catch (error) {
2545
- const message = error instanceof Error ? error.message : String(error);
2546
- if (options.json) {
2547
- console.log(JSON.stringify({ success: false, error: message }));
2548
- } else {
2549
- console.error(`\u9519\u8BEF: ${message}`);
2550
- }
2551
- process.exit(1);
2552
- }
2553
- }
2554
-
2555
2439
  // packages/cli/src/commands/nav.ts
2556
2440
  async function backCommand(options = {}) {
2557
2441
  await ensureDaemonRunning();
@@ -3717,24 +3601,6 @@ async function main() {
3717
3601
  break;
3718
3602
  }
3719
3603
  case "daemon":
3720
- case "start": {
3721
- const hostIdx = process.argv.findIndex((a) => a === "--host");
3722
- const host = hostIdx >= 0 ? process.argv[hostIdx + 1] : void 0;
3723
- await daemonCommand({ json: parsed.flags.json, host });
3724
- break;
3725
- }
3726
- case "stop": {
3727
- await stopCommand({ json: parsed.flags.json });
3728
- break;
3729
- }
3730
- case "status": {
3731
- await statusCommand({ json: parsed.flags.json });
3732
- break;
3733
- }
3734
- case "reload": {
3735
- await reloadCommand({ json: parsed.flags.json });
3736
- break;
3737
- }
3738
3604
  case "close": {
3739
3605
  await closeCommand({ json: parsed.flags.json, tabId: globalTabId });
3740
3606
  break;