You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何有效终止Puppeteer产生的残留Chromium进程?

终止Puppeteer残留Chromium进程解决方案

你之前的方法失效核心原因是匹配逻辑太粗,没有命中Puppeteer启动进程的专属特征,很容易漏杀,也可能误判进程名。
Puppeteer启动的所有Chromium实例都会默认携带--remote-debugging-port启动参数,用这个特征匹配进程,既能把所有残留的Puppeteer Chromium进程杀干净,也不会误杀你手动打开的正常Chrome/Chromium窗口。


跨平台Node.js实现(无需额外依赖)

直接用Node原生模块即可,兼容Windows、macOS、Linux:

const { exec } = require('child_process');
const os = require('os');

function killPuppeteerChromium() {
  const platform = os.platform();
  let killCmd = '';
  if (platform === 'win32') {
    killCmd = `wmic process where "commandline like '%--remote-debugging-port%' and (name='chromium.exe' or name='chrome.exe')" call terminate`;
  } else {
    killCmd = `pkill -9 -f ".*(chromium|chrome).*--remote-debugging-port.*"`;
  }
  exec(killCmd, () => {});
}

// 需要清理的时候直接调用
killPuppeteerChromium();

终端直接执行的清理命令

不想写代码的话,直接打开对应系统的终端执行命令即可:

  • Windows(建议用管理员权限打开cmd/PowerShell):
wmic process where "commandline like '%--remote-debugging-port%' and (name='chromium.exe' or name='chrome.exe')" call terminate
  • macOS / Linux:
pkill -9 -f ".*(chromium|chrome).*--remote-debugging-port.*"

之前尝试的方法失效原因

  • fkill仅匹配固定进程名:部分版本Puppeteer启动的内置Chromium进程名是chrome.exe而非chromium.exe,Linux/macOS下也可能因为软链接、版本差异出现进程名不匹配,导致漏杀
  • 调用browser.close失效:第三方包封装Puppeteer时没有对外暴露正确的browser实例引用,你调用的实例和实际运行的进程没有绑定,自然无法关闭
  • kill-tabs仅能处理和Puppeteer保持正常调试连接的标签页,对已经脱离控制的僵尸进程没有作用

内容的提问来源于stack exchange,提问作者Flappy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.30 16:45:49