Search code examples
javascriptfacebookurlquery-stringurlvariables

How to avoid the login window when accessing a Facebook profile page onload?


It can be anything; like a URL variable that we can put after or in front of the URL to avoid the login window when accessing a Facebook page...

So: we have a redirect to https://www.facebook.com/szabo.zsolt.guriga, but we'd like, at least, to temporarily disable the login window, so it doesn't show up immediately.

Currently, we see this in an instant when visiting the page:

screenshot-of-the-problem

Unfortunately, there's no change in the URL when closing that window...


Solution

  • Short answer:
    there's no way to do it... for my own special requirements (to show the profile page content without the login window for those who don't yet have Facebook account and never logged in).

    I found that the Facebook API's prerequisite is the user's "logging in".

    If the user has never logged in, it is requested from Facebook in the form of the window in question that will appear. There's no way to bypass this due to privacy policies.

    ...but the window can be closed, and the profile can be viewed partially.

    EDIT:
    after all, we figured out that we can't do much about what we face on desktop, but on mobile: the site was redirected to the Facebook app (and the client wasn't logged in there) from the browser. So, to forward the redirection to the browser and keeping it there, we had to use this script -- that might be relevant for others as well:

    <script>
    document.addEventListener("DOMContentLoaded", function() {
      var url = "https://www.facebook.com/szabo.zsolt.guriga?_rdr"; // facebook link with the ?_rdr query string
      var isMessenger = navigator.userAgent.includes("FBAN") || navigator.userAgent.includes("FBAV");
      var isAndroid = navigator.userAgent.toLowerCase().includes("android");
    
      if (isMessenger || isAndroid) {
        // forcing the opening of Chrome under Android
        var chromeUrl = "intent://" + url.replace("https://", "").replace("http://", "") +
          "#Intent;scheme=https;package=com.android.chrome;S.browser_fallback_url=" + encodeURIComponent(url) + ";end;";
    
        window.location.href = chromeUrl; // forcing Chrome to open 
      } else {
        // if not Android then normal redirect
        window.location.href = url;
      }
    
      // delete history for the Facebook not to throw back
      window.history.replaceState({}, document.title, window.location.pathname);
    });
    </script>