diff --git a/.puppeteerrc.cjs b/.puppeteerrc.cjs index 2a2dc7e..43281a0 100644 --- a/.puppeteerrc.cjs +++ b/.puppeteerrc.cjs @@ -1,4 +1,44 @@ +const os = require('os'); +const { existsSync } = require('fs'); +const { execSync } = require('child_process'); +const arch = os.arch(); + +let skipDownload = false; +let executablePath; + +if (['linux', 'android'].includes(process.platform)) + for (const item of ['chromium', 'chromium-browser', 'chrome', 'google-chrome']) + try { + const chromiumPath = execSync(`command -v ${item}`).toString().trim(); + if (chromiumPath && existsSync(chromiumPath)) { + executablePath = chromiumPath; + break; + } + } catch (err) {} + +/** + * @type {string} 浏览器 "可执行文件路径" 列表,可根据需要自行修改或添加 + */ +if (!executablePath) + for (const item of [ + // Windows + 'C:/Program Files/Google/Chrome/Application/chrome.exe', + 'C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe', + // macOS + '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', + '/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge' + ]) + if (existsSync(item)) { + executablePath = item; + break; + } + +if (executablePath || arch == 'arm64' || arch == 'aarch64') { + (typeof logger != 'undefined' ? logger : console).info(`[Chromium] ${executablePath}`); + skipDownload = true; +} + /** * @type {import("puppeteer").Configuration} */ -module.exports = require('jsxp/.puppeteerrc'); +module.exports = { skipDownload, executablePath }; diff --git a/README.md b/README.md index 7c27abf..a12740a 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ sudo yum install chromium # CentOS Stream 8 #查看版本 chromium-browser --version ``` +> 注意,如果windows下手动安装chromium浏览器,或安装了其他修改版chrome浏览器,出现找不到浏览器,需要手动将`可执行文件路径`添加到 [./.puppeteerrc.cjs](./.puppeteerrc.cjs) 的路径列表中。 # 🌰一、安装插件 diff --git a/package.json b/package.json index ec11530..063bb1a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "yuki-plugin", - "version": "2.0.6-2", + "version": "2.0.6-3", "author": "snowtafir", "description": "优纪插件,yunzai-V4 关于 微博推送、B站推送 等功能的拓展插件", "main": "./index",