问题1:error while loading shared libraries: libXcomposite.so.1
找到下面这个链接 github.com/puppeteer/p…
发现少依赖
ldd chrome | grep not
解决方法:安装Chrome后,这些共享包就都安装了 安装Chrome
wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
yum install -y google-chrome-stable_current_x86_64.rpm
/opt/google/chrome/chrome --version
问题2:Running as root without –no-sandbox is not supported.
附测试代码 test.js
const puppeteer = require('puppeteer-core');
let platform = global.process.platform;
// platform MacOS:darwin Widnows:win32 CentOS:linux
let executablePath = '/opt/puppeteer/chrome-mac/Chromium.app/Contents/MacOS/Chromium';
if (platform == 'win32') {
} else if (platform == 'linux') {
executablePath = '/opt/puppeteer/chrome-linux/chrome';
}
(async () => {
console.log(executablePath);
const brower = await puppeteer.launch({
headless: false,
executablePath: executablePath,
args: ['--no-sandbox', '--disable-setuid-sandbox'],
ignoreDefaultArgs: [
'--enable-automation',
]
});
const page = await brower.newPage();
await page.goto('http://www.baidu.com');
await page.waitFor(5000);
await brower.close();
})();