@lightcone-ai/daemon 0.9.43 → 0.9.44
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 +1 -1
- package/src/browser-login.js +29 -29
package/package.json
CHANGED
package/src/browser-login.js
CHANGED
|
@@ -16,36 +16,29 @@ import { WebSocket } from 'ws';
|
|
|
16
16
|
export const PLATFORM_CONFIGS = {
|
|
17
17
|
xhs: {
|
|
18
18
|
loginUrl: 'https://www.xiaohongshu.com',
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
// Returns current session value (null if not present)
|
|
20
|
+
getSessionValue: (cookies) => cookies.find(c => c.name === 'web_session')?.value ?? null,
|
|
21
|
+
// Login = value exists AND has changed from baseline (real auth replaces anonymous session)
|
|
22
|
+
isLoggedIn: (cookies, baseline) => {
|
|
23
|
+
const val = cookies.find(c => c.name === 'web_session')?.value ?? null;
|
|
24
|
+
return val !== null && val !== baseline;
|
|
25
|
+
},
|
|
25
26
|
},
|
|
26
27
|
douyin: {
|
|
27
28
|
loginUrl: 'https://www.douyin.com',
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
{ name: 'sessionid', domain: 'www.douyin.com' },
|
|
34
|
-
{ name: 'sid_guard', domain: '.douyin.com' },
|
|
35
|
-
{ name: 'sid_guard', domain: 'www.douyin.com' },
|
|
36
|
-
],
|
|
29
|
+
getSessionValue: (cookies) => cookies.find(c => c.name === 'sessionid')?.value ?? null,
|
|
30
|
+
isLoggedIn: (cookies, baseline) => {
|
|
31
|
+
const val = cookies.find(c => c.name === 'sessionid')?.value ?? null;
|
|
32
|
+
return val !== null && val !== baseline;
|
|
33
|
+
},
|
|
37
34
|
},
|
|
38
35
|
kuaishou: {
|
|
39
36
|
loginUrl: 'https://www.kuaishou.com',
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
{ name: 'userId', domain: 'www.kuaishou.com' },
|
|
46
|
-
{ name: 'passToken', domain: '.kuaishou.com' },
|
|
47
|
-
{ name: 'passToken', domain: 'www.kuaishou.com' },
|
|
48
|
-
],
|
|
37
|
+
getSessionValue: (cookies) => cookies.find(c => c.name === 'passToken')?.value ?? null,
|
|
38
|
+
isLoggedIn: (cookies, baseline) => {
|
|
39
|
+
const val = cookies.find(c => c.name === 'passToken')?.value ?? null;
|
|
40
|
+
return val !== null && val !== baseline;
|
|
41
|
+
},
|
|
49
42
|
},
|
|
50
43
|
};
|
|
51
44
|
|
|
@@ -181,7 +174,14 @@ export class BrowserLoginSession {
|
|
|
181
174
|
|
|
182
175
|
await this.send('Page.navigate', { url: this._config.loginUrl });
|
|
183
176
|
|
|
184
|
-
|
|
177
|
+
// Wait for page to settle, then record baseline session cookie value.
|
|
178
|
+
// XHS sets an anonymous web_session on first visit — we only trigger login_complete
|
|
179
|
+
// when the value CHANGES (real login replaces it with an authenticated session).
|
|
180
|
+
await sleep(4000);
|
|
181
|
+
const baselineCookies = await this.send('Network.getAllCookies', {});
|
|
182
|
+
const baselineSession = this._config.getSessionValue(baselineCookies.cookies ?? []);
|
|
183
|
+
|
|
184
|
+
this._startPolling(connection, baselineSession);
|
|
185
185
|
}
|
|
186
186
|
|
|
187
187
|
_connect(wsUrl) {
|
|
@@ -225,12 +225,12 @@ export class BrowserLoginSession {
|
|
|
225
225
|
return result.data;
|
|
226
226
|
}
|
|
227
227
|
|
|
228
|
-
async isLoggedIn() {
|
|
228
|
+
async isLoggedIn(baseline) {
|
|
229
229
|
const result = await this.send('Network.getAllCookies', {});
|
|
230
|
-
return this._config.isLoggedIn(result.cookies ?? []);
|
|
230
|
+
return this._config.isLoggedIn(result.cookies ?? [], baseline);
|
|
231
231
|
}
|
|
232
232
|
|
|
233
|
-
_startPolling(connection) {
|
|
233
|
+
_startPolling(connection, baselineSession) {
|
|
234
234
|
let _screenshotInProgress = false;
|
|
235
235
|
this._screenshotTimer = setInterval(async () => {
|
|
236
236
|
if (_screenshotInProgress) return;
|
|
@@ -247,7 +247,7 @@ export class BrowserLoginSession {
|
|
|
247
247
|
|
|
248
248
|
this._loginCheckTimer = setInterval(async () => {
|
|
249
249
|
try {
|
|
250
|
-
const loggedIn = await this.isLoggedIn();
|
|
250
|
+
const loggedIn = await this.isLoggedIn(baselineSession);
|
|
251
251
|
if (loggedIn) {
|
|
252
252
|
this._stopTimers();
|
|
253
253
|
connection.send({ type: 'browser:login_complete', platform: this._platform, profileDir: this._profileDir });
|