46

Have you had any experience in Facebook in-app browser detection? What's the core difference in user agent?

I don't want to know if it is a only mobile/ios/chrome. I need to know whether user agent is specific from Facebook in-app browser

milosz0010
  • 499
  • 1
  • 5
  • 7

4 Answers4

79

You can check for FBAN / FBAV in the user agent.

Check this link: Facebook user agent

Machavity
  • 28,730
  • 25
  • 78
  • 91
Jan Swart
  • 5,489
  • 6
  • 29
  • 40
  • What does ua.indexOf("FBAN") > -1 and ua.indexOf("FBAV") > -1 mean? Force out user to use web browser instead of in-apps browser? – Robbi Nespu Dec 08 '16 at 20:18
  • 1
    @RobbNesp `var us = navigator.userAgent` gives you a string value. `.indexOf()` checks for the position of a sub-string in a string. If it is not found a value of -1 is returned. It is simply checking if it is the Facebook browser, by checking if the browser's user agent contains either of the given sub strings. – Jan Swart Dec 11 '16 at 07:27
  • 8
    Thanks! Sharing snippet for Instagram also: `(ua.indexOf('Instagram') > -1)` – jeff_drumgod Oct 02 '18 at 23:43
  • I added the snippet to the answer, thanks @jeff_drumgod – svelandiag Mar 02 '20 at 17:29
  • 2
    Can you explain the `|| window.opera` bit? I don't think it would cast to the user agent string. – DrLightman Oct 15 '20 at 07:27
  • Thanks a zillion. – Jagruti May 20 '21 at 15:12
30

To complete worker11811's answer on using the user agent, here's a code snippet to make it work:

function isFacebookApp() {
    var ua = navigator.userAgent || navigator.vendor || window.opera;
    return (ua.indexOf("FBAN") > -1) || (ua.indexOf("FBAV") > -1);
}
Sascha
  • 766
  • 1
  • 9
  • 17
1

You can use https://www.npmjs.com/package/detect-inapp and check if inapp.isInApp() is true

DonnaTelloo
  • 160
  • 11
-16

this javascript works well

var standalone = window.navigator.standalone,
    userAgent = window.navigator.userAgent.toLowerCase(),
    safari = /safari/.test( userAgent ),
    ios = /iphone|ipod|ipad/.test( userAgent );

if( ios ) {
    if ( !standalone && safari ) {
        //browser
    } else if ( standalone && !safari ) {
        //standalone
    } else if ( !standalone && !safari ) {
        //uiwebview (Facebook in-app browser)

    };
} else {
    //not iOS
};