Skip to content

Commit 33e8d82

Browse files
haifengkaodignifiedquire
authored andcommitted
feat: Chromium support for Linux, Darwin and Windows
Add support for Chromium for Linux, Darwin and Windows platforms Remove linux chromium binary lookup in Google Chrome Closes #45 BREAKING: Chromium needs to be explicitly enabled now
1 parent 108cd87 commit 33e8d82

2 files changed

Lines changed: 67 additions & 3 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
[![Build Status](https://img.shields.io/travis/karma-runner/karma-chrome-launcher/master.svg?style=flat-square)](https://travis-ci.org/karma-runner/karma-chrome-launcher) [![Dependency Status](https://img.shields.io/david/karma-runner/karma-chrome-launcher.svg?style=flat-square)](https://david-dm.org/karma-runner/karma-chrome-launcher) [![devDependency Status](https://img.shields.io/david/dev/karma-runner/karma-chrome-launcher.svg?style=flat-square)](https://david-dm.org/karma-runner/karma-chrome-launcher#info=devDependencies)
77

8-
> Launcher for Google Chrome and Google Chrome Canary.
8+
> Launcher for Google Chrome, Google Chrome Canary and Google Chromium.
99
1010
## Installation
1111

@@ -22,7 +22,7 @@ $ npm install karma-chrome-launcher --save-dev
2222
// karma.conf.js
2323
module.exports = function(config) {
2424
config.set({
25-
browsers: ['Chrome', 'Chrome_without_security'],
25+
browsers: ['Chrome', 'Chrome_without_security'], // You may use 'ChromeCanary' or 'Chromium' as well
2626

2727
// you can define custom flags
2828
customLaunchers: {

index.js

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,54 @@ function getChromeExe (chromeDirName) {
6767
return windowsChromeDirectory
6868
}
6969

70+
var ChromiumBrowser = function (baseBrowserDecorator, args) {
71+
baseBrowserDecorator(this)
72+
73+
var flags = args.flags || []
74+
75+
this._getOptions = function (url) {
76+
// Chromium CLI options
77+
// http://peter.sh/experiments/chromium-command-line-switches/
78+
flags.forEach(function (flag, i) {
79+
if (isJSFlags(flag)) {
80+
flags[i] = sanitizeJSFlags(flag)
81+
}
82+
})
83+
84+
return [
85+
'--user-data-dir=' + this._tempDir,
86+
'--no-default-browser-check',
87+
'--no-first-run',
88+
'--disable-default-apps',
89+
'--disable-popup-blocking',
90+
'--disable-translate',
91+
'--disable-background-timer-throttling'
92+
].concat(flags, [url])
93+
}
94+
}
95+
96+
// Return location of Chromium's chrome.exe file.
97+
function getChromiumExe (chromeDirName) {
98+
// Only run these checks on win32
99+
if (process.platform !== 'win32') {
100+
return null
101+
}
102+
var windowsChromiumDirectory, i, prefix
103+
var suffix = '\\Chromium\\Application\\chrome.exe'
104+
var prefixes = [process.env.LOCALAPPDATA, process.env.PROGRAMFILES, process.env['PROGRAMFILES(X86)']]
105+
106+
for (i = 0; i < prefixes.length; i++) {
107+
prefix = prefixes[i]
108+
try {
109+
windowsChromiumDirectory = path.join(prefix, suffix)
110+
fsAccess.sync(windowsChromiumDirectory)
111+
return windowsChromiumDirectory
112+
} catch (e) {}
113+
}
114+
115+
return windowsChromiumDirectory
116+
}
117+
70118
function getBin (commands) {
71119
// Don't run these checks on win32
72120
if (process.platform !== 'linux') {
@@ -104,7 +152,7 @@ ChromeBrowser.prototype = {
104152
DEFAULT_CMD: {
105153
// Try chromium-browser before chromium to avoid conflict with the legacy
106154
// chromium-bsu package previously known as 'chromium' in Debian and Ubuntu.
107-
linux: getBin(['chromium-browser', 'chromium', 'google-chrome', 'google-chrome-stable']),
155+
linux: getBin(['google-chrome', 'google-chrome-stable']),
108156
darwin: getChromeDarwin('/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'),
109157
win32: getChromeExe('Chrome')
110158
},
@@ -150,6 +198,21 @@ ChromeCanaryBrowser.prototype = {
150198

151199
ChromeCanaryBrowser.$inject = ['baseBrowserDecorator', 'args']
152200

201+
ChromiumBrowser.prototype = {
202+
name: 'Chromium',
203+
204+
DEFAULT_CMD: {
205+
// Try chromium-browser before chromium to avoid conflict with the legacy
206+
// chromium-bsu package previously known as 'chromium' in Debian and Ubuntu.
207+
linux: getBin(['chromium-browser', 'chromium']),
208+
darwin: '/Applications/Chromium.app/Contents/MacOS/Chromium',
209+
win32: getChromiumExe()
210+
},
211+
ENV_CMD: 'CHROMIUM_BIN'
212+
}
213+
214+
ChromiumBrowser.$inject = ['baseBrowserDecorator', 'args']
215+
153216
var DartiumBrowser = function () {
154217
ChromeBrowser.apply(this, arguments)
155218

@@ -174,6 +237,7 @@ DartiumBrowser.$inject = ['baseBrowserDecorator', 'args']
174237
module.exports = {
175238
'launcher:Chrome': ['type', ChromeBrowser],
176239
'launcher:ChromeCanary': ['type', ChromeCanaryBrowser],
240+
'launcher:Chromium': ['type', ChromiumBrowser],
177241
'launcher:Dartium': ['type', DartiumBrowser]
178242
}
179243

0 commit comments

Comments
 (0)