-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[webview_flutter_wkwebview] Add support for javaScriptCanOpenWindowsAutomatically #10608
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
base: main
Are you sure you want to change the base?
Changes from 10 commits
85e36de
767e4a5
b58764b
bd3b12f
4133b20
58ecb77
9dde6ef
91f96b3
b5785c7
a700da7
ec04126
cf4f2c9
0d1533c
f630604
7df6f3e
130f1c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -82,6 +82,7 @@ class WebKitWebViewControllerCreationParams | |
| }, | ||
| this.allowsInlineMediaPlayback = false, | ||
| this.limitsNavigationsToAppBoundDomains = false, | ||
| this.javaScriptCanOpenWindowsAutomatically, | ||
| }) { | ||
| _configuration = WKWebViewConfiguration(); | ||
|
|
||
|
|
@@ -122,10 +123,13 @@ class WebKitWebViewControllerCreationParams | |
| }, | ||
| bool allowsInlineMediaPlayback = false, | ||
| bool limitsNavigationsToAppBoundDomains = false, | ||
| bool? javaScriptCanOpenWindowsAutomatically, | ||
| }) : this( | ||
| mediaTypesRequiringUserAction: mediaTypesRequiringUserAction, | ||
| allowsInlineMediaPlayback: allowsInlineMediaPlayback, | ||
| limitsNavigationsToAppBoundDomains: limitsNavigationsToAppBoundDomains, | ||
| javaScriptCanOpenWindowsAutomatically: | ||
| javaScriptCanOpenWindowsAutomatically, | ||
| ); | ||
|
|
||
| late final WKWebViewConfiguration _configuration; | ||
|
|
@@ -147,6 +151,18 @@ class WebKitWebViewControllerCreationParams | |
| /// (Only available for iOS > 14.0) | ||
| /// Defaults to false. | ||
| final bool limitsNavigationsToAppBoundDomains; | ||
|
|
||
| /// Whether JavaScript can open windows without user interaction. | ||
| /// | ||
| /// Setting this to `true` allows JavaScript's `window.open()` to create | ||
| /// new windows automatically without requiring a user gesture. | ||
| /// | ||
| /// When `null`, the platform's native default is used: | ||
| /// - iOS: `false` | ||
| /// - macOS: `true` | ||
| /// | ||
| /// See https://developer.apple.com/documentation/webkit/wkpreferences/1536573-javascriptcanopenwindowsautomati | ||
|
||
| final bool? javaScriptCanOpenWindowsAutomatically; | ||
| } | ||
|
|
||
| /// An implementation of [PlatformWebViewController] with the WebKit api. | ||
|
|
@@ -643,6 +659,16 @@ class WebKitWebViewController extends PlatformWebViewController { | |
| case JavaScriptMode.unrestricted: | ||
| await webpagePreferences.setAllowsContentJavaScript(true); | ||
| } | ||
| // Set javaScriptCanOpenWindowsAutomatically on WKPreferences only if explicitly set | ||
| final bool? javaScriptCanOpenWindowsAutomatically = | ||
|
||
| _webKitParams.javaScriptCanOpenWindowsAutomatically; | ||
| if (javaScriptCanOpenWindowsAutomatically != null) { | ||
| final WKPreferences preferences = await _webView.configuration | ||
| .getPreferences(); | ||
| await preferences.setJavaScriptCanOpenWindowsAutomatically( | ||
| javaScriptCanOpenWindowsAutomatically, | ||
| ); | ||
| } | ||
| return; | ||
| } on PlatformException catch (exception) { | ||
| if (exception.code != 'PigeonUnsupportedOperationError') { | ||
|
|
@@ -660,6 +686,13 @@ class WebKitWebViewController extends PlatformWebViewController { | |
| case JavaScriptMode.unrestricted: | ||
| await preferences.setJavaScriptEnabled(true); | ||
| } | ||
| final bool? javaScriptCanOpenWindowsAutomatically = | ||
| _webKitParams.javaScriptCanOpenWindowsAutomatically; | ||
| if (javaScriptCanOpenWindowsAutomatically != null) { | ||
| await preferences.setJavaScriptCanOpenWindowsAutomatically( | ||
| javaScriptCanOpenWindowsAutomatically, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| @override | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uber nit: maybe
WebKitWebViewControllerCreationParams.javaScriptCanOpenWindowsAutomaticallyso the reader doesn't have to look for the exact name space.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@LongCatIsLooong
Thanks for your view.
Fixed in bcd1d03.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry for the confusion but above commit is outdated.
I fixed it again in 7df6f3e