taoCMS是基于php+sqlite/mysql的国内最小(100Kb左右)的功能完善、开源免费的CMS管理系统

Puppeteer on Raspbian NodeJS

2021-03-29

If we want to use Puppeteer in nodejs, we simply do a:

npm i puppeteer
# or "yarn add puppeteer"

After that humans would think that the following code would work:

const puppeteer = require('puppeteer');

(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
await page.screenshot({path: 'example.png'});

await browser.close();
})();

Well…let me tell you, it would work…but not on an ARM Processor. And were so lucky today, because Raspberry Pi contains an ARM Processor.

You would get the following error trying to run the :

Error: Failed to launch chrome!
/home/xxxx/.../node_modules/puppeteer/.local-chromium/liniux-641577/chrome-linux/chrome: Syntax error: word unexpected (expecting ") "

Solving the issue

Install Chromium by running:
sudo apt install chromium-browser chromium-codecs-ffmpeg

It usually installs Chromium in /usr/bin/ -folder. So then we change the executablePath to the below:

const browser = await puppeteer.launch({
headless: true,
executablePath: '/usr/bin/chromium-browser',
args: ['--no-sandbox', '--disable-setuid-sandbox']
});

That’s all, running your Nodejs program will now run puppeteer successfully and should open the Chromium browser.

Enjoy!

类别:未分组 | 阅读:80182 | 评论:0 | 标签:

想收藏或者和大家分享这篇好文章→

公告

taoCMS发布taoCMS 3.0.2(最后更新21年03月15日),请大家速速升级,欢迎大家试用和提出您宝贵的意见建议。

捐助与联系

☟请使用新浪微博联系我☟

☟在github上follow我☟

标签云