tt-help-cli-ycl 1.3.77 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tt-help-cli-ycl",
3
- "version": "1.3.77",
3
+ "version": "1.3.78",
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
@@ -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 进程 (userDataDir: ${userDataDir})`);
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) {
@@ -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,20 +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 (targetDir) {
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
- `Write-Output "TOTAL_MSEDGE_PROCS: $($procs.Count)"; ` +
112
- `foreach ($p in $procs) { ` +
113
- ` Write-Output "PROC_PID=$($p.ProcessId) CMD=$($p.CommandLine)"; ` +
114
- `}; ` +
115
111
  `$count = 0; ` +
116
112
  `$pids = @(); ` +
117
113
  `foreach ($p in $procs) { ` +
118
- ` if ($p.CommandLine -and $p.CommandLine -like "*${escapedDir}*") { ` +
114
+ ` if ($p.CommandLine -and $p.CommandLine -like "*--remote-debugging-port=${port}*") { ` +
119
115
  ` $pids += $p.ProcessId; ` +
120
116
  ` Stop-Process -Id $p.ProcessId -Force -ErrorAction SilentlyContinue; ` +
121
117
  ` $count++ ` +
@@ -132,7 +128,9 @@ function killEdgeProcesses(targetDir) {
132
128
  .toString()
133
129
  .trim();
134
130
  console.error(`[killEdgeProcesses] Windows PS result: ${result}`);
135
- try { fs.unlinkSync(ps1Path); } catch {}
131
+ try {
132
+ fs.unlinkSync(ps1Path);
133
+ } catch {}
136
134
  command = "exit 0";
137
135
  } catch (e) {
138
136
  console.error(`[killEdgeProcesses] Windows PS failed: ${e.message}`);
@@ -222,7 +220,7 @@ export async function ensureBrowserReady(options = {}) {
222
220
  const edgeArgsValid = await checkEdgeArgs();
223
221
  if (!edgeArgsValid) {
224
222
  console.error(`Edge 已运行但启动参数不完整,正在重启端口 ${port}...`);
225
- await killEdgeProcesses(userDataDir);
223
+ await killEdgeProcesses(userDataDir, port);
226
224
  await new Promise((r) => setTimeout(r, 3000));
227
225
  needLaunch = true;
228
226
  }
@@ -238,7 +236,7 @@ export async function ensureBrowserReady(options = {}) {
238
236
  const edgeRunning = await isEdgeRunning();
239
237
  if (edgeRunning) {
240
238
  console.error(`Edge 已运行但 CDP 端口 ${port} 未启用,正在重启...`);
241
- await killEdgeProcesses(userDataDir);
239
+ await killEdgeProcesses(userDataDir, port);
242
240
  await new Promise((r) => setTimeout(r, 3000));
243
241
  } else {
244
242
  console.error(`CDP 端口 ${port} 未就绪,正在启动 Edge 浏览器...`);
@@ -266,7 +264,7 @@ export async function switchAccount(oldAccount, newAccount, proxyServer) {
266
264
  console.error(` [账户切换] 等待 30 秒,请完成当前操作后自动切换...`);
267
265
  await new Promise((r) => setTimeout(r, 30000));
268
266
 
269
- await killEdgeProcesses(oldAccount.userDataDir);
267
+ await killEdgeProcesses(oldAccount.userDataDir, oldAccount.port);
270
268
  await new Promise((r) => setTimeout(r, 3000));
271
269
 
272
270
  const newCdpOptions = {};
@@ -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
  }