tt-help-cli-ycl 1.3.76 → 1.3.78
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/cli/open.js +2 -2
- package/src/lib/browser/cdp.js +10 -8
- package/src/lib/browser/page.js +2 -2
package/package.json
CHANGED
package/src/cli/open.js
CHANGED
|
@@ -94,8 +94,8 @@ export async function handleOpen(parsed) {
|
|
|
94
94
|
process.on("SIGINT", async () => {
|
|
95
95
|
console.error("\n正在关闭浏览器...");
|
|
96
96
|
try {
|
|
97
|
-
console.error(`[SIGINT] 正在终止 Edge 进程 (
|
|
98
|
-
await killEdgeProcesses(userDataDir);
|
|
97
|
+
console.error(`[SIGINT] 正在终止 Edge 进程 (端口: ${port})`);
|
|
98
|
+
await killEdgeProcesses(userDataDir, port);
|
|
99
99
|
console.error("[SIGINT] Edge 进程已终止,正在关闭浏览器连接...");
|
|
100
100
|
await browser.close();
|
|
101
101
|
} catch (e) {
|
package/src/lib/browser/cdp.js
CHANGED
|
@@ -70,7 +70,7 @@ function checkEdgeArgs() {
|
|
|
70
70
|
});
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
function killEdgeProcesses(targetDir) {
|
|
73
|
+
function killEdgeProcesses(targetDir, port) {
|
|
74
74
|
return new Promise((resolve) => {
|
|
75
75
|
const platform = os.platform();
|
|
76
76
|
let command;
|
|
@@ -102,16 +102,16 @@ function killEdgeProcesses(targetDir) {
|
|
|
102
102
|
'killall -9 "Microsoft Edge" 2>/dev/null; rm -f ~/Library/Caches/Microsoft\\ Edge/Singleton*; true';
|
|
103
103
|
}
|
|
104
104
|
} else if (platform === "win32") {
|
|
105
|
-
if (
|
|
105
|
+
if (port) {
|
|
106
|
+
// 用端口匹配(纯数字,无编码问题),而不是 userDataDir 路径(中文路径会乱码)
|
|
106
107
|
try {
|
|
107
108
|
const ps1Path = path.join(os.tmpdir(), `kill-edge-${Date.now()}.ps1`);
|
|
108
|
-
const escapedDir = targetDir.replace(/'/g, "''");
|
|
109
109
|
const ps1Content =
|
|
110
110
|
`$procs = Get-CimInstance Win32_Process -Filter "Name='msedge.exe'" 2>$null; ` +
|
|
111
111
|
`$count = 0; ` +
|
|
112
112
|
`$pids = @(); ` +
|
|
113
113
|
`foreach ($p in $procs) { ` +
|
|
114
|
-
` if ($p.CommandLine -and $p.CommandLine -like "
|
|
114
|
+
` if ($p.CommandLine -and $p.CommandLine -like "*--remote-debugging-port=${port}*") { ` +
|
|
115
115
|
` $pids += $p.ProcessId; ` +
|
|
116
116
|
` Stop-Process -Id $p.ProcessId -Force -ErrorAction SilentlyContinue; ` +
|
|
117
117
|
` $count++ ` +
|
|
@@ -128,7 +128,9 @@ function killEdgeProcesses(targetDir) {
|
|
|
128
128
|
.toString()
|
|
129
129
|
.trim();
|
|
130
130
|
console.error(`[killEdgeProcesses] Windows PS result: ${result}`);
|
|
131
|
-
try {
|
|
131
|
+
try {
|
|
132
|
+
fs.unlinkSync(ps1Path);
|
|
133
|
+
} catch {}
|
|
132
134
|
command = "exit 0";
|
|
133
135
|
} catch (e) {
|
|
134
136
|
console.error(`[killEdgeProcesses] Windows PS failed: ${e.message}`);
|
|
@@ -218,7 +220,7 @@ export async function ensureBrowserReady(options = {}) {
|
|
|
218
220
|
const edgeArgsValid = await checkEdgeArgs();
|
|
219
221
|
if (!edgeArgsValid) {
|
|
220
222
|
console.error(`Edge 已运行但启动参数不完整,正在重启端口 ${port}...`);
|
|
221
|
-
await killEdgeProcesses(userDataDir);
|
|
223
|
+
await killEdgeProcesses(userDataDir, port);
|
|
222
224
|
await new Promise((r) => setTimeout(r, 3000));
|
|
223
225
|
needLaunch = true;
|
|
224
226
|
}
|
|
@@ -234,7 +236,7 @@ export async function ensureBrowserReady(options = {}) {
|
|
|
234
236
|
const edgeRunning = await isEdgeRunning();
|
|
235
237
|
if (edgeRunning) {
|
|
236
238
|
console.error(`Edge 已运行但 CDP 端口 ${port} 未启用,正在重启...`);
|
|
237
|
-
await killEdgeProcesses(userDataDir);
|
|
239
|
+
await killEdgeProcesses(userDataDir, port);
|
|
238
240
|
await new Promise((r) => setTimeout(r, 3000));
|
|
239
241
|
} else {
|
|
240
242
|
console.error(`CDP 端口 ${port} 未就绪,正在启动 Edge 浏览器...`);
|
|
@@ -262,7 +264,7 @@ export async function switchAccount(oldAccount, newAccount, proxyServer) {
|
|
|
262
264
|
console.error(` [账户切换] 等待 30 秒,请完成当前操作后自动切换...`);
|
|
263
265
|
await new Promise((r) => setTimeout(r, 30000));
|
|
264
266
|
|
|
265
|
-
await killEdgeProcesses(oldAccount.userDataDir);
|
|
267
|
+
await killEdgeProcesses(oldAccount.userDataDir, oldAccount.port);
|
|
266
268
|
await new Promise((r) => setTimeout(r, 3000));
|
|
267
269
|
|
|
268
270
|
const newCdpOptions = {};
|
package/src/lib/browser/page.js
CHANGED
|
@@ -31,7 +31,7 @@ export async function relaunchBrowser(cdpOptions, port) {
|
|
|
31
31
|
console.error(` [浏览器] 浏览器已关闭,正在重启 (端口 ${port})...`);
|
|
32
32
|
const targetDir = cdpOptions.userDataDir || DEFAULT_USER_DATA_DIR;
|
|
33
33
|
// kill 并清理 Singleton 锁文件,确保 Edge 能启动新实例
|
|
34
|
-
await killEdgeProcesses(targetDir);
|
|
34
|
+
await killEdgeProcesses(targetDir, port);
|
|
35
35
|
await new Promise((r) => setTimeout(r, 3000));
|
|
36
36
|
// 确保端口已释放后再启动
|
|
37
37
|
let retries = 0;
|
|
@@ -43,7 +43,7 @@ export async function relaunchBrowser(cdpOptions, port) {
|
|
|
43
43
|
retries++;
|
|
44
44
|
console.error(` [浏览器] CDP 连接异常,重试 ${retries}/5...`);
|
|
45
45
|
await new Promise((r) => setTimeout(r, 3000));
|
|
46
|
-
await killEdgeProcesses(targetDir);
|
|
46
|
+
await killEdgeProcesses(targetDir, port);
|
|
47
47
|
await new Promise((r) => setTimeout(r, 5000));
|
|
48
48
|
continue;
|
|
49
49
|
}
|