How to debug on Facebook Internal Browser (Mobile)?

后端 未结 5 1872
萌比男神i
萌比男神i 2020-12-15 16:54

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

相关标签:
5条回答
  • 2020-12-15 16:58

    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.

    0 讨论(0)
  • 2020-12-15 16:58
    • 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

    0 讨论(0)
  • 2020-12-15 17:14

    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

    0 讨论(0)
  • 2020-12-15 17:14

    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.

    0 讨论(0)
  • 2020-12-15 17:18

    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.

    0 讨论(0)
提交回复
热议问题