Skip to content
New issue

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

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

Already on GitHub? # to your account

Cant get cookie IOS #221

Closed
vawaysinhthanh opened this issue Dec 12, 2019 · 3 comments
Closed

Cant get cookie IOS #221

vawaysinhthanh opened this issue Dec 12, 2019 · 3 comments
Labels

Comments

@vawaysinhthanh
Copy link

vawaysinhthanh commented Dec 12, 2019

Environment

Flutter version: 1.9.6
Plugin version:
Android version:
iOS version: 11.1
Xcode version:
Device information:

Description

InAppWebView(
initialUrl: _webviewUrl,
initialOptions: InAppWebViewWidgetOptions(
iosInAppWebViewOptions: IosInAppWebViewOptions(
sharedCookiesEnabled: true,
),
inAppWebViewOptions: InAppWebViewOptions(
debuggingEnabled: true,
)),
onWebViewCreated: (InAppWebViewController controller) {
_webView = controller;
},
onLoadStart: (InAppWebViewController controller, String url) {
getCookies();
setState(() {
_webviewUrl = url;
});
webViewURLChange();
},
onLoadError: (InAppWebViewController controller, String url,
int code, String message) {
Navigator.of(context).pop(null);
},
onLoadStop: (InAppWebViewController controller, String url) {
getCookies();
},
onProgressChanged:
(InAppWebViewController controller, int progress) {
setState(() {
_progress = progress / 100;
});

            //if (_progress == 1.0) {
            webviewUpdate();
            //}
          },
        ),
        (_isShow == false
            ? Positioned.fill(
                child: Container(
                  color: Colors.white,
                  alignment: Alignment.center,
                  child: Func.loading(),
                ),
              )
            : Container()),
      ]

void getCookies() async {
var cookies = await CookieManager.instance().getCookie(url : 'https://facebook.com/', name: 'c_user');
print(cookies);
//checkLogin();

}

but not print cookie
Expected behavior:

Current behavior:

Steps to reproduce

  1. This
  2. Than that
  3. Then

Images

Stacktrace/Logcat

@wwwdata
Copy link
Contributor

wwwdata commented Jan 17, 2020

I also have this error and I could trace down the problem. It seems that when the cookies are read out, the code always tries to compare the URL with the cookie domain. But unfortunately, the domain field is optional. So it will be nil sometimes and that makes the code crash.

The affected lines of code are here:
Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value

if cookie.domain.contains(URL(string: url)!.host!) {
cookieList.append([
"name": cookie.name,
"value": cookie.value
])

Edit: actually upon debugging, I found out this was my mistake. The URL I tried it with was about:blank that obviously could not be parsed so the force unwrap then crashed. I guess the force unwrap should still be removed and the fallback should be to not return a cookie here. Crashing the whole app is bad.

This was referenced Jul 6, 2020
Copy link

github-actions bot commented Oct 7, 2024

This issue is stale and has been automatically closed because it has been open for more than 365 days with no activity. Please reopen a new issue if you still have it.

@github-actions github-actions bot added the stale label Oct 7, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 7, 2024
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 22, 2024
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants