依赖信息:
electron ^13.0.0
puppeteer ^9.0.0
vue-cli-plugin-electron-builder ~2.1.1
// background.js
主线程增加监听,渲染层会有个按钮向主线程发送通知,以调起puppeteer脚本唤起浏览器
ipcMain.on("Start", () => {
puppeteer.launch({
headless: false
}).then(async browser => {
const page = await browser.newPage();
await page.goto('https://www.google.com');
console.log(await page.title());
await browser.close();
})
})
启动命令:
npm run electron:serve
点击按钮,控制台报错:
UnhandledPromiseRejectionWarning: Error: Could not find expected browser (chrome) locally. Run `npm install` to download the correct Chromium revision (869685).
at ChromeLauncher.launch (webpack:///./node_modules/puppeteer/lib/cjs/puppeteer/node/Launcher.js?:82:27)
(node: