Reputation: 911
I integrated my project with Facebook authorization https://developers.facebook.com/docs/facebook-login/web
The Rollbar shows next error
TypeError: this.onready is not a function. (In 'this.onready(a)', 'this.onready' is undefined)
from file https://connect.facebook.net/en_US/sdk.js
from the internal browser of the facebook IOS application (version 172, 171, 170).
Tell me please what the problem is and how to fix it?
$.ajaxSetup({cache: true});
window.fbAsyncInit = function() {
if(typeof FB != 'undefined'){
FB.init({
appId : fb_app_id,
cookie : true,
xfbml : true,
version : 'v2.8'
});
FB.getLoginStatus(function(response) {
if (response.status == 'connected') {
onLogin(response);
} else {
FB.login(function(response) {
onLogin(response);
}, {scope: 'user_friends, email'});
}
});
}
else{
Rollbar.debug("Not loaded base SDK");
return false;
}
};
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "https://connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
function checkLoginState() {
if(typeof FB == 'undefined'){
Rollbar.debug("FB is undefined. Was a problem loading the Facebook resources. Maybe your provider temporarily blocks this resource");
return false;
}
FB.getLoginStatus(function(response) {
onLogin(response);
});
}
Upvotes: 2
Views: 503
Reputation: 1045
We are having the same problem.
It looks like there's a bug in Facebook's code. Inside the SDK -
var i = "fbNativeReady";
a = {
onready: function(a) {
__p && __p();
if (!h.nativeApp()) {
g.error("FB.Native.onready only works when the page is rendered in a WebView of the native Facebook app. Test if this is the case calling FB.UA.nativeApp()");
return
}
window.__fbNative && !this.nativeReady && ES("Object", "assign", !1, this, window.__fbNative);
if (this.nativeReady) a();
else {
var b = function b(c) {
window.removeEventListener(i, b), this.onready(a)
};
window.addEventListener(i, b, !1)
}
}
};
You can see that the event listener "b" isn't bound, so when the event "fbNativeReady" is dispatched, the listener is invoked without a context, meaning "this" is window, and no "onready" function exists on it.
binding b to "this" can fix this issue.
A possible solution can be to run this code after a certain delay to avoid having fbNativeReady event dispatched after the code was loaded
Upvotes: 0