lightning component

How To Detect a Device In Salesforce Lightning Component ?

Lightning Component

In some of our use cases, we might have to know the device that user is in. This post explains how we can detect a device in Lightning Component.

The $Browser global value provider returns information about the hardware and operating system of the browser accessing the application.

{!$Browser.isTablet}      > To detect the tablet device
{!$Browser.isPhone}      > To detect the user is in Mobile Phone / mobile browser
{!$Browser.isAndroid}   > To detect the user is in Android device
{!$Browser.formFactor} > Returns a FormFactor enum value based on the type of hardware the browser is                                                            running on.

DESKTOP for a desktop client
PHONE for a phone including a mobile phone with a browser and a smartphone
TABLET for a tablet client (for which isTablet returns true)


Create a new lightning component : DetectMyDevice.cmp

Create a Lightning Application (


lightning component

To detect a device in JavaScript controller:

var device = $A.get("$Browser.formFactor");

Check Also : How to Use Design Resource In Lightning Component Bundle?


Lightning Developer Guide

About The contributor: 


Leave a Reply