-
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 all commits
85e36de
767e4a5
b58764b
bd3b12f
4133b20
58ecb77
9dde6ef
91f96b3
b5785c7
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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit, the link doesn't seem to be complete (although the website does seem to redirect you to the correct page). Also I doubt this will be rendered as a link in markdown (so people would have to copy and paste this into their browser's URL bar in order to open it).
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 96e2b0a. |
||
| 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.