From 222850219f0dae62879af7e712dd535970c21f41 Mon Sep 17 00:00:00 2001 From: Jonathan Felchlin Date: Tue, 20 Mar 2018 10:57:47 -0700 Subject: [PATCH] Support for chromium on all platforms, including via puppeteer --- browsers/Chrome.js | 4 +--- browsers/Chromium.js | 38 ++++++++++++++++++++++++++++++++++++++ browsers/index.js | 1 + package.json | 1 + 4 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 browsers/Chromium.js diff --git a/browsers/Chrome.js b/browsers/Chrome.js index db404f1..e665134 100644 --- a/browsers/Chrome.js +++ b/browsers/Chrome.js @@ -1,9 +1,7 @@ module.exports = { name: 'Chrome', DEFAULT_CMD: { - // Try chromium-browser before chromium to avoid conflict with the legacy - // chromium-bsu package previously known as 'chromium' in Debian and Ubuntu. - linux: ['chromium-browser', 'chromium', 'google-chrome', 'google-chrome-stable'], + linux: ['google-chrome', 'google-chrome-stable'], darwin: ['/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'], win32: [ process.env.LOCALAPPDATA + '\\Google\\Chrome\\Application\\chrome.exe', diff --git a/browsers/Chromium.js b/browsers/Chromium.js new file mode 100644 index 0000000..6591b1c --- /dev/null +++ b/browsers/Chromium.js @@ -0,0 +1,38 @@ +var resolveGlobal = require('resolve-global'); +var globalPuppeteerPath = resolveGlobal.silent('puppeteer'); + +function getPuppeteerChromiumPath(moduleId) { + try { + return require(moduleId).executablePath(); + } catch(e) { + return null; + } +} + +var puppeteerChromiumPath = getPuppeteerChromiumPath('puppeteer'); +var globalPuppeteerChromiumPath = getPuppeteerChromiumPath(globalPuppeteerPath); + +module.exports = { + name: 'Chromium', + DEFAULT_CMD: { + linux: [ + puppeteerChromiumPath, + globalPuppeteerChromiumPath, + // Try chromium-browser before chromium to avoid conflict with the legacy + // chromium-bsu package previously known as 'chromium' in Debian and Ubuntu. + 'chromium-browser', + 'chromium', + ], + darwin: [ + puppeteerChromiumPath, + globalPuppeteerChromiumPath, + '/Applications/Google Chrome.app/Contents/MacOS/Chromium', + ], + win32: [ + puppeteerChromiumPath, + globalPuppeteerChromiumPath, + process.env['ProgramFiles(x86)'] + '\\Chromium\\Application\\chrome.exe', + ], + }, + ENV_CMD: 'CHROME_BIN' +}; diff --git a/browsers/index.js b/browsers/index.js index 99f26fb..fe1239f 100644 --- a/browsers/index.js +++ b/browsers/index.js @@ -1,6 +1,7 @@ module.exports = { chrome: require('./Chrome.js'), chromeCanary: require('./ChromeCanary.js'), + chromium: require('./Chromium.js'), edge: require('./Edge.js'), firefox: require('./Firefox.js'), firefoxAurora: require('./FirefoxAurora.js'), diff --git a/package.json b/package.json index 711dd3d..5e23f0a 100644 --- a/package.json +++ b/package.json @@ -89,6 +89,7 @@ "phantomjs-prebuilt": "2.1.14" }, "dependencies": { + "resolve-global": "^0.1.0", "which": "^1.2.4" } }