Search code examples
javascriptgoogle-signinfedcm

AbortError Occurs When Calling google.accounts.id.prompt


I am implementing the Sign In With Google feature on a webpage, following the guidance on this page: https://developers.google.com/identity/gsi/web/reference/js-reference.

I wanted to make it so that when our custom-styled button is pressed, the Sign In With Google popup would appear. Thus, I've made it so that google.accounts.id.prompt is called upon button click as follows:

<html>
  <body>
    <script src="https://accounts.google.com/gsi/client" async></script>
    <script>
      function handleCredentialResponse(response) {
        console.log("Encoded JWT ID token: " + response.credential);
      }
      window.onload = function () {
        google.accounts.id.initialize({
          client_id: "XXXXXXXXX.apps.googleusercontent.com",
          callback: handleCredentialResponse
        });
        document.getElementById("buttonDiv").onclick = function() {
          google.accounts.id.prompt();
        };
      }
    </script>
    <div id="buttonDiv">test</div>
  </body>
</html>

Recently, I've noticed that this functionality has stopped working. When calling google.accounts.id.prompt, the following error message is outputted to the Dev Console, and the login popup does not appear:

[GSI_LOGGER]: FedCM get() rejects with AbortError: Request has been aborted.

I noticed this error on April 7 2024. I do not know when it started occurring, but as of March 20 2024, it was working without issues. Moreover, this issue occurs on Google Chrome, but not on Firefox.

Could there be any potential causes and solutions for this issue?


Solution

  • That was actually a bug in the Sign in with Google One Tap library. The bug is fixed. You should be able to call google.accounts.id.prompt() directly without using the setTimeout() workaround.