Karma runner plugin for detecting all browsers installed on the current system.
npm install karma-detect-browserskarma-detect-browsers as a devDependency in your package.json.
json
{
"devDependencies": {
"karma": "^0.13",
"karma-detect-browsers": "^2.0"
}
}
`
You can simply do it by:
`bash
npm install karma-detect-browsers --save-dev
`
Get started
* add detectBrowsers as framework and plugin to your karma config file
* add the karma browser plugins for all the browser installed on your system
* add the karma browser plugins to the package.json file
`js
// karma.conf.js
module.exports = function(config) {
config.set({
frameworks: ['detectBrowsers'],
plugins: [
'karma-chrome-launcher',
'karma-edge-launcher',
'karma-firefox-launcher',
'karma-ie-launcher',
'karma-safari-launcher',
'karma-safaritechpreview-launcher',
'karma-opera-launcher',
'karma-phantomjs-launcher',
'karma-detect-browsers'
]
});
};
`
Configuration
`js
// karma.conf.js
module.exports = function(config) {
config.set({
frameworks: ['detectBrowsers'],
// configuration
detectBrowsers: {
// enable/disable, default is true
enabled: true,
// enable/disable phantomjs support, default is true
usePhantomJS: true,
// use headless mode, for browsers that support it, default is false
preferHeadless: true,
// post processing of browsers list
// here you can edit the list of browsers used by karma
postDetection: function(availableBrowsers) {
/* Karma configuration with custom launchers
customLaunchers: {
IE9: {
base: 'IE',
'x-ua-compatible': 'IE=EmulateIE9'
}
}
*/
//Add IE Emulation
var result = availableBrowsers;
if (availableBrowsers.indexOf('IE')>-1) {
result.push('IE9');
}
//Remove PhantomJS if another browser has been detected
if (availableBrowsers.length > 1 && availableBrowsers.indexOf('PhantomJS')>-1) {
var i = result.indexOf('PhantomJS');
if (i !== -1) {
result.splice(i, 1);
}
}
return result;
}
},
plugins: [
'karma-chrome-launcher',
'karma-edge-launcher',
'karma-firefox-launcher',
'karma-ie-launcher',
'karma-safari-launcher',
'karma-safaritechpreview-launcher',
'karma-opera-launcher',
'karma-phantomjs-launcher',
'karma-detect-browsers'
]
});
};
`
Contributing
In lieu of a formal styleguide take care to maintain the existing coding style. Lint and test your code using grunt.
You can preview your changes by running:
`bash
grunt demo
`
Release History
$3
* Fix path for Chromium browser in macOS
$3
* Remove extra check if browsers are listed as plugin in the karma config file
$3
* Fix log output of the browsers used, take possible changes made in the postDetection() function into account
$3
* Split Chrome and Chromium
* Add support for headless mode in Chrome and Firefox
* Add check if all browser launchers are installed
* Preserve browser config for non-detectable browsers like SauceLabs
$3
* Fix problem with stating multiple Firefox instances in Linux
$3
* Update edge launcher binary path
$3
* Update Edge detection to follow bug fixes in karma-edge-launcher
$3
* Edge.js will always return a browser object
$3
* Fix error with Edge module on unix systems
$3
* Fix for build errors on unix systems
$3
* Add support for detecting Microsoft Edge browser
$3
* Add support for detecting Safari Tech Preview
$3
* Add some executables names for the Chrome browser in Linux
$3
* Drop peerDependencies so that the user has full control which karma browser plugins are installed via npm
* This is a breaking change since now you have to manually add the karma browser plugins to the package.json` file of your project