-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
optimize: view pup executablePath setting
- Loading branch information
Showing
3 changed files
with
43 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,44 @@ | ||
const os = require('os'); | ||
const { existsSync } = require('fs'); | ||
const { execSync } = require('child_process'); | ||
const arch = os.arch(); | ||
|
||
let skipDownload = false; | ||
let executablePath; | ||
|
||
if (['linux', 'android'].includes(process.platform)) | ||
for (const item of ['chromium', 'chromium-browser', 'chrome', 'google-chrome']) | ||
try { | ||
const chromiumPath = execSync(`command -v ${item}`).toString().trim(); | ||
if (chromiumPath && existsSync(chromiumPath)) { | ||
executablePath = chromiumPath; | ||
break; | ||
} | ||
} catch (err) {} | ||
|
||
/** | ||
* @type {string} 浏览器 "可执行文件路径" 列表,可根据需要自行修改或添加 | ||
*/ | ||
if (!executablePath) | ||
for (const item of [ | ||
// Windows | ||
'C:/Program Files/Google/Chrome/Application/chrome.exe', | ||
'C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe', | ||
// macOS | ||
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', | ||
'/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge' | ||
]) | ||
if (existsSync(item)) { | ||
executablePath = item; | ||
break; | ||
} | ||
|
||
if (executablePath || arch == 'arm64' || arch == 'aarch64') { | ||
(typeof logger != 'undefined' ? logger : console).info(`[Chromium] ${executablePath}`); | ||
skipDownload = true; | ||
} | ||
|
||
/** | ||
* @type {import("puppeteer").Configuration} | ||
*/ | ||
module.exports = require('jsxp/.puppeteerrc'); | ||
module.exports = { skipDownload, executablePath }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters