From 52cf19d0db084154c53190e727b2ad829708e35a Mon Sep 17 00:00:00 2001 From: Ayakura Yuki Date: Wed, 6 Sep 2023 10:51:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20.puppeteerrc.cjs=20?= =?UTF-8?q?=E4=BB=A5=E6=94=AF=E6=8C=81=E5=AE=9A=E4=BD=8D=20macOS=20?= =?UTF-8?q?=E4=B8=8A=E7=9A=84=20Chrome=20=E6=88=96=20Microsoft=20Edge=20?= =?UTF-8?q?=E6=B5=8F=E8=A7=88=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .puppeteerrc.cjs | 77 +++++++++++++++++++++++++++++++----------------- 1 file changed, 50 insertions(+), 27 deletions(-) diff --git a/.puppeteerrc.cjs b/.puppeteerrc.cjs index 2f3a7b5..ffefdc9 100644 --- a/.puppeteerrc.cjs +++ b/.puppeteerrc.cjs @@ -1,39 +1,62 @@ -const os = require("os") -const { existsSync, realpathSync } = require("fs") -const { execSync } = require("child_process") +const os = require('os') +const {existsSync, realpathSync} = require('fs') +const {execSync} = require('child_process') const arch = os.arch() let skipDownload = false let executablePath -if (process.platform == "linux" || process.platform == "android") +// linux / android +if (process.platform === 'linux' || process.platform === 'android') { for (const item of [ - "chromium", - "chromium-browser", - "chrome", - "chrome-browser", - ]) try { - const chromiumPath = execSync(`command -v ${item}`).toString().trim() - if (chromiumPath && existsSync(chromiumPath)) { - executablePath = realpathSync(chromiumPath) - break + 'chromium', + 'chromium-browser', + 'chrome', + 'chrome-browser', + ]) { + try { + const chromiumPath = execSync(`command -v ${item}`).toString().trim() + if (chromiumPath && existsSync(chromiumPath)) { + 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") { - (typeof logger == "object" ? logger : console).info(`[Chromium] ${executablePath}`) +// 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 [ + '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 } -module.exports = { skipDownload, executablePath } \ No newline at end of file +module.exports = {skipDownload, executablePath}