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

Add an option to enable third party cookies in the webView #727

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ Otherwise you'll still not be able to display content from pages with untrusted

You can test your ignorance if ssl certificates is working e.g. through https://self-signed.badssl.com/


### Enabling third party cookies
Set the `thirdPartyCookiesEnabled` option to true in the launch function or in the Webview scaffold to enable third party cookies in the WebView. This option is ignored on iOS.


### Webview Events
Expand Down Expand Up @@ -239,6 +240,7 @@ Future<Null> launch(String url, {
bool geolocationEnabled: false,
bool debuggingEnabled: false,
bool ignoreSSLErrors: false,
bool thirdPartyCookiesEnabled: false,
});
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ void openUrl(MethodCall call, MethodChannel.Result result) {
boolean geolocationEnabled = call.argument("geolocationEnabled");
boolean debuggingEnabled = call.argument("debuggingEnabled");
boolean ignoreSSLErrors = call.argument("ignoreSSLErrors");
boolean thirdPartyCookiesEnabled = call.argument("thirdPartyCookiesEnabled");

if (webViewManager == null || webViewManager.closed == true) {
Map<String, Object> arguments = (Map<String, Object>) call.arguments;
Expand Down Expand Up @@ -162,7 +163,8 @@ void openUrl(MethodCall call, MethodChannel.Result result) {
invalidUrlRegex,
geolocationEnabled,
debuggingEnabled,
ignoreSSLErrors
ignoreSSLErrors,
thirdPartyCookiesEnabled
);
result.success(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,8 @@ void openUrl(
String invalidUrlRegex,
boolean geolocationEnabled,
boolean debuggingEnabled,
boolean ignoreSSLErrors
boolean ignoreSSLErrors,
boolean thirdPartyCookiesEnabled
) {
webView.getSettings().setJavaScriptEnabled(withJavascript);
webView.getSettings().setBuiltInZoomControls(withZoom);
Expand Down Expand Up @@ -445,6 +446,10 @@ void openUrl(
} else {
webView.loadUrl(url);
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
CookieManager.getInstance().setAcceptThirdPartyCookies(webView, thirdPartyCookiesEnabled);
}
}

void reloadUrl(String url) {
Expand Down
3 changes: 3 additions & 0 deletions lib/src/base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class FlutterWebviewPlugin {
/// - [withOverviewMode]: enable overview mode for Android webview ( setLoadWithOverviewMode )
/// - [useWideViewPort]: use wide viewport for Android webview ( setUseWideViewPort )
/// - [ignoreSSLErrors]: use to bypass Android/iOS SSL checks e.g. for self-signed certificates
/// - [thirdPartyCookiesEnabled]: use to enable third party cookies in the WebView
Future<Null> launch(
String url, {
Map<String, String> headers,
Expand Down Expand Up @@ -168,6 +169,7 @@ class FlutterWebviewPlugin {
bool geolocationEnabled,
bool debuggingEnabled,
bool ignoreSSLErrors,
bool thirdPartyCookiesEnabled,
}) async {
final args = <String, dynamic>{
'url': url,
Expand All @@ -193,6 +195,7 @@ class FlutterWebviewPlugin {
'withOverviewMode': withOverviewMode ?? false,
'debuggingEnabled': debuggingEnabled ?? false,
'ignoreSSLErrors': ignoreSSLErrors ?? false,
'thirdPartyCookiesEnabled': thirdPartyCookiesEnabled ?? false,
};

if (headers != null) {
Expand Down
3 changes: 3 additions & 0 deletions lib/src/webview_scaffold.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class WebviewScaffold extends StatefulWidget {
this.geolocationEnabled,
this.debuggingEnabled = false,
this.ignoreSSLErrors = false,
this.thirdPartyCookiesEnabled = false,
}) : super(key: key);

final PreferredSizeWidget appBar;
Expand Down Expand Up @@ -74,6 +75,7 @@ class WebviewScaffold extends StatefulWidget {
final bool useWideViewPort;
final bool debuggingEnabled;
final bool ignoreSSLErrors;
final bool thirdPartyCookiesEnabled;

@override
_WebviewScaffoldState createState() => _WebviewScaffoldState();
Expand Down Expand Up @@ -180,6 +182,7 @@ class _WebviewScaffoldState extends State<WebviewScaffold> {
geolocationEnabled: widget.geolocationEnabled,
debuggingEnabled: widget.debuggingEnabled,
ignoreSSLErrors: widget.ignoreSSLErrors,
thirdPartyCookiesEnabled: widget.thirdPartyCookiesEnabled,
);
} else {
if (_rect != value) {
Expand Down