Need help upgrading to Ionic Framework 4.0? Get assistance with our Enterprise Migration Services EXPLORE NOW

User Agent

Improve this doc

The UserAgent plugin provides functions to set the HTTP user-agent header. For more info about User-Agents, please see the HTTP User-Agent docs.

Requires Cordova plugin: cordova-useragent. For more info, please see the User-Agent plugin docs.

Repo: https://github.com/danielsogl/cordova-plugin-useragent

Installation

  1. Install the Cordova and Ionic Native plugins:
    $ ionic cordova plugin add cordova-plugin-useragent
    $ npm install --save @ionic-native/[email protected]
    
  2. Add this plugin to your app's module

Supported platforms

Usage

import { UserAgent } from '@ionic-native/user-agent';


constructor(private userAgent: UserAgent) { }

...


this.userAgent.set('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36')
  .then((res: any) => console.log(res))
  .catch((error: any) => console.error(error));

* this.userAgent.get()
  .then((res: any) => console.log(res))
  .catch((error: any) => console.error(error));

* this.userAgent.reset()
  .then((res: any) => console.log(res))
  .catch((error: any) => console.error(error));

Instance Members

set(userAgent)

Changes the current user-agent to the one sent by argument.

Param Type Details
userAgent string

User-Agent

Returns: Promise<any> Returns a promise that resolves when the user-agent changes

get()

Returns the current user-agent string.

Returns: Promise<any> Returns a promise that resolves when the user-agent is returned

reset()

Sets the user-agent back to default

Returns: Promise<any> Returns a promise that resolves when the user-agent resets

API

Native

General