2023-09-06 10:51:06 +08:00
|
|
|
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')
|
2023-09-06 03:00:17 +08:00
|
|
|
const arch = os.arch()
|
|
|
|
|
|
|
|
let skipDownload = false
|
|
|
|
let executablePath
|
|
|
|
|
2023-09-06 15:33:46 +08:00
|
|
|
if (process.platform === 'linux' || process.platform === 'android')
|
2024-06-08 21:09:19 +08:00
|
|
|
for (const item of ['chromium', 'chromium-browser', 'chrome'])
|
|
|
|
try {
|
|
|
|
const chromiumPath = execSync(`command -v ${item}`).toString().trim()
|
|
|
|
if (chromiumPath && existsSync(chromiumPath)) {
|
|
|
|
executablePath = chromiumPath
|
|
|
|
break
|
|
|
|
}
|
|
|
|
} catch (err) {}
|
|
|
|
|
|
|
|
// macOS
|
|
|
|
if (process.platform === 'darwin')
|
2023-09-06 03:00:17 +08:00
|
|
|
for (const item of [
|
2024-06-08 21:09:19 +08:00
|
|
|
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
|
|
|
|
'/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge'
|
|
|
|
])
|
|
|
|
if (existsSync(item)) {
|
|
|
|
executablePath = item
|
2023-09-06 15:33:46 +08:00
|
|
|
break
|
2023-09-06 10:51:06 +08:00
|
|
|
}
|
2023-09-06 03:00:17 +08:00
|
|
|
|
2024-06-08 21:09:19 +08:00
|
|
|
if (!executablePath)
|
|
|
|
for (const item of [
|
|
|
|
'/usr/bin/chromium',
|
|
|
|
'/usr/bin/chromium-browser',
|
|
|
|
'/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
|
|
|
|
}
|
2023-09-06 03:00:17 +08:00
|
|
|
|
2023-09-06 10:51:06 +08:00
|
|
|
if (executablePath || arch === 'arm64' || arch === 'aarch64') {
|
2024-06-08 21:09:19 +08:00
|
|
|
;(typeof logger == 'object' ? logger : console).info(
|
|
|
|
`[Chromium] ${executablePath}`
|
|
|
|
)
|
2023-09-06 03:00:17 +08:00
|
|
|
skipDownload = true
|
2023-08-14 13:09:35 +08:00
|
|
|
}
|
2024-06-09 01:31:31 +08:00
|
|
|
/**
|
|
|
|
* @type {import("puppeteer").Configuration}
|
|
|
|
*/
|
2023-09-06 11:37:42 +08:00
|
|
|
module.exports = { skipDownload, executablePath }
|