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

Can I set cookie from outside? #112

Open
jaggerwang opened this issue Jul 1, 2018 · 4 comments
Open

Can I set cookie from outside? #112

jaggerwang opened this issue Jul 1, 2018 · 4 comments

Comments

@jaggerwang
Copy link

jaggerwang commented Jul 1, 2018

Problem

I see there is a getCookies method, but I want to set cookie to webview, so webview and app can share the same session.

I tried the following method, but not working.

                final cookieJar = await vm.config.cookieJar;
                final webview = FlutterWebviewPlugin();
                for (var item in cookieJar.domains) {
                  for (var domainCookies in item.values) {
                    for (var pathCookies in domainCookies.values) {
                      for (var cookie in pathCookies.values) {
                        cookie.cookie.httpOnly = false;
                        print('document.cookie = "${cookie.cookie}";');
                        await webview.evalJavascript(
                            'document.cookie = "${cookie.cookie}";');
                      }
                    }
                  }
                }

I tried the JavaScript code in Chrome, it did work.

Env

name: tangbole
description: A tumblr client app.

dependencies:
  cookie_jar: ^0.0.4
  cupertino_icons: ^0.1.2
  english_words: ^3.1.0
  dio: ^0.0.14
  flutter:
    sdk: flutter
  flutter_redux: ^0.5.1
  flutter_webview_plugin: ^0.1.6
  logging: ^0.11.3+1
  meta: ^1.1.5
  path_provider: ^0.4.1
  uri: ^0.11.2
  redux: ^3.0.0
  redux_logging: ^0.3.0
  redux_persist: ^0.7.0-rc.2
  redux_persist_flutter: ^0.6.0-rc.1
  validate: ^1.6.0

dev_dependencies:
  flutter_driver:
    sdk: flutter
  flutter_test:
    sdk: flutter
  mockito: ^2.2.3

flutter:
  uses-material-design: true
  assets:
    - images/lake.jpg
@jaggerwang
Copy link
Author

And when I call getCookies, I got the following error.

print(FlutterWebviewPlugin().getCookies());
Runner: flutter: Instance of 'Future<Map<String, dynamic>>'
Runner: [VERBOSE-2:dart_error.cc(16)] Unhandled exception:
type '_InternalLinkedHashMap<dynamic, dynamic>' is not a subtype of type 'FutureOr<Map<String, dynamic>>'
#0      FlutterWebviewPlugin.getCookies (package:flutter_webview_plugin/src/base.dart:155:12)
<asynchronous suspension>
#1      _TumblrLoginScreenState.initCookie (file:///Users/jagger/projects/tangbole/app/lib/components/account/tumblr_login.dart:37:42)
<asynchronous suspension>
#2      _TumblrLoginScreenState.initState (file:///Users/jagger/projects/tangbole/app/lib/components/account/tumblr_login.dart:24:5)
#3      StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3751:58)
#4      ComponentElement.mount (package:flutter/src/widgets/framework.dart:3617:5)
#5      Element.inflateWidget (package:flutter/src/widgets/framework.dart:2907:14)
#6      Element.updateChild (package:flutter/src/widgets/framework.dart:2710:12)
#7      SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4654:14)
#8      El<…>

@jaggerwang
Copy link
Author

And It can't load local url http://localhost:8080/account/info with withLocalUrl: true, the local url can be open in safari in iOS simulator. But it can load none local url https://tangbole.app/api/account/info. Does it because I'm not using https in local url?

@jaggerwang
Copy link
Author

Anyone here?

@yufei-wu
Copy link

yufei-wu commented Jul 5, 2018

You should use 127.0.0.1 not localhost for local url

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants