Ember UserAgent

Ember UserAgent is an Ember Addon for UserAgent parsing via UAParser.js.
The userAgent
service works in both browser & Fastboot environments and makes it easy to detect:
- Device Type
- Device Model
- Browser
- Operating System
- Layout Engine
- CPU architecture
Installation
ember install ember-useragent
Usage
Ember UserAgent exposes a (1) service, which is automatically injected into controllers, components and routes, and a (2) template helper.
Service
const userAgent = this.get('userAgent');
userAgent.get('browser.isChrome');
userAgent.get('engine.isWebKit');
userAgent.get('os.info');
userAgent.get('device.info');
Helper
{{#if (user-agent "browser.isChrome")}}
Chrome, here...
{{/if}}
Service Properties
The service exposes all of UAParser's functions, but also adds some properties for quick access.
browser | device | engine | os | cpu |
---|
info | info | info | info | architecture |
isChrome | isConsole | isWebKit | isAndroid | |
isChromeHeadless | isDesktop | | isIOS | |
isEdge | isMobile | | isLinux | |
isFirefox | isTablet | | isMacOS | |
isIE | | | isWindows | |
isSafari | | | | |
The service also exposes the userAgent
property, which contains the user agent string.
You can overwrite this property, if you want to force a certain user agent string.
All of the properties described above will update in accordance.
Manual Usage
Ember UserAgent shims UAParser.js into your application. You can import it like any other module:
import UAParser from 'ua-parser-js';
Injection
By default, this addon will generate an initializer in app/initializers/user-agent.js
that injects the userAgent
service app-wide. If the userAgent
property conflicts with other addons or you wish to use manual injection (Ember.service.inject
) you can override this file.
Using UAParser.js
For more information on how to use UAParser.js, please refer to the documentation.