Blog

Posts written in 2015.

  • Published on
    -
    1 min read

    Detecting Facebook In-App Browser

    It seems there is going to be a growing trend where apps on our mobile devices will open webpages whilst you are inside the app itself instead of using the devices' native browser. A prime example of this is Facebook. In recent updates during the tail end of last year, both their iOS and Android offerings open webpages from within the application.

    This isn't a bad thing. In fact I quite like having webpages opening within the application, since this creates a nice seamless experience. However, the Facebook in-app browser doesn't seem to render a webpage in the same manner as the devices' own native browser (Safari/Chrome). I started noticing this whilst working on a complex website that was very much custom JavaScript driven.

    The only thing I could do is modify specific mark-up or features that affected my website negatively when opened from within Facebook by detecting the user-agent. In my code (using ASP.NET C#), I was required to carry out additional browser checks:

    //User is within Facebook browser.
    if (Request.UserAgent.IndexOf("FBAN") > -1)
    {
        if (Request.UserAgent.Contains("iPhone OS 8_0_2"))
        {
            //You are using iPhone version 8.0.2.
        }
        
        if (Request.UserAgent.Contains("Chrome"))
        {
            //You are in the Facebook App in Android.
        }
    }
    else
    {
        //You are not in Facebook App.
    }
    

    You can modify the code above to create a nice self-contained method to return an enumeration as I ended up doing to be used when required.