Skip to main content
Version: 23.8.0

无头模式

¥Headless mode

默认情况下,Puppeteer 在 无头模式 中启动浏览器。

¥By default Puppeteer launches the browser in the Headless mode.

const browser = await puppeteer.launch();
// Equivalent to
const browser = await puppeteer.launch({headless: true});

在 v22 之前,Puppeteer 默认启动 旧的无头模式。旧的无头模式现在称为 chrome-headless-shell,并作为单独的二进制文件发布。chrome-headless-shell 与常规 Chrome 的行为并不完全匹配,但目前对于不需要完整 Chrome 功能集的自动化任务来说,它的性能更高。如果性能对你的用例更重要,请切换到 chrome-headless-shell,如下所示:

¥Before v22, Puppeteer launched the old Headless mode by default. The old headless mode is now known as chrome-headless-shell and ships as a separate binary. chrome-headless-shell does not match the behavior of the regular Chrome completely but it is currently more performant for automation tasks where the complete Chrome feature set is not needed. If the performance is more important for your use case, switch to chrome-headless-shell as following:

const browser = await puppeteer.launch({headless: 'shell'});

要启动 "有头" 版本的 Chrome,请在启动浏览器时将 headless 设置为 false 选项:

¥To launch a "headful" version of Chrome, set the headless to false option when launching a browser:

const browser = await puppeteer.launch({headless: false});