Miao-Yunzai/.puppeteerrc.cjs

62 lines
1.4 KiB
JavaScript
Raw Normal View History

const os = require('os')
2023-09-06 14:48:25 +08:00
const { existsSync } = require('fs')
2023-09-06 11:37:42 +08:00
const { execSync } = require('child_process')
const arch = os.arch()
let skipDownload = false
let executablePath
// linux / android
if (process.platform === 'linux' || process.platform === 'android') {
for (const item of [
2023-09-06 14:48:25 +08:00
"chromium",
"chromium-browser",
"chrome",
]) {
try {
const chromiumPath = execSync(`command -v ${item}`).toString().trim()
if (chromiumPath && existsSync(chromiumPath)) {
2023-09-06 14:48:25 +08:00
executablePath = chromiumPath
break
}
} catch (err) {
}
}
}
// macOS
if (process.platform === 'darwin') {
for (const item of [
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
'/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge',
]) {
if (existsSync(item)) {
executablePath = item
break
}
}
}
// windows 或其他
if (!executablePath) {
for (const item of [
'/usr/bin/chromium',
'/usr/bin/chromium-browser',
2023-09-06 14:48:25 +08:00
'/usr/bin/chrome',
'C:/Program Files/Google/Chrome/Application/chrome.exe',
'C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe',
]) {
if (existsSync(item)) {
executablePath = item
break
}
}
}
if (executablePath || arch === 'arm64' || arch === 'aarch64') {
(typeof logger == 'object' ? logger : console).info(`[Chromium] ${executablePath}`)
skipDownload = true
}
2023-09-06 11:37:42 +08:00
module.exports = { skipDownload, executablePath }