更新 .puppeteerrc.cjs 以支持定位 macOS 上的 Chrome 或 Microsoft Edge 浏览器
This commit is contained in:
parent
217937041d
commit
52cf19d0db
|
@ -1,39 +1,62 @@
|
||||||
const os = require("os")
|
const os = require('os')
|
||||||
const { existsSync, realpathSync } = require("fs")
|
const {existsSync, realpathSync} = require('fs')
|
||||||
const { execSync } = require("child_process")
|
const {execSync} = require('child_process')
|
||||||
const arch = os.arch()
|
const arch = os.arch()
|
||||||
|
|
||||||
let skipDownload = false
|
let skipDownload = false
|
||||||
let executablePath
|
let executablePath
|
||||||
|
|
||||||
if (process.platform == "linux" || process.platform == "android")
|
// linux / android
|
||||||
|
if (process.platform === 'linux' || process.platform === 'android') {
|
||||||
for (const item of [
|
for (const item of [
|
||||||
"chromium",
|
'chromium',
|
||||||
"chromium-browser",
|
'chromium-browser',
|
||||||
"chrome",
|
'chrome',
|
||||||
"chrome-browser",
|
'chrome-browser',
|
||||||
]) try {
|
]) {
|
||||||
const chromiumPath = execSync(`command -v ${item}`).toString().trim()
|
try {
|
||||||
if (chromiumPath && existsSync(chromiumPath)) {
|
const chromiumPath = execSync(`command -v ${item}`).toString().trim()
|
||||||
executablePath = realpathSync(chromiumPath)
|
if (chromiumPath && existsSync(chromiumPath)) {
|
||||||
break
|
executablePath = realpathSync(chromiumPath)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
}
|
}
|
||||||
} catch (err) {}
|
}
|
||||||
|
|
||||||
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-browser",
|
|
||||||
"/snap/bin/chromium",
|
|
||||||
]) if (existsSync(item)) {
|
|
||||||
executablePath = item
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (executablePath || arch == "arm64" || arch == "aarch64") {
|
// macOS
|
||||||
(typeof logger == "object" ? logger : console).info(`[Chromium] ${executablePath}`)
|
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 [
|
||||||
|
'C:/Program Files/Google/Chrome/Application/chrome.exe',
|
||||||
|
'C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe',
|
||||||
|
'/usr/bin/chromium',
|
||||||
|
'/usr/bin/chromium-browser',
|
||||||
|
'/snap/bin/chromium',
|
||||||
|
]) {
|
||||||
|
if (existsSync(item)) {
|
||||||
|
executablePath = item
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (executablePath || arch === 'arm64' || arch === 'aarch64') {
|
||||||
|
(typeof logger == 'object' ? logger : console).info(`[Chromium] ${executablePath}`)
|
||||||
skipDownload = true
|
skipDownload = true
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { skipDownload, executablePath }
|
module.exports = {skipDownload, executablePath}
|
||||||
|
|
Loading…
Reference in New Issue