@ -26,6 +26,16 @@ First of all, require the library:
const bowser = require('bowser');
const bowser = require('bowser');
```
```
By default, `require('bowser')` requires the *ES6 version of files*, which
**do not** include any polyfills.
In case if you don't use your own `babel-polyfill` you may need to have pre-built bundle with all needed polyfills.
So, for you it's suitable to require bowser like this: `require('bowser/bundled')`.
As the result, you get a ES5 version of bowser with `babel-polyfill` bundled together.
If you use bowser for Node.js, you'd better use `require('bowser/es5')`,
since source files have `import` statements, which are not compatible with Node.js yet.
## Browser props detection
## Browser props detection
Often we need to pick users' browser properties such as the name, the version, the rendering engine and so on. Here is an example how to make it with Bowser:
Often we need to pick users' browser properties such as the name, the version, the rendering engine and so on. Here is an example how to make it with Bowser:
@ -110,13 +120,6 @@ Thus, you can define OS or platform specific rules and they will have more prior
More of API and possibilities you will find in the `docs` folder.
More of API and possibilities you will find in the `docs` folder.
# Advanced Usage
By default, `require('bowser')` requires the *ES6 version of files*, which
**don't** include any polyfills. In case if you don't use your own `babel-polyfill`
you may need to have pre-built bundle with all needed polyfills.
It's possible requiring bowser like that: `require('bowser/compiled');`
As result you get a ES5 file with `babel-polyfill` bundled in it.
# Contributing
# Contributing
If you'd like to contribute a change to bowser, modify the files in `src/`, then run the following (you'll need node + npm installed):
If you'd like to contribute a change to bowser, modify the files in `src/`, then run the following (you'll need node + npm installed):
Documentation generated by <ahref="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sun Jul 08 2018 12:30:49 GMT+0300 (EEST) using the <ahref="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <ahref="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sun Jul 22 2018 19:42:18 GMT+0300 (EEST) using the <ahref="https://github.com/clenemt/docdash">docdash</a> theme.
@ -2528,7 +2679,7 @@ Returns <code>undefined</code> when the browser is no described in the checkTree
<brclass="clear">
<brclass="clear">
<footer>
<footer>
Documentation generated by <ahref="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sun Jul 08 2018 12:30:49 GMT+0300 (EEST) using the <ahref="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <ahref="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sun Jul 22 2018 19:42:18 GMT+0300 (EEST) using the <ahref="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <ahref="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sun Jul 08 2018 12:30:48 GMT+0300 (EEST) using the <ahref="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <ahref="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sun Jul 22 2018 19:42:18 GMT+0300 (EEST) using the <ahref="https://github.com/clenemt/docdash">docdash</a> theme.
@ -758,7 +758,7 @@ like <code>"iPhone"</code> or <code>"Kindle Fire HD 7"</code
<brclass="clear">
<brclass="clear">
<footer>
<footer>
Documentation generated by <ahref="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sun Jul 08 2018 12:30:49 GMT+0300 (EEST) using the <ahref="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <ahref="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sun Jul 22 2018 19:42:18 GMT+0300 (EEST) using the <ahref="https://github.com/clenemt/docdash">docdash</a> theme.
<article><h2>Bowser</h2><p>A Browser detector. Because sometimes, there is no other way, and not even good modern browsers always provide good feature detection mechanisms.</p>
<article><h2>Bowser</h2><p>A Browser detector. Because sometimes, there is no other way, and not even good modern browsers always provide good feature detection mechanisms.</p>
<li><ahref="#contributing">How can I help?</a></li>
</ul>
</ul>
<h1>Overview</h1><p>The library is made to help to detect what browser your user has and gives you a convenient API
<h1>Overview</h1><p>The library is made to help to detect what browser your user has and gives you a convenient API to filter the users somehow depending on their browsers.</p>
to filter the users somehow depending on their browsers.</p>
<p><em>Please, note that this is an alpha version. Check out the <ahref="https://github.com/lancedikson/bowser/tree/v1.x">1.x</a> branch for a stable version.</em></p>
<p><strong>Changes of the 2.0</strong>
The upcoming 2.0 version has drastically changed API. All available methods can be found in the <code>docs</code> folder from now on and on a webpage soon.</p>
<h1>Use cases</h1><p>First of all, require the library:</p>
<h1>Use cases</h1><p>First of all, require the library:</p>
<preclass="prettyprint source"><code>const Bowser = require('bowser');</code></pre><h2>Browser props detection</h2><p>Often we need to pick users' browser properties such as the name,
<preclass="prettyprint source lang-javascript"><code>const bowser = require('bowser');</code></pre><p>By default, <code>require('bowser')</code> requires the <em>ES6 version of files</em>, which
the version, the rendering engine and so on. Here is an example how to make it with Bowser:</p>
<strong>do not</strong> include any polyfills.</p>
<preclass="prettyprint source"><code>const browser = new Bowser(window.navigator.userAgent);
<p>In case if you don't use your own <code>babel-polyfill</code> you may need to have pre-built bundle with all needed polyfills.
So, for you it's suitable to require bowser like this: <code>require('bowser/bundled')</code>.
As the result, you get a ES5 version of bowser with <code>babel-polyfill</code> bundled together.</p>
<p>If you use bowser for Node.js, you'd better use <code>require('bowser/es5')</code>,
since source files have <code>import</code> statements, which are not compatible with Node.js yet.</p>
<h2>Browser props detection</h2><p>Often we need to pick users' browser properties such as the name, the version, the rendering engine and so on. Here is an example how to make it with Bowser:</p>
}</code></pre><h2>Filtering browsers</h2><p>You could want to filter some particular browsers to provide any special
}</code></pre><h2>Filtering browsers</h2><p>You could want to filter some particular browsers to provide any special support for them or make any workarounds.
support for them or make any workarounds.
It could look like this:</p>
It could look like this:</p>
<preclass="prettyprint source"><code>const browser = new Bowser(window.navigator.userAgent);
});</code></pre><p>Settings for any particular OS has more priority and redefines settings of standalone browsers.</p>
});</code></pre><p>Settings for any particular OS or platform has more priority and redefines settings of standalone browsers.
<h3>new Bowser(<code>:Object</code>)</h3><p>Use it to get object with detected flags of your current browser.</p>
Thus, you can define OS or platform specific rules and they will have more priority in the end.</p>
<h3>bowser._detect(ua <code>:String</code>)<code>:Object</code></h3><p>Use it to get object with detected flags from User Agent string.</p>
<p>More of API and possibilities you will find in the <code>docs</code> folder.</p>
<h3>bowser.check(minVersions<code>:Object</code>, strictMode<code>:Boolean</code>, [ua]<code>:String</code>)<code>:Boolean</code></h3><p>Use it to check if browser is supported. In default non-strict mode any browser family not present in <code>minVersions</code> will pass the check (like Chrome in the third call in the sample bellow). When strict mode is enabled then any not specified browser family in <code>minVersions</code> will cause <code>check</code> to return <code>false</code> (in the sample it is the fourth call, the last one).</p>
<h1>Contributing</h1><p>If you'd like to contribute a change to bowser, modify the files in <code>src/</code>, then run the following (you'll need node + npm installed):</p>
bowser.check({chrome: "45"}, true, window.navigator.userAgent); // false</code></pre><h3>bowser.compareVersions(versions<code>:Array<String></code>)<code>:Number</code></h3><p>Use it to compare two versions.</p>
// -1</code></pre><h3>bowser.isUnsupportedBrowser(minVersions<code>:Object</code>, [strictMode]<code>:Boolean</code>, [ua]<code>:string</code>)<code>:Boolean</code></h3><p>Use it to check if browser is unsupported.</p>
// true / false</code></pre><p>See more examples in <ahref="test/test.js">tests</a>.</p>
<hr>
<h2>Bowser Flags</h2><p>Your mileage may vary, but these flags should be set. See Contributing below.</p>
<preclass="prettyprint source lang-js"><code>alert('Hello ' + bowser.name + ' ' + bowser.version);</code></pre><h3>All detected browsers</h3><p>These flags are set for all detected browsers:</p>
<ul>
<li><code>name</code> - A human readable name for this browser. E.g. 'Chrome', ''</li>
<li><code>version</code> - Version number for the browser. E.g. '32.0'</li>
</ul>
<p>For unknown browsers, Bowser makes a best guess from the UA string. So, these may not be set.</p>
<h3>Rendering engine flags</h3><p>If detected, one of these flags may be set to true:</p>
<p>Safari, Chrome and some other minor browsers will report that they have <code>webkit</code> engines.
Firefox and Seamonkey will report that they have <code>gecko</code> engines.</p>
<p>For all detected browsers the browser version is set in the <code>version</code> field.</p>
<h3>OS Flags</h3><p>If detected, one of these flags may be set to true:</p>
<ul>
<li><code>mac</code></li>
<li><code>windows</code> - other than Windows Phone</li>
<li><code>windowsphone</code></li>
<li><code>linux</code> - other than <code>android</code>, <code>chromeos</code>, <code>webos</code>, <code>tizen</code>, and <code>sailfish</code></li>
<li><code>chromeos</code></li>
<li><code>android</code></li>
<li><code>ios</code> - also sets one of <code>iphone</code>/<code>ipad</code>/<code>ipod</code></li>
<li><code>blackberry</code></li>
<li><code>firefoxos</code></li>
<li><code>webos</code> - may also set <code>touchpad</code></li>
<li><code>bada</code></li>
<li><code>tizen</code></li>
<li><code>sailfish</code></li>
</ul>
<p><code>osversion</code> may also be set:</p>
<ul>
<li><code>osversion</code> - for Android, iOS, MacOS, Windows, Windows Phone, WebOS, Bada, and Tizen. If included in UA string.</li>
</ul>
<p>iOS is always reported as <code>ios</code> and additionally as <code>iphone</code>/<code>ipad</code>/<code>ipod</code>, whichever one matches best.
If WebOS device is an HP TouchPad the flag <code>touchpad</code> is additionally set.</p>
<h3>Browser capability grading</h3><p>One of these flags may be set:</p>
<ul>
<li><code>a</code> - This browser has full capabilities</li>
<li><code>c</code> - This browser has degraded capabilities. Serve simpler version</li>
<li><code>x</code> - This browser has minimal capabilities and is probably not well detected.</li>
</ul>
<p>There is no <code>b</code>. For unknown browsers, none of these flags may be set.</p>
}</code></pre><h3>Contributing</h3><p>If you'd like to contribute a change to bowser, modify the files in <code>src/</code>, then run the following (you'll need node + npm installed):</p>
$ make test</code></pre><p>Please do not check-in the built files <code>bowser.js</code> and <code>bowser.min.js</code> in pull requests.</p>
$ npm test</code></pre><h3>Adding tests</h3><p>See the list in <code>test/acceptance/useragentstrings.yml</code> with example user agents and their expected bowser object.</p>
<h3>Adding tests</h3><p>See the list in <code>src/useragents.js</code> with example user agents and their expected bowser object.</p>
<p>Whenever you add support for new browsers or notice a bug / mismatch, please update the list and
<p>Whenever you add support for new browsers or notice a bug / mismatch, please update the list and
check if all tests are still passing.</p>
check if all tests are still passing.</p>
<h3>Similar Projects</h3><ul>
<h3>Similar Projects</h3><ul>
@ -236,7 +144,7 @@ check if all tests are still passing.</p>
<brclass="clear">
<brclass="clear">
<footer>
<footer>
Documentation generated by <ahref="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sun Jul 08 2018 12:30:49 GMT+0300 (EEST) using the <ahref="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <ahref="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sun Jul 22 2018 19:42:18 GMT+0300 (EEST) using the <ahref="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <ahref="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sun Jul 08 2018 12:30:48 GMT+0300 (EEST) using the <ahref="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <ahref="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sun Jul 22 2018 19:42:18 GMT+0300 (EEST) using the <ahref="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <ahref="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sun Jul 08 2018 12:30:48 GMT+0300 (EEST) using the <ahref="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <ahref="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sun Jul 22 2018 19:42:18 GMT+0300 (EEST) using the <ahref="https://github.com/clenemt/docdash">docdash</a> theme.