45

I'm developing website with a lot of HTML5 and CSS3 features. I'm also using iframe to embed several content on my website. It works fine if I open it using Chrome/Firefox/Safari mobile browser. However, if I share on facebook (post/page) and I opened it up with Facebook application with Facebook Internal Browser, my website is messed up.

Is there any tools or way to debug on Facebook Browser? Thanks.

Eldwin Eldwin
  • 1,084
  • 2
  • 11
  • 29

5 Answers5

27

This is how you can do the debugging yourself. It's painful, but the only way I've come across so far.

tl;dr Get the Facebook App loading a page on your local server so you can iterate quickly. Then print debug statements directly to the page until you figure out what is going on.

  1. Get a link to a page on your local server that you can access on your mobile device (test in mobile safari that it works). See this to find out your local IP address How do you access a website running on localhost from iPhone browser. It will look something like this http://192.xxx.1.127:3000/facebook-test

  2. Post that link on your Facebook page (you can make it private so your friends aren't all like WTF?)

  3. Click the posted link in the Facebook mobile App and it will open up in Facebook's mobile browser

  4. Since you don't have a console, you basically need to print debug statements directly to the page so it is visible. Put debug statements all over your code. If your problems are primarily related to CSS, then you can iteratively comment out stuff until you've found the issue(s) or print the relevant CSS attributes using JavaScript. Eg something like (using JQuery)

    function debug(str){$('body').append("<br>"+str);}

  5. Quite possibly the most painful part. The Facebook browser caches very aggressively. If you are making changes and nothing has happened, it's because the content is cached. You can sometimes resolve this by updating the URLs, eg /facebook-test-1, /facebook-test-2, or adding dummy parameters eg /facebook-test?dummy=1. But if the changes are in external css or js sheets it sometimes will still cache. To 100% clear the cache, delete the Facebook App from your mobile device and reinstall.

Community
  • 1
  • 1
AllTheCodez
  • 305
  • 4
  • 8
  • 1
    How you are capturing error log? Can you please share sample code? how debug(str) function will trigger? – A Qadeer Qureshi Aug 29 '17 at 13:40
  • Maybe things have changed but step 2 is not possible - no way to create a private post that nobody else will see. – Andrew Oct 24 '19 at 16:17
  • Seems like that does not work anymore. Facebook will not create a link if the page is not accessible for it. So you have to somehow publicly expose it (e.g.: port forwarding in your router) and create a link to your public IP (or a dynamic DNS URL) for it to work. Quite unfortunate. – xtj7 Dec 17 '20 at 10:57
  • FWIW, I've been able to make this work with the same strategy, and step 4 can be greatly helped by a mobile devtools library like https://github.com/liriliri/eruda which basically adds some actual devtools UI, captures console, allows some basic element manipulation, etc. – Alessandro Jeanteur Jul 26 '21 at 22:09
8

The internal browser the Facebook app uses is essentially a uiWebView. Paul Irish has made a simple iOS app that lets you load any URL into a uiWebView which you then can debug using Safari's Developer Tools.

https://github.com/paulirish/iOS-WebView-App

Simen Brekken
  • 1,468
  • 1
  • 15
  • 23
  • Please note that this is about to change according to recent news. Facebook is changing it's model to use a custom embedded browser they provide instead of the system WebView. – Bence Szalai Oct 21 '22 at 10:10
8

I found a way how to debug it easier. You will need to install the Ghostlab app (You have a 7-day free trial there, however it's totally worth paying for).

  1. In Ghostlab, add the website address (or a localhost address) you want to debug and start the session.
  2. Ghostlab will generate a link for access.
  3. Copy that link and post it on Facebook (as a private post)
  4. Open the link on mobile and that's it! Ghostlab will identify you once you open that link, and will allow you to debug the page.

For debugging, you will have all the same tools as in the Chrome devtools (how cool is that!). For example, you can tweak CSS and see the changes applied live.

Lys
  • 111
  • 1
  • 4
2

If you want to debug a possible error, you can try to catch it and display it.

Put this at the very top of your code:

window.onerror = function (msg, url, lineNo, columnNo, error) {
    var string = msg.toLowerCase();
    var substring = "script error";
    if (string.indexOf(substring) > -1){
        alert('Script Error: See Browser Console for Detail');
    } else {
        var message = [
            'Message: ' + msg,
            'URL: ' + url,
            'Line: ' + lineNo,
            'Column: ' + columnNo,
            'Error object: ' + JSON.stringify(error)
        ].join(' - ');

        alert(message);
    }
}

(Source: MDN)

This will catch and alert your errors.

Share a link on Facebook (privately), or send yourself a message on Facebook Messenger (easier). To break the cache, create a new URL every time, e.g. by appending a random string to the URL.

Follow the link and see if you can find any errors.

nicoqh
  • 1,213
  • 12
  • 21
2
  • With help of ngrok create temporary http & https adress instead of your ordinary localhost:3000(or other port) and you could run your app on any devices. It is super easy to use.
  • and as it was written above all other useful information you should write somewhere inside div element (in case of React I recommend to put onClick on that div with force update or other function for getting info, sometimes it helps because JS in FB could be executed erlier than your information appears). Keep in mind that alerts are not reliable, sometimes they are blocked
  • bonus from ngrok that in console you will see which files was requested and response code (it will replace lack of network tab)
  • and about iFrame.If you use it on other domain and you rely on cookies - you should know that facebook in-app browser blocks 3rd party cookies
  • test on Android and iOS separately because technicaly they use different browsers

exampe in windows console

Dmitriy Sakhno
  • 453
  • 3
  • 8
  • Not sure this is what he meant. – advance512 May 08 '19 at 12:13
  • Thanks for the comment. I agree with you. Have made some changes in my answer. At the moment when I wrote it network tab was the thing which solved my problem ( on Android device FB blocked one of my JS file from execution and I understood it by checking that it was downloaded) – Dmitriy Sakhno May 08 '19 at 13:49
  • also aproach with creating https could prevents other possible bugs when FB blocks unsecure http connection which is provided with usual approach http//your_ip_adress. Especially it's relevant if you develop iframe – Dmitriy Sakhno May 08 '19 at 13:58