Skip to content
An Ember addon for Fastboot-enabled UserAgent parsing via UAParser.js.
JavaScript HTML
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
addon [BUG] fix deprecation warning Apr 8, 2019
app Add helper for user agent service properties Oct 8, 2018
blueprints/ember-useragent Swaps ember-cli-cjs-transform for ember-auto-import Nov 14, 2018
config
tests deps: updates ember-cli@3.9.0 Apr 18, 2019
vendor
.editorconfig Initial Commit from Ember CLI v2.11.0 Feb 10, 2017
.ember-cli Initial Commit from Ember CLI v2.11.0 Feb 10, 2017
.eslintignore deps: updates ember-cli@3.9.0 Apr 18, 2019
.eslintrc.js deps: updates ember-cli@3.9.0 Apr 18, 2019
.gitignore deps: updates ember-cli@3.9.0 Apr 18, 2019
.npmignore deps: updates ember-cli@3.9.0 Apr 18, 2019
.template-lintrc.js deps: updates ember-cli@3.9.0 Apr 18, 2019
.travis.yml deps: updates ember-cli@3.9.0 Apr 18, 2019
.watchmanconfig Initial Commit from Ember CLI v2.11.0 Feb 10, 2017
CONTRIBUTING.md
LICENSE.md deps: updates ember-cli@3.9.0 Apr 18, 2019
README.md
ember-cli-build.js Updates to Ember CLI 3.0.0 Mar 2, 2018
index.js
package-lock.json
package.json 0.9.1 Apr 18, 2019
testem.js chore(deps): run ember-cli-update Aug 1, 2018

README.md

Ember UserAgent Build Status Ember Observer Score Download count all time npm

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

Compatibility

  • Ember.js v2.18 or above
  • Ember CLI v2.13 or above

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'); // Boolean
userAgent.get('engine.isWebKit'); // Boolean
userAgent.get('os.info'); // => { name: 'Ubuntu', version: '11.10' }
userAgent.get('device.info'); // => { model: 'iPhone 7', type: 'mobile', vendor: 'Apple'}

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 auto imports ua-parser-js into your application using ember-auto-import:

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.

You can’t perform that action at this time.