简体   繁体   English

从没有 puppeteer 功能的 puppeteer 启动 chromium

[英]Launch chromium from puppeteer without puppeteer functions

How can I launch chromium installed in node_modules directly puppeteer without puppeteer functionality (only launch browser)?如何在没有 puppeteer 功能的情况下直接启动 node_modules 中安装的 chromium puppeteer (仅启动浏览器)? I assume that there is a switch when calling launch , but I can't find it anywhere in the documentation.我假设调用launch时有一个开关,但我在文档中的任何地方都找不到它。 A browser path and some universal launch code would also help, but unfortunately I can't even create it.浏览器路径和一些通用启动代码也会有所帮助,但不幸的是我什至无法创建它。

So, how to launch puppeteer browser directly (bypass puppeteer)?那么,如何直接启动 puppeteer 浏览器(绕过 puppeteer)?

puppeteer.executablePath() gives you the path to the executable file. puppeteer.executablePath()为您提供可执行文件的路径。

Quote from the documentation:从文档中引用:

returns: < string > A path where Puppeteer expects to find the bundled browser.返回:< string > Puppeteer 期望找到捆绑浏览器的路径。 The browser binary might not be there if the download was skipped with PUPPETEER_SKIP_DOWNLOAD .如果使用PUPPETEER_SKIP_DOWNLOAD跳过下载,则浏览器二进制文件可能不存在。

You can then use Node.js itself to create a process .然后您可以使用 Node.js 本身来创建一个进程 See example:参见示例:

import { executablePath } from 'puppeteer';
import { execFile } from 'child_process';

chromiumParams = ['--no-first-run', '--no-default-browser-check'];
chromiumPath = executablePath();
execFile(chromiumPath, chromiumParams, (error, stdout) => {
  if (error) { throw error; }
  console.log(stdout);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM