Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cookies dont persist #374

Closed
owenkealey opened this issue Jun 3, 2020 · 13 comments
Closed

Cookies dont persist #374

owenkealey opened this issue Jun 3, 2020 · 13 comments

Comments

@owenkealey
Copy link

Environment

Flutter version: 1.17
Plugin version: 3.3.0+3
Android version:
iOS version:
Xcode version: 11.5
Device information:

Description

Expected behavior:
Cookies to persist on app restart.

Current behavior:
Cookies don't persist.

I sign into GMail on an in app browser and I get logged in and stay logged in, but when I restart the app I am not signed into gmail on the browser. Why?

@pichillilorenzo
Copy link
Owner

pichillilorenzo commented Jun 3, 2020

I can't reproduce this behavior on iOS Simulator.
I'm using InAppBrowser, I open https://github.com/ and I log-in with my GitHub account.
If I close my InAppBrowser instance and re-open it, I'm already signed.
If I close the whole app and restart it, I'm also already signed.

If you are using incognito: true option, then it won't persist cookies.

Could you share your code/use case?

@owenkealey
Copy link
Author

owenkealey commented Jun 3, 2020

sure

import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:swift_splash/frontend/styles/text.dart';


/// The google login screen
class GoogleLogin extends StatelessWidget{

  @override 
  Widget build(final BuildContext context){
    return GoogleForm();
  }
}

/// google login screen
class GoogleForm extends StatefulWidget{

  @override
  GoogleFormState createState() => GoogleFormState();
}


class GoogleFormState extends State<GoogleForm>{

  /// Builds the google login screen
  @override 
  Widget build(final BuildContext context){
    return Scaffold(
      backgroundColor: Theme.of(context).scaffoldBackgroundColor,
      appBar: AppBar(
        backgroundColor: Theme.of(context).cardColor,
        iconTheme: IconThemeData(
          color: Colors.blue
        ),
        title: Text("Google Login", style: TextStyles(context).navBar),
        centerTitle: true,
      ),
      body: Center(
        child: Column(
          children: <Widget>[
            Expanded(
              child: InAppWebView(
                initialUrl: "https://accounts.google.com/AccountChooser?service=mail&continue=https://mail.google.com/mail/",
                onLoadStop: (controller,url){
                  print(url);
                },
                key: UniqueKey(),
                initialOptions: InAppWebViewGroupOptions(
                  crossPlatform: InAppWebViewOptions(
                    javaScriptEnabled: true,
                    userAgent: "Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1",
                    javaScriptCanOpenWindowsAutomatically: true,
                  ),
                ),
              )
            )
          ],
        )
      )
    );
  }
}```

@owenkealey
Copy link
Author

I also have other inappwebviews in the widget tree that have incognito:true switched on, could that be the reason?

@owenkealey
Copy link
Author

Also zoomBy doesnt seem to work at all, my webview looks the same no matter how much or little i zoom it.

@owenkealey
Copy link
Author

I have confirmed the cookie problem only happens when I have multiple other webviews in the app @pichillilorenzo

@owenkealey
Copy link
Author

Which are instantiated before the google login one.

@pichillilorenzo
Copy link
Owner

I cannot reproduce your problem. On iOS Simulator, it is working fine!
I have 2 WebViews:

  • one without incognito: true, so it will remember me
  • one with incognito: true, so it won't save/persist my session

Here is my full code example:

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';

Future main() async {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
  InAppWebViewController _webViewController;

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('InAppWebView Example'),
        ),
        body: Container(
            child: Column(children: <Widget>[
              Expanded(
                  child: InAppWebView(
                    initialUrl: "https://accounts.google.com/AccountChooser?service=mail&continue=https://mail.google.com/mail/",
                    initialHeaders: {},
                    initialOptions: InAppWebViewGroupOptions(
                      crossPlatform: InAppWebViewOptions(
                        debuggingEnabled: true,
                        userAgent: "Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1",
                        javaScriptCanOpenWindowsAutomatically: true,
                      ),
                    ),
                    onWebViewCreated: (InAppWebViewController controller) {
                      _webViewController = controller;
                    },
                    onLoadStart: (InAppWebViewController controller, String url) {

                    },
                    onLoadStop: (InAppWebViewController controller, String url) async {

                    },
                  )),
              Expanded(
                  child: InAppWebView(
                    initialUrl: "https://accounts.google.com/AccountChooser?service=mail&continue=https://mail.google.com/mail/",
                    initialHeaders: {},
                    initialOptions: InAppWebViewGroupOptions(
                      crossPlatform: InAppWebViewOptions(
                        debuggingEnabled: true,
                        userAgent: "Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1",
                        javaScriptCanOpenWindowsAutomatically: true,
                        incognito: true
                      ),
                    ),
                    onWebViewCreated: (InAppWebViewController controller) {
                      _webViewController = controller;
                    },
                    onLoadStart: (InAppWebViewController controller, String url) {

                    },
                    onLoadStop: (InAppWebViewController controller, String url) async {

                    },
                  ))
            ])),
      ),
    );
  }
}

Screenshot:

Simulator Screen Shot - iPhone SE (2nd generation) - 2020-06-04 at 14 03 10

As you can see, in the first WebView, it remembers my account [email protected].
Instead, in the second one, it restarts every time from login page.

If I close the whole App and restart it, I see it as the screenshot every time.

@owenkealey
Copy link
Author

Ah well then I have no idea what is causing it in my code, thanks anyway

@scottk
Copy link

scottk commented Sep 11, 2020

I am also having this problem, it seems inconsistent. If I log into a google account, close the web view (not even the app) and reopen a webview I am no longer logged in. Incognito is set to false, and it just opens a browser and goes to mail.google.com so I'm not sure what I could be doing wrong here

@pichillilorenzo
Copy link
Owner

@scottk could you share the code you are using, please? Otherwise I cannot reproduce your error

@scottk
Copy link

scottk commented Sep 11, 2020

Hi no problem. It is now only happening on iOS, Android seems fine.

return InAppWebViewOptions( incognito: false, cacheEnabled: true, transparentBackground: true, disableHorizontalScroll: true, disableVerticalScroll: true);

These are my common options

return InAppWebViewGroupOptions( crossPlatform: buildCrossPlatformOptions(), android: AndroidInAppWebViewOptions(thirdPartyCookiesEnabled: true), ios: IOSInAppWebViewOptions(sharedCookiesEnabled: true) );

this is for the specific devices. I tried setting sharedCookies to false and true and neither changes. If the browser is destroyed (close app and reopen) the session is lost, not sure what else to try

@HajerWael
Copy link

How u solve this please ? I have the same issue specially with cookies isSessiononly= true ,\ seems working fine on IOS simulator but not in real iphone device ?

Copy link

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 and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants