问题
最近学node
, 之前用puppeteer
写的抓包工具报错

但是如果你真的yarn
一下就会报类似

解决
手动下载Chromium
下载地址:https://download-chromium.appspot.com/
把下载刚刚下载的文件解压到项目的chromium
文件夹下,在chromium
文件夹下你会看到chrome-mac
文件

创建src/app.js
(async () => {
const browser = await puppeteer.launch({
executablePath: '../chromium/Chromium.app/Contents/MacOS/Chromium',
headless: false
});
const page = await browser.newPage();
await page.goto('https://www.baidu.com');
// Get the "viewport" of the page, as reported by the page.
const dimensions = await page.evaluate(() => {
return {
width: document.documentElement.clientWidth,
height: document.documentElement.clientHeight,
deviceScaleFactor: window.devicePixelRatio
};
});
console.log('Dimensions:', dimensions);
await browser.close();
})();
以上解决!
网友评论