GoogleAuth library loading with promises
<p>I am trying to load google authentication library using promises, but I fail when I try to call gapi.auth2.getAuthInstance() and return it in promise;</p>

<p>Here's how I am doing this:</p>

<pre><code>var loadPlatform = function ($q) {
    var deferred = $q.defer(),
        platform = document.createElement('script');

    platform.src ='https://apis.google.com/js/platform.js';
    platform.type = 'text/javascript';
    platform.async = true;
    platform.defer = true;
    platform.onload = deferred.resolve;
    platform.onerror = deferred.reject;

    document.body.appendChild(platform);

    return deferred.promise;
};

//I return this from other function
return loadPlatform($q)
    .then(function () {
        var deferred = $q.defer();

        gapi.load('auth2', function () {
            deferred.resolve(gapi.auth2);
        });

        return deferred.promise;
    })
    .then(function (auth2) {
        //This function retuns Promise
        //https://developers.google.com/identity/sign-in/web/reference#gapiauth2initparams
        return auth2.init(params);
    })
    .then(function (GoogleAuth) {
        //Here I should have solved GoogleAuth object
    });
</code></pre>

<p>Everything works until I return auth2.init(params) then browser freezes.
What's happening here?</p>