tt-help-cli-ycl 1.4.124 → 1.4.125

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": "tt-help-cli-ycl",
3
- "version": "1.4.124",
3
+ "version": "1.4.125",
4
4
  "description": "TikTok user & video data scraper - extract ttSeller, verified, locationCreated from HTML source",
5
5
  "type": "module",
6
6
  "bin": {
package/src/cli/open.js CHANGED
@@ -93,14 +93,20 @@ export async function handleOpen(parsed) {
93
93
  // Ctrl+C 关闭浏览器
94
94
  process.on("SIGINT", async () => {
95
95
  console.error("\n正在关闭浏览器...");
96
+ // 先优雅断开 CDP 连接(带 3s 超时保护):进程已被强杀时 close() 会挂起等 close 事件
96
97
  try {
97
- console.error(`[SIGINT] 正在终止 Edge 进程 (端口: ${port})`);
98
- await killEdgeProcesses(userDataDir, port);
99
- console.error("[SIGINT] Edge 进程已终止,正在关闭浏览器连接...");
100
- await browser.close();
98
+ await Promise.race([
99
+ browser.close(),
100
+ new Promise((r) => setTimeout(r, 3000)),
101
+ ]);
101
102
  } catch (e) {
102
- console.error(`[SIGINT] 关闭浏览器时出错: ${e.message}`);
103
+ console.error(`[SIGINT] 断开浏览器连接时出错: ${e.message}`);
103
104
  }
105
+ // 再强杀 Edge 进程兜底(优雅关闭不保证退出浏览器进程)
106
+ console.error(`[SIGINT] 正在终止 Edge 进程 (端口: ${port})`);
107
+ await killEdgeProcesses(userDataDir, port).catch((e) => {
108
+ console.error(`[SIGINT] 终止 Edge 进程失败: ${e.message}`);
109
+ });
104
110
  console.error("浏览器已关闭");
105
111
  process.exit(0);
106
112
  });
@@ -150,8 +150,9 @@ function killEdgeProcesses(targetDir, port) {
150
150
  });
151
151
  const pids = parseNetstatListeningPids(netstatOut, port);
152
152
  if (pids.length > 0) {
153
+ // 不重定向 stderr:taskkill 的错误信息(拒绝访问/找不到进程)需要可见
153
154
  killCmds = pids
154
- .map((pid) => `taskkill /F /T /PID ${pid} 2>nul`)
155
+ .map((pid) => `taskkill /F /T /PID ${pid}`)
155
156
  .join(" & ");
156
157
  console.error(
157
158
  `[killEdgeProcesses] 端口 ${port} 监听进程 PID: ${pids.join(", ")}`,
@@ -160,10 +161,27 @@ function killEdgeProcesses(targetDir, port) {
160
161
  } catch (e) {
161
162
  console.error(`[killEdgeProcesses] netstat 查询失败: ${e.message}`);
162
163
  }
164
+ if (killCmds) {
165
+ // 同步执行并打印结果:taskkill 失败(权限/会话不匹配等)必须可见,不能静默吞掉
166
+ const killCmd = `(${killCmds})`;
167
+ try {
168
+ const out = execSync(killCmd, {
169
+ encoding: "utf-8",
170
+ timeout: 15000,
171
+ windowsHide: true,
172
+ });
173
+ const lines = out.trim().split(/\r?\n/).filter(Boolean);
174
+ console.error(
175
+ `[killEdgeProcesses] taskkill 结果: ${lines.join(" | ") || "(无输出)"}`,
176
+ );
177
+ } catch (e) {
178
+ console.error(`[killEdgeProcesses] taskkill 失败: ${e.message}`);
179
+ const detail = `${e.stdout || ""}${e.stderr || ""}`.trim();
180
+ if (detail) console.error(`[killEdgeProcesses] 详情: ${detail}`);
181
+ }
182
+ }
163
183
  // 找不到监听进程 = 浏览器可能已退出,不做按进程名的兜底(避免误杀其他端口实例)
164
- command = killCmds
165
- ? `(${killCmds}); del /f /q "%LOCALAPPDATA%\\Microsoft\\Edge\\Singleton*" 2>nul; exit 0`
166
- : "exit 0";
184
+ command = `del /f /q "%LOCALAPPDATA%\\Microsoft\\Edge\\Singleton*" 2>nul; exit 0`;
167
185
  } else {
168
186
  command = "taskkill /F /IM msedge.exe 2>nul || exit 0";
169
187
  }
@@ -467,7 +467,9 @@ async function listWatchdogPids() {
467
467
  .map((s) => parseInt(s.trim(), 10))
468
468
  .filter((n) => n > 0);
469
469
  } catch (e) {
470
- console.error(`[upgrader] 枚举 watchdog 进程失败(WMI 不可用?): ${e.message}`);
470
+ console.error(
471
+ `[upgrader] 枚举 watchdog 进程失败(WMI 不可用?): ${e.message}`,
472
+ );
471
473
  return [];
472
474
  }
473
475
  }