tt-help-cli-ycl 1.4.69 → 1.4.70

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.69",
3
+ "version": "1.4.70",
4
4
  "description": "TikTok user & video data scraper - extract ttSeller, verified, locationCreated from HTML source",
5
5
  "type": "module",
6
6
  "bin": {
@@ -11,10 +11,23 @@
11
11
 
12
12
  import { spawn, execSync } from "child_process";
13
13
  import { EventEmitter } from "events";
14
+ import { killEdgeProcesses } from "../lib/browser/cdp.js";
14
15
 
15
16
  const MAX_RESTART = 3;
16
17
  const IS_WIN = process.platform === "win32";
17
18
 
19
+ // 从命令行中提取 CDP 端口列表(解析 --base-port 和 --port-count)
20
+ function extractCdpPorts(cmdLine) {
21
+ const match = cmdLine.match(/--base-port\s+(\d+)/);
22
+ if (!match) return [];
23
+ const base = parseInt(match[1], 10);
24
+ const countMatch = cmdLine.match(/--port-count\s+(\d+)/);
25
+ const count = countMatch ? parseInt(countMatch[1], 10) : 1;
26
+ const ports = [];
27
+ for (let i = 0; i < count; i++) ports.push(base + i);
28
+ return ports;
29
+ }
30
+
18
31
  // 引号感知的命令拆分:"a b" "c d" → ["a b", "c d"]
19
32
  function splitCommand(cmdLine) {
20
33
  const parts = [];
@@ -112,9 +125,9 @@ export class ProcessManager extends EventEmitter {
112
125
  command = parts[0] || command;
113
126
  args = parts.slice(1);
114
127
  }
115
- // Windows .cmd 文件必须 shell:true,macOS/Linux 直接 spawn
128
+ // Windows .cmd 必须 shell:true;为免 DEP0190 警告,传完整命令行字符串
116
129
  child = IS_WIN
117
- ? spawn(command, args, {
130
+ ? spawn([command, ...args].join(" "), {
118
131
  stdio: ["ignore", "pipe", "pipe"],
119
132
  detached: false,
120
133
  shell: true,
@@ -210,6 +223,10 @@ export class ProcessManager extends EventEmitter {
210
223
 
211
224
  if (info.child) {
212
225
  try {
226
+ // 先从命令行提取 CDP 端口,用于关闭脱离进程树的浏览器
227
+ const cmdLine = info.cmdDef?.command || "";
228
+ const ports = extractCdpPorts(cmdLine);
229
+
213
230
  if (IS_WIN) {
214
231
  // Windows: shell:true 产生 cmd.exe 中间层,必须杀整个进程树
215
232
  execSync(`taskkill /PID ${info.child.pid} /T /F`, {
@@ -227,6 +244,11 @@ export class ProcessManager extends EventEmitter {
227
244
  } catch {}
228
245
  }, 2000);
229
246
  }
247
+
248
+ // 全平台:关闭脱离进程树的浏览器(open -a / start msedge 启动的)
249
+ for (const port of ports) {
250
+ killEdgeProcesses(null, port);
251
+ }
230
252
  } catch (e) {
231
253
  console.error(`[watchdog] 停止命令 ${cmdId} 失败: ${e.message}`);
232
254
  }