优化 puppeteer

This commit is contained in:
🌌 2023-09-06 13:00:35 +08:00
parent 897d66c480
commit 9a7fd50c65
1 changed files with 5 additions and 6 deletions

View File

@ -1,5 +1,5 @@
const os = require("os") const os = require("os")
const { existsSync, realpathSync } = require("fs") const { existsSync } = require("fs")
const { execSync } = require("child_process") const { execSync } = require("child_process")
const arch = os.arch() const arch = os.arch()
@ -11,21 +11,20 @@ if (process.platform == "linux" || process.platform == "android")
"chromium", "chromium",
"chromium-browser", "chromium-browser",
"chrome", "chrome",
"chrome-browser",
]) try { ]) try {
const chromiumPath = execSync(`command -v ${item}`).toString().trim() const chromiumPath = execSync(`command -v ${item}`).toString().trim()
if (chromiumPath && existsSync(chromiumPath)) { if (chromiumPath && existsSync(chromiumPath)) {
executablePath = realpathSync(chromiumPath) executablePath = chromiumPath
break break
} }
} catch (err) {} } catch (err) {}
if (!executablePath) for (const item of [ if (!executablePath) for (const item of [
"C:/Program Files/Google/Chrome/Application/chrome.exe",
"C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe",
"/usr/bin/chromium", "/usr/bin/chromium",
"/usr/bin/chromium-browser", "/usr/bin/chromium-browser",
"/snap/bin/chromium", "/usr/bin/chrome",
"C:/Program Files/Google/Chrome/Application/chrome.exe",
"C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe",
]) if (existsSync(item)) { ]) if (existsSync(item)) {
executablePath = item executablePath = item
break break