Skip to content

[google_sign_in_web] googleSignIn.signIn() hangs forever if can't connect to apis.google.com #70427

Closed
flutter/packages
#9267

Description

@treeder

Steps to Reproduce

  1. In Chrome dev tools, add apis.google.com in "Network request blocking" tab
  2. call: var user = await googleSignIn.signIn()

Nothing will happen and it will never return.

Expected results:

Expect an error.

Actual results:

Nothing, it never returns. eg:

print("before signIn");
user = await _googleSignIn.signIn();
print("after signIn");

"after signIn" never prints and no error is thrown.

Activity

  1. TahaTesser commented on Nov 13, 2020

    @TahaTesser
    Contributor

    Hi @treeder
    Is there a reason to block apis.google.com, can you please provide more details

    I can reproduce the issue

    code sample
    import 'package:flutter/material.dart';
    import 'package:google_sign_in/google_sign_in.dart';
    
    GoogleSignIn _googleSignIn = GoogleSignIn(
      scopes: <String>[
        'email',
        'https://www.googleapis.com/auth/contacts.readonly',
      ],
    );
    
    void main() => runApp(MyApp());
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Material App',
          theme: ThemeData.dark(),
          home: Home(),
        );
      }
    }
    
    class Home extends StatefulWidget {
      @override
      _HomeState createState() => _HomeState();
    }
    
    class _HomeState extends State<Home> {
      String userName;
      bool iSignedIn = false;
      GoogleSignInAccount _currentUser;
    
      @override
      void initState() {
        super.initState();
        _googleSignIn.onCurrentUserChanged.listen((GoogleSignInAccount account) {
          setState(() {
            _currentUser = account;
          });
          if (_currentUser != null) {
            setState(() {
              iSignedIn = true;
              userName = account.displayName;
            });
          }
        });
        _googleSignIn.signInSilently().then((value) {
          if (value != null) {
            setState(() {
              userName = value.displayName;
            });
          }
        });
      }
    
      Future<void> _handleSignIn() async {
        try {
          await _googleSignIn.signIn();
        } catch (error) {
          print(error);
        }
      }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: Text('Material App Bar'),
          ),
          body: Center(
            child: Container(
              child: Text(iSignedIn ? userName : 'empty user name'),
            ),
          ),
          floatingActionButton: FloatingActionButton.extended(
            icon: Icon(Icons.add),
            label: Text(iSignedIn ? 'Sign Out' : 'Sign In'),
            onPressed: () {
              if (!iSignedIn) {
                _handleSignIn();
              } else {
                _googleSignIn.signOut();
                setState(() {
                  iSignedIn = false;
                });
              }
            },
          ),
        );
      }
    }
    
    logs
    PS C:\Users\taha\AndroidStudioProjects\triage\flutter_plugin_examples\google_signin_example> flutterb run -d chrome --debug  --web-hostname localhost --web-port 7357
    Launching lib\main.dart on Chrome in debug mode...
    Syncing files to device Chrome...                                       
     8,289ms (!)
    Debug service listening on ws://127.0.0.1:53194/pRR4YSLUgYo=
    
    Warning: Flutter's support for web development is not stable yet and hasn't
    been thoroughly tested in production environments.
    For more information see https://flutter.dev/web
    
      To hot restart changes while running, press "r" or "R".
    For a more detailed help message, press "h". To quit, press "q".
    [object Object]
    [object Object]
    

    Package version

    google_sign_in: ^4.5.6
    flutter doctor -v
    [✓] Flutter (Channel beta, 1.23.0-18.1.pre, on Microsoft Windows [Version 10.0.19042.610], locale en-US)
        • Flutter version 1.23.0-18.1.pre at C:\Code\flutter_beta
        • Framework revision 198df796aa (4 weeks ago), 2020-10-15 12:04:33 -0700
        • Engine revision 1d12d82d9c
        • Dart version 2.11.0 (build 2.11.0-213.1.beta)
    
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
        • Android SDK at C:\Code\sdk
        • Platform android-30, build-tools 30.0.2
        • Java binary at: C:\Code\android-studio\jre\bin\java
        • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
        • All Android licenses accepted.
    
    [✓] Chrome - develop for the web
        • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
    
    [✓] Android Studio (version 4.1.0)
        • Android Studio at C:\Code\android-studio
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    
    [✓] VS Code (version 1.51.1)
        • VS Code at C:\Users\taha\AppData\Local\Programs\Microsoft VS Code
        • Flutter extension version 3.16.0
    
    [✓] Connected device (4 available)
        • Android SDK built for x86 (mobile) • emulator-5554 • android-x86    • Android 8.0.0 (API 26) (emulator)
        • Web Server (web)                   • web-server    • web-javascript • Flutter Tools
        • Chrome (web)                       • chrome        • web-javascript • Google Chrome 86.0.4240.198
        • Edge (web)                         • edge          • web-javascript • Microsoft Edge 86.0.622.63
    
    • No issues found!
  2. added
    in triagePresently being triaged by the triage team
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Nov 13, 2020
  3. treeder commented on Nov 13, 2020

    @treeder
    Author

    Main reason is to emulate an app being used in China which can't access any Google domains.

  4. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Nov 13, 2020
  5. added
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    platform-webWeb applications specifically
    and removed
    in triagePresently being triaged by the triage team
    on Nov 13, 2020
  6. ditman commented on Dec 12, 2020

    @ditman
    Member

    I've reproduced this happening. We need to ensure that the underyling google sign in JS SDK has loaded.

    We might be able to attach to the onerror event of its script tag, and see if the browser reports the error to know that the plugin hasn't been downloaded properly, another thing we can do (less optimal) is to allocate some timer on the JS callback of the script.

    The second option is less efficient, but might end up being required anyway, especially depending on how the browser reacts to the actual blocking; and/or how the firewall is actually blocking the domain.

    (I'll add this to the "Flutter Web Plugins" project, I can't work immediately on this.)

  7. 9 remaining items

  8. github-actions commented on Jul 8, 2025

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  9. locked as resolved and limited conversation to collaborators on Jul 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

P2Important issues not at the top of the work listfound in release: 3.3Found to occur in 3.3found in release: 3.7Found to occur in 3.7has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: google_sign_inThe Google Sign-In pluginpackageflutter/packages repository. See also p: labels.platform-webWeb applications specificallyteam-webOwned by Web platform teamtriaged-webTriaged by Web platform team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions