Are there any way to detect that user opens lightning component within Salesforce1 or within separate app?

2 Answers 2


Some events are handled specifically within Salesforce1, so you can use that to check context. See this link for a list of Salesforce1 events.

This example displays a toast message in Salesforce1 but not in a standalone/separate app.

var toast = $A.get("e.force:showToast");
if (toast){
        "title": "Success!",
        "message": " Your contacts have been loaded successfully."
} else {
        console.log("not in Salesforce1");

Update - April 9, 2015 I was advised by an S1 developer that you can also use $A.getContext().getApp() to get context.

if (context=="one:one") {
            //you're running Salesforce1
        else {
            //you're running a standalone app

See the JavaScript API docs (https://[your-salesforce-instance]/auradocs/reference.app#reference?topic=api:Aura) for more details.

  • Looks like they updated this to context=="native:bridge" worry that this is not best practice although does appear to work on ios / android.. Nov 10, 2015 at 7:24
  • 1
    In 2017 I don't see getContext() or getApp() methods in $A documentation... any updated solution?
    – Wookie88
    Sep 5, 2017 at 13:01

I Know its old question but might be help full for other users as of new release, there is support by salesforce to find the context

 const device = $A.get("$Browser.formFactor"); // DESKTOP,PHONE

Returns Desktop or Phone


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.