@lightcone-ai/daemon 0.9.14 → 0.9.16

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/xhs-login.js +25 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightcone-ai/daemon",
3
- "version": "0.9.14",
3
+ "version": "0.9.16",
4
4
  "type": "module",
5
5
  "main": "src/index.js",
6
6
  "bin": {
package/src/xhs-login.js CHANGED
@@ -5,6 +5,7 @@
5
5
  */
6
6
  import { spawn } from 'child_process';
7
7
  import { homedir } from 'os';
8
+ import { accessSync, constants as fsConstants } from 'fs';
8
9
  import path from 'path';
9
10
  import http from 'http';
10
11
  import { WebSocket } from 'ws';
@@ -15,7 +16,22 @@ export function xhsProfileDir(userId) {
15
16
  }
16
17
 
17
18
  const CDP_PORT = 9225;
18
- const CHROME_BIN = process.env.CHROME_BIN ?? '/usr/bin/google-chrome';
19
+ function detectChrome() {
20
+ if (process.env.CHROME_BIN) return process.env.CHROME_BIN;
21
+ const candidates = [
22
+ '/usr/bin/google-chrome',
23
+ '/usr/bin/google-chrome-stable',
24
+ '/usr/bin/chromium-browser',
25
+ '/usr/bin/chromium',
26
+ '/snap/bin/chromium',
27
+ '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
28
+ ];
29
+ for (const p of candidates) {
30
+ try { accessSync(p, fsConstants.X_OK); return p; } catch {}
31
+ }
32
+ return candidates[0];
33
+ }
34
+ const CHROME_BIN = detectChrome();
19
35
  const SCREENSHOT_INTERVAL_MS = 2000;
20
36
  const LOGIN_CHECK_INTERVAL_MS = 3000;
21
37
 
@@ -53,6 +69,10 @@ export class XhsLoginSession {
53
69
  '--headless=new',
54
70
  `--user-data-dir=${this._profileDir}`,
55
71
  '--window-size=800,900',
72
+ '--disable-blink-features=AutomationControlled',
73
+ '--disable-infobars',
74
+ '--excludeSwitches=enable-automation',
75
+ '--user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
56
76
  'about:blank',
57
77
  ], {
58
78
  stdio: 'ignore',
@@ -92,6 +112,10 @@ export class XhsLoginSession {
92
112
 
93
113
  await this.send('Page.enable', {});
94
114
  await this.send('Network.enable', {});
115
+ // Hide automation fingerprint
116
+ await this.send('Page.addScriptToEvaluateOnNewDocument', {
117
+ source: `Object.defineProperty(navigator, 'webdriver', { get: () => undefined });`,
118
+ });
95
119
  await this.send('Page.navigate', { url: 'https://www.xiaohongshu.com' });
96
120
 
97
121
  // Start sending screenshots and checking login