Skip to content

Instantly share code, notes, and snippets.

@jhurliman
Created October 21, 2011 05:53
Show Gist options
  • Save jhurliman/1303191 to your computer and use it in GitHub Desktop.
Save jhurliman/1303191 to your computer and use it in GitHub Desktop.
Add a custom timeout to FB.getLoginStatus()
/* Add this somewhere after FB.init() and before any calls to FB.getLoginStatus() */
// Add a timeout to FB.getLoginStatus()
var FB_STATUS_TIMEOUT = 1000 * 30;
var origGetLoginStatus = FB.getLoginStatus;
FB.getLoginStatus = function(callback, force) {
// Start a timer
var timedOut = false;
var timeout = setTimeout(function() {
timedOut = true;
if (callback) callback({ error: 'timeout' });
}, FB_STATUS_TIMEOUT);
// Call the real FB.getLoginStatus()
origGetLoginStatus(function(response) {
if (!timedOut) {
clearTimeout(timeout);
if (callback) callback(response);
}
}, force);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment