tt-help-cli-ycl 1.3.74 → 1.3.76
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 +4 -2
- package/src/lib/browser/cdp.js +8 -2
package/package.json
CHANGED
package/src/cli/open.js
CHANGED
|
@@ -94,10 +94,12 @@ 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})`);
|
|
97
98
|
await killEdgeProcesses(userDataDir);
|
|
99
|
+
console.error("[SIGINT] Edge 进程已终止,正在关闭浏览器连接...");
|
|
98
100
|
await browser.close();
|
|
99
|
-
} catch {
|
|
100
|
-
|
|
101
|
+
} catch (e) {
|
|
102
|
+
console.error(`[SIGINT] 关闭浏览器时出错: ${e.message}`);
|
|
101
103
|
}
|
|
102
104
|
console.error("浏览器已关闭");
|
|
103
105
|
process.exit(0);
|
package/src/lib/browser/cdp.js
CHANGED
|
@@ -109,12 +109,16 @@ function killEdgeProcesses(targetDir) {
|
|
|
109
109
|
const ps1Content =
|
|
110
110
|
`$procs = Get-CimInstance Win32_Process -Filter "Name='msedge.exe'" 2>$null; ` +
|
|
111
111
|
`$count = 0; ` +
|
|
112
|
+
`$pids = @(); ` +
|
|
112
113
|
`foreach ($p in $procs) { ` +
|
|
113
114
|
` if ($p.CommandLine -and $p.CommandLine -like "*${escapedDir}*") { ` +
|
|
115
|
+
` $pids += $p.ProcessId; ` +
|
|
114
116
|
` Stop-Process -Id $p.ProcessId -Force -ErrorAction SilentlyContinue; ` +
|
|
115
117
|
` $count++ ` +
|
|
116
118
|
` } ` +
|
|
117
119
|
`}; ` +
|
|
120
|
+
`Write-Output "KILLED_PIDS: $($pids -join ',')"; ` +
|
|
121
|
+
`Start-Sleep -Milliseconds 500; ` +
|
|
118
122
|
`Get-ChildItem "$env:LOCALAPPDATA\\Microsoft\\Edge\\Singleton*" -ErrorAction SilentlyContinue | Remove-Item -Force; ` +
|
|
119
123
|
`Write-Output $count`;
|
|
120
124
|
fs.writeFileSync(ps1Path, ps1Content);
|
|
@@ -123,9 +127,11 @@ function killEdgeProcesses(targetDir) {
|
|
|
123
127
|
)
|
|
124
128
|
.toString()
|
|
125
129
|
.trim();
|
|
126
|
-
|
|
130
|
+
console.error(`[killEdgeProcesses] Windows PS result: ${result}`);
|
|
131
|
+
try { fs.unlinkSync(ps1Path); } catch {}
|
|
127
132
|
command = "exit 0";
|
|
128
|
-
} catch {
|
|
133
|
+
} catch (e) {
|
|
134
|
+
console.error(`[killEdgeProcesses] Windows PS failed: ${e.message}`);
|
|
129
135
|
command = "taskkill /F /IM msedge.exe 2>nul || exit 0";
|
|
130
136
|
}
|
|
131
137
|
} else {
|