Pupeteer:如何在Linux上指定Chromium路径

时间:2019-08-01 09:23:58

标签: puppeteer

我在Linux环境中,我想找到如何指定Chromium应该使用的路径。目前,这是我遇到的错误:

Chromium revision is not downloaded. Run "npm install" or "yarn
           install" Error: Chromium revision is not downloaded. Run "npm
           install" or "yarn install" at Launcher.launch

我确实使用变量PUPPETEER_SKIP_CHROMIUM_DOWNLOAD禁用了下载,但是我还没有找到如何给铬二进制文件的路径。

3 个答案:

答案 0 :(得分:1)

您可以在调用puppeteer.launch时使用选项executablePath指定Chromium二进制文件的路径。

引用文档:

  

executablePath:要运行而不是捆绑的Chromium的Chromium或Chrome可执行文件的路径。如果executablePath是相对路径,则相对于当前工作目录来解析。 注意:仅保证Puppeteer与捆绑的Chromium一起使用,使用后果自负。

代码示例

const browser = await puppeteer.launch({
    executablePath: '/path/to/binary',
    /* ... */
});

答案 1 :(得分:1)

我解决了我的问题

 export PUPPETEER_EXECUTABLE_PATH=/usr/bin/google-chrome

然后,如果您试图让 mermaid.cli 工作 (mmdc),我遇到的第二个问题是沙箱错误,我已修复:

echo '{ "args":["--no-sandbox"] }' > puppeteer.json
mmdc -i input.mmd -o output.svg -p puppeteer.json

此修复之前的错误是:

 (node:23266) UnhandledPromiseRejectionWarning: Error: Failed to launch chrome!
 [0223/152312.185004:ERROR:zygote_host_impl_linux.cc(90)] Running as root without -- 
 no-sandbox is not supported. See https://crbug.com/638180.

答案 2 :(得分:0)

Puppeteer将查找环境变量# treat null values df['column'].fillna('NA', inplace = True) # separate all genres into one list, considering comma + space as separators genre = df['column'].str.split(', ').tolist() # flatten the list flat_genre = [item for sublist in genre for item in sublist] # convert to a set to make unique set_genre = set(flat_genre) # back to list unique_genre = list(set_genre) # remove NA unique_genre.remove('NA') # create columns by each unique genre df = df.reindex(df.columns.tolist() + unique_genre, axis=1, fill_value=0) # for each value inside column, update the dummy for index, row in df.iterrows(): for val in row.column.split(', '): if val != 'NA': df.loc[index, val] = 1 df.drop('column', axis = 1, inplace = True) df Title Action Fantasy Comedy Sci-Fi Drama Romance 0 Movie 1 1 1 0 0 0 0 1 Movie 2 0 1 0 0 1 0 2 Movie 3 1 0 0 0 0 0 3 Movie 4 0 0 1 1 0 1 4 Movie 5 0 0 0 0 0 0

因此要指定Chromium(或Firefox,如果您愿意的话)的路径,请运行PUPPETEER_EXECUTABLE_PATH