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
ember install ember-useragent
Fastboot
Should you be using Fastboot in your application, Ember UserAgent >=0.2.0 requires Ember CLI Fastboot >=1.0.0.
Ember UserAgent exposes a service, which is automatically injected into controllers, components and routes.
const userAgent = this.get('userAgent');
userAgent.get('browser.isChrome'); // Boolean
userAgent.get('engine.isWebKit'); // Boolean
userAgent.get('os.info'); // => { name: 'Ubuntu', version: '11.10' }
userAgent.getDevice(); // => { model: 'iPhone 7', type: 'mobile', vendor: 'Apple'}
The service exposes all of UAParser's functions, but also adds some properties for quick access.
browser | device | engine | os | userAgent |
---|---|---|---|---|
info | info | info | info | |
isChrome | isConsole | isWebKit | isAndroid | |
isChromeHeadless | isDesktop | isIOS | ||
isEdge | isMobile | isLinux | ||
isFirefox | isTablet | isMacOS | ||
isIE | isWindows | |||
isSafari | isWindows |
There aren't many use cases for using it manually, but Ember UserAgent shims UAParser.js into your application. Access it in one of two ways.
Module import:
import UAParser from 'ua-parser-js';
Or from the service:
{
userAgent: service(),
UAParser: alias('userAgent.UAParser')
}
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.
For more information on how to use UAParser.js, please refer to the documentation.