'Google Auth don't work in mobile popup_closed_by_user error

I created an web application (js) that connects with Google. It works on PC but not on mobile. The error indicated is popup_closed_by_user while I did not close the popup!! I would like some help please, here is an example:

    <!DOCTYPE html>   
        <html lang="en">
        <head> 
          <script src="https://apis.google.com/js/api:client.js"></script>
            <title>Document</title>
        </head>
        <body>
<h3>warning: there is Script Error bc client id is not entered. this example don't work in stackoverflow code snippet</h3>
            <h1>name: <span id="namegoogle">not connected</span></h1>
            <h1>image: <img id="img_google" alt="not connected"/></h1>
            <button id="customBtn">GOOGLE: click to connect</button>
            <p>ERROR: <span id="errorgoogle">[NO ERROR]</span></p><br><br><h3>WARNING: CLIENT ID IS NOT DECLARED</h3>
        </body>
        <script>var is_google_user_succed_942894 = false;
    var google_getGivenName = "";var google_getFamilyName = "";var google_getAvatarUrl = "";
    var googleUser = {};var startApp = function() {
            gapi.load('auth2', function(){
              // Retrieve the singleton for the GoogleAuth library and set up the client.
              auth2 = gapi.auth2.init({
                client_id: '################################################################################################.apps.googleusercontent.com',
                cookiepolicy: 'single_host_origin',
                // Request scopes in addition to 'profile' and 'email'
                //scope: 'additional_scope'
              });
              attachSignin(document.getElementById('customBtn'));
            });
          };
    startApp();
          function attachSignin(element) {
            console.log(element.id);
            auth2.attachClickHandler(element, {},
                function(googleUser) {
    document.getElementById("namegoogle").innerHTML = googleUser.getBasicProfile().getName();
        document.getElementById("img_google").src = googleUser.getBasicProfile().getImageUrl();
              }, function(error) {
                  var error_msg = error['error']; document.getElementById('errorgoogle').innerHTML = error_msg;
                });
    }
        </script><script src="https://apis.google.com/js/platform.js?onload=renderButton" async defer></script>
        </html>


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source