Skip to content

Commit

Permalink
optimize: view pup executablePath setting
Browse files Browse the repository at this point in the history
  • Loading branch information
snowtafir committed Dec 26, 2024
1 parent 9e21e4a commit 869ddc8
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
42 changes: 41 additions & 1 deletion .puppeteerrc.cjs
Original file line number Diff line number Diff line change
@@ -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 };
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ sudo yum install chromium # CentOS Stream 8
#查看版本
chromium-browser --version
```
> 注意,如果windows下手动安装chromium浏览器,或安装了其他修改版chrome浏览器,出现找不到浏览器,需要手动将`可执行文件路径`添加到 [./.puppeteerrc.cjs](./.puppeteerrc.cjs) 的路径列表中。
# 🌰一、安装插件

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 869ddc8

Please sign in to comment.