@web-auto/camo 0.2.0 → 0.2.1
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/LICENSE +21 -21
- package/README.md +586 -586
- package/bin/browser-service.mjs +11 -11
- package/bin/camo.mjs +22 -22
- package/package.json +48 -48
- package/scripts/build.mjs +19 -19
- package/scripts/bump-version.mjs +34 -34
- package/scripts/check-file-size.mjs +80 -80
- package/scripts/file-size-policy.json +12 -2
- package/scripts/install.mjs +76 -76
- package/scripts/release.sh +54 -54
- package/src/autoscript/action-providers/index.mjs +6 -6
- package/src/autoscript/impact-engine.mjs +78 -78
- package/src/autoscript/runtime.mjs +1017 -1017
- package/src/autoscript/schema.mjs +376 -376
- package/src/cli.mjs +405 -405
- package/src/commands/attach.mjs +141 -141
- package/src/commands/autoscript.mjs +1011 -1011
- package/src/commands/browser.mjs +1255 -1255
- package/src/commands/container.mjs +401 -401
- package/src/commands/cookies.mjs +69 -69
- package/src/commands/create.mjs +98 -98
- package/src/commands/devtools.mjs +349 -349
- package/src/commands/events.mjs +152 -152
- package/src/commands/highlight-mode.mjs +24 -24
- package/src/commands/init.mjs +68 -68
- package/src/commands/lifecycle.mjs +275 -275
- package/src/commands/mouse.mjs +45 -45
- package/src/commands/profile.mjs +46 -46
- package/src/commands/record.mjs +115 -115
- package/src/commands/system.mjs +14 -14
- package/src/commands/window.mjs +123 -123
- package/src/container/change-notifier.mjs +362 -362
- package/src/container/element-filter.mjs +143 -143
- package/src/container/index.mjs +3 -3
- package/src/container/runtime-core/checkpoint.mjs +209 -209
- package/src/container/runtime-core/index.mjs +21 -21
- package/src/container/runtime-core/operations/index.mjs +774 -774
- package/src/container/runtime-core/operations/selector-scripts.mjs +277 -277
- package/src/container/runtime-core/operations/tab-pool.mjs +746 -746
- package/src/container/runtime-core/operations/viewport.mjs +189 -189
- package/src/container/runtime-core/search.mjs +190 -190
- package/src/container/runtime-core/subscription.mjs +224 -224
- package/src/container/runtime-core/utils.mjs +94 -94
- package/src/container/runtime-core/validation.mjs +127 -127
- package/src/container/runtime-core.mjs +1 -1
- package/src/container/subscription-registry.mjs +459 -459
- package/src/core/actions.mjs +561 -561
- package/src/core/browser.mjs +266 -266
- package/src/core/index.mjs +52 -52
- package/src/core/utils.mjs +91 -91
- package/src/events/daemon-entry.mjs +33 -33
- package/src/events/daemon.mjs +80 -80
- package/src/events/progress-log.mjs +109 -109
- package/src/events/ws-server.mjs +239 -239
- package/src/lib/client.mjs +200 -200
- package/src/lifecycle/cleanup.mjs +83 -83
- package/src/lifecycle/lock.mjs +126 -126
- package/src/lifecycle/session-registry.mjs +279 -279
- package/src/lifecycle/session-view.mjs +76 -76
- package/src/lifecycle/session-watchdog.mjs +281 -281
- package/src/services/browser-service/index.js +671 -671
- package/src/services/browser-service/internal/BrowserSession.input.test.js +389 -389
- package/src/services/browser-service/internal/BrowserSession.js +325 -304
- package/src/services/browser-service/internal/ElementRegistry.js +60 -60
- package/src/services/browser-service/internal/ProfileLock.js +84 -84
- package/src/services/browser-service/internal/SessionManager.js +184 -184
- package/src/services/browser-service/internal/SessionManager.test.js +39 -39
- package/src/services/browser-service/internal/browser-session/cookies.js +144 -144
- package/src/services/browser-service/internal/browser-session/input-ops.js +222 -222
- package/src/services/browser-service/internal/browser-session/input-pipeline.js +144 -144
- package/src/services/browser-service/internal/browser-session/logging.js +46 -46
- package/src/services/browser-service/internal/browser-session/navigation.js +38 -38
- package/src/services/browser-service/internal/browser-session/page-hooks.js +442 -442
- package/src/services/browser-service/internal/browser-session/page-management.js +302 -302
- package/src/services/browser-service/internal/browser-session/page-management.test.js +148 -148
- package/src/services/browser-service/internal/browser-session/recording.js +198 -198
- package/src/services/browser-service/internal/browser-session/runtime-events.js +61 -61
- package/src/services/browser-service/internal/browser-session/session-core.js +84 -84
- package/src/services/browser-service/internal/browser-session/session-state.js +38 -38
- package/src/services/browser-service/internal/browser-session/types.js +14 -14
- package/src/services/browser-service/internal/browser-session/utils.js +95 -95
- package/src/services/browser-service/internal/browser-session/viewport-manager.js +46 -46
- package/src/services/browser-service/internal/browser-session/viewport.js +215 -215
- package/src/services/browser-service/internal/container-matcher.js +851 -851
- package/src/services/browser-service/internal/container-registry.js +182 -182
- package/src/services/browser-service/internal/engine-manager.js +259 -259
- package/src/services/browser-service/internal/fingerprint.js +203 -203
- package/src/services/browser-service/internal/heartbeat.js +137 -137
- package/src/services/browser-service/internal/logging.js +46 -46
- package/src/services/browser-service/internal/page-runtime/runtime.js +1317 -1317
- package/src/services/browser-service/internal/pageRuntime.js +28 -28
- package/src/services/browser-service/internal/runtimeInjector.js +31 -31
- package/src/services/browser-service/internal/service-process-logger.js +140 -140
- package/src/services/browser-service/internal/state-bus.js +45 -45
- package/src/services/browser-service/internal/storage-paths.js +42 -42
- package/src/services/browser-service/internal/ws-server.js +1194 -1194
- package/src/services/browser-service/internal/ws-server.test.js +58 -58
- package/src/services/browser-service/server.mjs +6 -6
- package/src/services/controller/cli-bridge.js +93 -93
- package/src/services/controller/container-index.js +50 -50
- package/src/services/controller/container-storage.js +36 -36
- package/src/services/controller/controller-actions.js +207 -207
- package/src/services/controller/controller.js +1138 -1138
- package/src/services/controller/selectors.js +54 -54
- package/src/services/controller/transport.js +125 -125
- package/src/utils/args.mjs +26 -26
- package/src/utils/browser-service.mjs +544 -544
- package/src/utils/command-log.mjs +64 -64
- package/src/utils/config.mjs +214 -214
- package/src/utils/fingerprint.mjs +181 -181
- package/src/utils/help.mjs +216 -216
- package/src/utils/js-policy.mjs +13 -13
- package/src/utils/ws-client.mjs +30 -30
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import test from 'node:test';
|
|
2
|
-
import assert from 'node:assert/strict';
|
|
3
|
-
import { SessionManager } from './SessionManager.js';
|
|
4
|
-
test('createSession closes session when start fails', async () => {
|
|
5
|
-
let closeCalled = 0;
|
|
6
|
-
const fakeSession = {
|
|
7
|
-
id: 'start-fail-profile',
|
|
8
|
-
modeName: 'dev',
|
|
9
|
-
onExit: undefined,
|
|
10
|
-
async start() {
|
|
11
|
-
throw new Error('start_failed');
|
|
12
|
-
},
|
|
13
|
-
async close() {
|
|
14
|
-
closeCalled += 1;
|
|
15
|
-
},
|
|
16
|
-
getCurrentUrl() {
|
|
17
|
-
return null;
|
|
18
|
-
},
|
|
19
|
-
getRecordingStatus() {
|
|
20
|
-
return {
|
|
21
|
-
active: false,
|
|
22
|
-
enabled: false,
|
|
23
|
-
name: null,
|
|
24
|
-
outputPath: null,
|
|
25
|
-
overlay: false,
|
|
26
|
-
startedAt: null,
|
|
27
|
-
endedAt: null,
|
|
28
|
-
eventCount: 0,
|
|
29
|
-
lastEventAt: null,
|
|
30
|
-
lastError: null,
|
|
31
|
-
};
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
const manager = new SessionManager({ ownerWatchdogMs: 60_000 }, () => fakeSession);
|
|
35
|
-
await assert.rejects(async () => manager.createSession({ profileId: 'start-fail-profile' }), /start_failed/);
|
|
36
|
-
assert.equal(closeCalled, 1);
|
|
37
|
-
assert.equal(manager.getSession('start-fail-profile'), undefined);
|
|
38
|
-
await manager.shutdown();
|
|
39
|
-
});
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { SessionManager } from './SessionManager.js';
|
|
4
|
+
test('createSession closes session when start fails', async () => {
|
|
5
|
+
let closeCalled = 0;
|
|
6
|
+
const fakeSession = {
|
|
7
|
+
id: 'start-fail-profile',
|
|
8
|
+
modeName: 'dev',
|
|
9
|
+
onExit: undefined,
|
|
10
|
+
async start() {
|
|
11
|
+
throw new Error('start_failed');
|
|
12
|
+
},
|
|
13
|
+
async close() {
|
|
14
|
+
closeCalled += 1;
|
|
15
|
+
},
|
|
16
|
+
getCurrentUrl() {
|
|
17
|
+
return null;
|
|
18
|
+
},
|
|
19
|
+
getRecordingStatus() {
|
|
20
|
+
return {
|
|
21
|
+
active: false,
|
|
22
|
+
enabled: false,
|
|
23
|
+
name: null,
|
|
24
|
+
outputPath: null,
|
|
25
|
+
overlay: false,
|
|
26
|
+
startedAt: null,
|
|
27
|
+
endedAt: null,
|
|
28
|
+
eventCount: 0,
|
|
29
|
+
lastEventAt: null,
|
|
30
|
+
lastError: null,
|
|
31
|
+
};
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
const manager = new SessionManager({ ownerWatchdogMs: 60_000 }, () => fakeSession);
|
|
35
|
+
await assert.rejects(async () => manager.createSession({ profileId: 'start-fail-profile' }), /start_failed/);
|
|
36
|
+
assert.equal(closeCalled, 1);
|
|
37
|
+
assert.equal(manager.getSession('start-fail-profile'), undefined);
|
|
38
|
+
await manager.shutdown();
|
|
39
|
+
});
|
|
40
40
|
//# sourceMappingURL=SessionManager.test.js.map
|
|
@@ -1,145 +1,145 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import crypto from 'node:crypto';
|
|
4
|
-
import { resolveCookiesRoot } from '../storage-paths.js';
|
|
5
|
-
export class BrowserSessionCookies {
|
|
6
|
-
profileId;
|
|
7
|
-
getContext;
|
|
8
|
-
getActivePage;
|
|
9
|
-
lastCookieSignature = null;
|
|
10
|
-
lastCookieSaveTs = 0;
|
|
11
|
-
constructor(profileId, getContext, getActivePage) {
|
|
12
|
-
this.profileId = profileId;
|
|
13
|
-
this.getContext = getContext;
|
|
14
|
-
this.getActivePage = getActivePage;
|
|
15
|
-
}
|
|
16
|
-
async getCookies() {
|
|
17
|
-
const context = this.getContext();
|
|
18
|
-
if (!context)
|
|
19
|
-
return [];
|
|
20
|
-
return context.cookies();
|
|
21
|
-
}
|
|
22
|
-
async saveCookiesForActivePage() {
|
|
23
|
-
const context = this.getContext();
|
|
24
|
-
if (!context)
|
|
25
|
-
return [];
|
|
26
|
-
const page = this.getActivePage();
|
|
27
|
-
if (!page)
|
|
28
|
-
return [];
|
|
29
|
-
const cookies = await context.cookies();
|
|
30
|
-
if (!cookies.length)
|
|
31
|
-
return [];
|
|
32
|
-
const digest = this.hashCookies(cookies);
|
|
33
|
-
const now = Date.now();
|
|
34
|
-
if (digest === this.lastCookieSignature && now - this.lastCookieSaveTs < 2000) {
|
|
35
|
-
return [];
|
|
36
|
-
}
|
|
37
|
-
const targets = this.resolveCookieTargets(page.url());
|
|
38
|
-
if (!targets.length)
|
|
39
|
-
return [];
|
|
40
|
-
const payload = JSON.stringify({
|
|
41
|
-
timestamp: now,
|
|
42
|
-
profileId: this.profileId,
|
|
43
|
-
url: page.url(),
|
|
44
|
-
cookies,
|
|
45
|
-
}, null, 2);
|
|
46
|
-
const results = [];
|
|
47
|
-
for (const target of targets) {
|
|
48
|
-
await fs.promises.mkdir(path.dirname(target), { recursive: true });
|
|
49
|
-
await fs.promises.writeFile(target, payload, 'utf-8');
|
|
50
|
-
results.push({ path: target, count: cookies.length });
|
|
51
|
-
}
|
|
52
|
-
this.lastCookieSignature = digest;
|
|
53
|
-
this.lastCookieSaveTs = now;
|
|
54
|
-
return results;
|
|
55
|
-
}
|
|
56
|
-
async saveCookiesToFile(filePath) {
|
|
57
|
-
const cookies = await this.getCookies();
|
|
58
|
-
await fs.promises.mkdir(path.dirname(filePath), { recursive: true });
|
|
59
|
-
await fs.promises.writeFile(filePath, JSON.stringify({ timestamp: Date.now(), cookies }, null, 2), 'utf-8');
|
|
60
|
-
return { path: filePath, count: cookies.length };
|
|
61
|
-
}
|
|
62
|
-
async saveCookiesIfStable(filePath, opts = {}) {
|
|
63
|
-
const minDelayMs = Math.max(1000, Number(opts.minDelayMs) || 2000);
|
|
64
|
-
const page = this.getActivePage();
|
|
65
|
-
if (!page)
|
|
66
|
-
return null;
|
|
67
|
-
const html = await page.content();
|
|
68
|
-
const isLoggedIn = html.includes('Frame_wrap_') && !html.includes('LoginCard') && !html.includes('passport');
|
|
69
|
-
if (!isLoggedIn)
|
|
70
|
-
return null;
|
|
71
|
-
const cookies = await this.getCookies();
|
|
72
|
-
if (!cookies.length)
|
|
73
|
-
return null;
|
|
74
|
-
const digest = this.hashCookies(cookies);
|
|
75
|
-
const now = Date.now();
|
|
76
|
-
if (digest === this.lastCookieSignature && now - this.lastCookieSaveTs < minDelayMs) {
|
|
77
|
-
return null;
|
|
78
|
-
}
|
|
79
|
-
await fs.promises.mkdir(path.dirname(filePath), { recursive: true });
|
|
80
|
-
await fs.promises.writeFile(filePath, JSON.stringify({ timestamp: now, cookies }, null, 2), 'utf-8');
|
|
81
|
-
this.lastCookieSignature = digest;
|
|
82
|
-
this.lastCookieSaveTs = now;
|
|
83
|
-
return { path: filePath, count: cookies.length };
|
|
84
|
-
}
|
|
85
|
-
async injectCookiesFromFile(filePath) {
|
|
86
|
-
const context = this.getContext();
|
|
87
|
-
if (!context)
|
|
88
|
-
throw new Error('context not ready');
|
|
89
|
-
const raw = JSON.parse(await fs.promises.readFile(filePath, 'utf-8'));
|
|
90
|
-
const cookies = Array.isArray(raw) ? raw : Array.isArray(raw?.cookies) ? raw.cookies : [];
|
|
91
|
-
if (!cookies.length)
|
|
92
|
-
return { count: 0 };
|
|
93
|
-
await context.addCookies(cookies);
|
|
94
|
-
return { count: cookies.length };
|
|
95
|
-
}
|
|
96
|
-
resolveCookieTargets(currentUrl) {
|
|
97
|
-
const cookieDir = resolveCookiesRoot();
|
|
98
|
-
const targets = new Set([path.join(cookieDir, `${this.profileId}.json`)]);
|
|
99
|
-
if (currentUrl) {
|
|
100
|
-
try {
|
|
101
|
-
const { hostname } = new URL(currentUrl);
|
|
102
|
-
const hostSegment = this.sanitizeHost(hostname);
|
|
103
|
-
if (hostSegment) {
|
|
104
|
-
targets.add(path.join(cookieDir, `${hostSegment}-latest.json`));
|
|
105
|
-
}
|
|
106
|
-
if (hostname && hostname.includes('weibo')) {
|
|
107
|
-
targets.add(path.join(cookieDir, 'weibo.com-latest.json'));
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
catch {
|
|
111
|
-
targets.add(path.join(cookieDir, 'default-latest.json'));
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return Array.from(targets);
|
|
115
|
-
}
|
|
116
|
-
sanitizeHost(host) {
|
|
117
|
-
if (!host)
|
|
118
|
-
return 'default';
|
|
119
|
-
return host.replace(/[^a-z0-9.-]/gi, '_');
|
|
120
|
-
}
|
|
121
|
-
hashCookies(cookies) {
|
|
122
|
-
const normalized = cookies
|
|
123
|
-
.map((c) => ({
|
|
124
|
-
name: c.name,
|
|
125
|
-
value: c.value,
|
|
126
|
-
domain: c.domain,
|
|
127
|
-
path: c.path,
|
|
128
|
-
expires: c.expires,
|
|
129
|
-
httpOnly: !!c.httpOnly,
|
|
130
|
-
secure: !!c.secure,
|
|
131
|
-
}))
|
|
132
|
-
.sort((a, b) => {
|
|
133
|
-
if (a.domain === b.domain) {
|
|
134
|
-
if (a.name === b.name)
|
|
135
|
-
return (a.path || '').localeCompare(b.path || '');
|
|
136
|
-
return a.name.localeCompare(b.name);
|
|
137
|
-
}
|
|
138
|
-
return (a.domain || '').localeCompare(b.domain || '');
|
|
139
|
-
});
|
|
140
|
-
const hash = crypto.createHash('sha1');
|
|
141
|
-
hash.update(JSON.stringify(normalized));
|
|
142
|
-
return hash.digest('hex');
|
|
143
|
-
}
|
|
144
|
-
}
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import crypto from 'node:crypto';
|
|
4
|
+
import { resolveCookiesRoot } from '../storage-paths.js';
|
|
5
|
+
export class BrowserSessionCookies {
|
|
6
|
+
profileId;
|
|
7
|
+
getContext;
|
|
8
|
+
getActivePage;
|
|
9
|
+
lastCookieSignature = null;
|
|
10
|
+
lastCookieSaveTs = 0;
|
|
11
|
+
constructor(profileId, getContext, getActivePage) {
|
|
12
|
+
this.profileId = profileId;
|
|
13
|
+
this.getContext = getContext;
|
|
14
|
+
this.getActivePage = getActivePage;
|
|
15
|
+
}
|
|
16
|
+
async getCookies() {
|
|
17
|
+
const context = this.getContext();
|
|
18
|
+
if (!context)
|
|
19
|
+
return [];
|
|
20
|
+
return context.cookies();
|
|
21
|
+
}
|
|
22
|
+
async saveCookiesForActivePage() {
|
|
23
|
+
const context = this.getContext();
|
|
24
|
+
if (!context)
|
|
25
|
+
return [];
|
|
26
|
+
const page = this.getActivePage();
|
|
27
|
+
if (!page)
|
|
28
|
+
return [];
|
|
29
|
+
const cookies = await context.cookies();
|
|
30
|
+
if (!cookies.length)
|
|
31
|
+
return [];
|
|
32
|
+
const digest = this.hashCookies(cookies);
|
|
33
|
+
const now = Date.now();
|
|
34
|
+
if (digest === this.lastCookieSignature && now - this.lastCookieSaveTs < 2000) {
|
|
35
|
+
return [];
|
|
36
|
+
}
|
|
37
|
+
const targets = this.resolveCookieTargets(page.url());
|
|
38
|
+
if (!targets.length)
|
|
39
|
+
return [];
|
|
40
|
+
const payload = JSON.stringify({
|
|
41
|
+
timestamp: now,
|
|
42
|
+
profileId: this.profileId,
|
|
43
|
+
url: page.url(),
|
|
44
|
+
cookies,
|
|
45
|
+
}, null, 2);
|
|
46
|
+
const results = [];
|
|
47
|
+
for (const target of targets) {
|
|
48
|
+
await fs.promises.mkdir(path.dirname(target), { recursive: true });
|
|
49
|
+
await fs.promises.writeFile(target, payload, 'utf-8');
|
|
50
|
+
results.push({ path: target, count: cookies.length });
|
|
51
|
+
}
|
|
52
|
+
this.lastCookieSignature = digest;
|
|
53
|
+
this.lastCookieSaveTs = now;
|
|
54
|
+
return results;
|
|
55
|
+
}
|
|
56
|
+
async saveCookiesToFile(filePath) {
|
|
57
|
+
const cookies = await this.getCookies();
|
|
58
|
+
await fs.promises.mkdir(path.dirname(filePath), { recursive: true });
|
|
59
|
+
await fs.promises.writeFile(filePath, JSON.stringify({ timestamp: Date.now(), cookies }, null, 2), 'utf-8');
|
|
60
|
+
return { path: filePath, count: cookies.length };
|
|
61
|
+
}
|
|
62
|
+
async saveCookiesIfStable(filePath, opts = {}) {
|
|
63
|
+
const minDelayMs = Math.max(1000, Number(opts.minDelayMs) || 2000);
|
|
64
|
+
const page = this.getActivePage();
|
|
65
|
+
if (!page)
|
|
66
|
+
return null;
|
|
67
|
+
const html = await page.content();
|
|
68
|
+
const isLoggedIn = html.includes('Frame_wrap_') && !html.includes('LoginCard') && !html.includes('passport');
|
|
69
|
+
if (!isLoggedIn)
|
|
70
|
+
return null;
|
|
71
|
+
const cookies = await this.getCookies();
|
|
72
|
+
if (!cookies.length)
|
|
73
|
+
return null;
|
|
74
|
+
const digest = this.hashCookies(cookies);
|
|
75
|
+
const now = Date.now();
|
|
76
|
+
if (digest === this.lastCookieSignature && now - this.lastCookieSaveTs < minDelayMs) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
await fs.promises.mkdir(path.dirname(filePath), { recursive: true });
|
|
80
|
+
await fs.promises.writeFile(filePath, JSON.stringify({ timestamp: now, cookies }, null, 2), 'utf-8');
|
|
81
|
+
this.lastCookieSignature = digest;
|
|
82
|
+
this.lastCookieSaveTs = now;
|
|
83
|
+
return { path: filePath, count: cookies.length };
|
|
84
|
+
}
|
|
85
|
+
async injectCookiesFromFile(filePath) {
|
|
86
|
+
const context = this.getContext();
|
|
87
|
+
if (!context)
|
|
88
|
+
throw new Error('context not ready');
|
|
89
|
+
const raw = JSON.parse(await fs.promises.readFile(filePath, 'utf-8'));
|
|
90
|
+
const cookies = Array.isArray(raw) ? raw : Array.isArray(raw?.cookies) ? raw.cookies : [];
|
|
91
|
+
if (!cookies.length)
|
|
92
|
+
return { count: 0 };
|
|
93
|
+
await context.addCookies(cookies);
|
|
94
|
+
return { count: cookies.length };
|
|
95
|
+
}
|
|
96
|
+
resolveCookieTargets(currentUrl) {
|
|
97
|
+
const cookieDir = resolveCookiesRoot();
|
|
98
|
+
const targets = new Set([path.join(cookieDir, `${this.profileId}.json`)]);
|
|
99
|
+
if (currentUrl) {
|
|
100
|
+
try {
|
|
101
|
+
const { hostname } = new URL(currentUrl);
|
|
102
|
+
const hostSegment = this.sanitizeHost(hostname);
|
|
103
|
+
if (hostSegment) {
|
|
104
|
+
targets.add(path.join(cookieDir, `${hostSegment}-latest.json`));
|
|
105
|
+
}
|
|
106
|
+
if (hostname && hostname.includes('weibo')) {
|
|
107
|
+
targets.add(path.join(cookieDir, 'weibo.com-latest.json'));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
targets.add(path.join(cookieDir, 'default-latest.json'));
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return Array.from(targets);
|
|
115
|
+
}
|
|
116
|
+
sanitizeHost(host) {
|
|
117
|
+
if (!host)
|
|
118
|
+
return 'default';
|
|
119
|
+
return host.replace(/[^a-z0-9.-]/gi, '_');
|
|
120
|
+
}
|
|
121
|
+
hashCookies(cookies) {
|
|
122
|
+
const normalized = cookies
|
|
123
|
+
.map((c) => ({
|
|
124
|
+
name: c.name,
|
|
125
|
+
value: c.value,
|
|
126
|
+
domain: c.domain,
|
|
127
|
+
path: c.path,
|
|
128
|
+
expires: c.expires,
|
|
129
|
+
httpOnly: !!c.httpOnly,
|
|
130
|
+
secure: !!c.secure,
|
|
131
|
+
}))
|
|
132
|
+
.sort((a, b) => {
|
|
133
|
+
if (a.domain === b.domain) {
|
|
134
|
+
if (a.name === b.name)
|
|
135
|
+
return (a.path || '').localeCompare(b.path || '');
|
|
136
|
+
return a.name.localeCompare(b.name);
|
|
137
|
+
}
|
|
138
|
+
return (a.domain || '').localeCompare(b.domain || '');
|
|
139
|
+
});
|
|
140
|
+
const hash = crypto.createHash('sha1');
|
|
141
|
+
hash.update(JSON.stringify(normalized));
|
|
142
|
+
return hash.digest('hex');
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
145
|
//# sourceMappingURL=cookies.js.map
|