yiyan-browser-agent 1.0.23 → 1.0.24

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yiyan-browser-agent",
3
- "version": "1.0.23",
3
+ "version": "1.0.24",
4
4
  "description": "AI coding agent powered by Yiyan (文心一言) via browser automation — no API key needed",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -23,11 +23,15 @@ class BrowserManager {
23
23
  // Try connect existing browser
24
24
  try {
25
25
  if (fs.existsSync(CDP_PORT_FILE)) {
26
- const portInfo = JSON.parse(fs.readFileSync(CDP_PORT_FILE, 'utf8'));
27
- const browserURL = `http://localhost:${portInfo.port || CDP_PORT}`;
26
+ const endpointInfo = JSON.parse(fs.readFileSync(CDP_PORT_FILE, 'utf8'));
27
+ const wsEndpoint = endpointInfo.wsEndpoint;
28
+
29
+ if (!wsEndpoint) {
30
+ throw new Error('No wsEndpoint in file');
31
+ }
28
32
 
29
33
  logger.info('Connecting to existing browser...');
30
- const browser = await chromium.connectOverCDP(browserURL, { timeout: 5000 });
34
+ const browser = await chromium.connect({ wsEndpoint, timeout: 5000 });
31
35
 
32
36
  // Create NEW context and page (tab) for this task
33
37
  const context = await browser.newContext({
@@ -54,26 +58,35 @@ class BrowserManager {
54
58
  * Launch new browser with CDP port
55
59
  */
56
60
  static async _launchNew() {
57
- logger.info('Launching new browser with CDP port ' + CDP_PORT + '...');
61
+ logger.info('Launching new browser server...');
58
62
 
59
- // Launch browser (not persistentContext) to expose CDP properly
60
- const browser = await chromium.launch({
63
+ // Use launchServer to create independent browser process
64
+ // Browser will NOT close when Node.js process exits
65
+ const browserServer = await chromium.launchServer({
61
66
  headless: false,
62
- port: CDP_PORT,
63
67
  args: [
64
68
  '--disable-blink-features=AutomationControlled',
65
69
  '--no-first-run',
66
70
  '--no-sandbox',
67
- `--user-data-dir=${SESSION_DIR}`,
68
71
  ],
69
72
  });
70
73
 
71
- // Save CDP port info
74
+ // Get the WebSocket endpoint
75
+ const wsEndpoint = browserServer.wsEndpoint();
76
+ const port = wsEndpoint.match(/:(\d+)/)?.[1] || CDP_PORT;
77
+
78
+ // Save endpoint info
72
79
  fs.writeFileSync(CDP_PORT_FILE, JSON.stringify({
73
- port: CDP_PORT,
80
+ wsEndpoint: wsEndpoint,
81
+ port: port,
74
82
  launchedAt: Date.now()
75
83
  }));
76
84
 
85
+ logger.success('Browser server started!');
86
+
87
+ // Connect to our own server
88
+ const browser = await chromium.connect({ wsEndpoint });
89
+
77
90
  // Create context and page
78
91
  const context = await browser.newContext({
79
92
  viewport: { width: 1280, height: 900 },
@@ -84,8 +97,8 @@ class BrowserManager {
84
97
  await page.goto(config.YIYAN_URL, { waitUntil: 'domcontentloaded', timeout: 15000 });
85
98
  await page.waitForTimeout(800);
86
99
 
87
- logger.success('Browser launched! Tab ready.');
88
- return { browser, context, page, isNew: true };
100
+ logger.success('Tab ready.');
101
+ return { browser, context, page, isNew: true, browserServer };
89
102
  }
90
103
 
91
104
  /**