[webview_flutter_wkwebview] Add support for javaScriptCanOpenWindowsAutomatically#10608
[webview_flutter_wkwebview] Add support for javaScriptCanOpenWindowsAutomatically#10608fummicc1 wants to merge 16 commits intoflutter:mainfrom
Conversation
…utomatically Adds support for WKPreferences.javaScriptCanOpenWindowsAutomatically to allow JavaScript's window.open() to work without user interaction on iOS and macOS. Fixes flutter/flutter#112276
There was a problem hiding this comment.
Code Review
This pull request adds support for javaScriptCanOpenWindowsAutomatically to allow JavaScript's window.open() to work without user interaction on iOS and macOS. The changes are well-implemented across Dart and Swift files, including the necessary Pigeon interface updates, native implementation, and tests. I have a couple of suggestions to improve the code. One is to refactor the setJavaScriptMode method in webkit_webview_controller.dart to reduce code duplication, which will enhance maintainability. The other is a minor improvement in the new Swift test to ensure better error reporting.
packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/PreferencesProxyAPITests.swift
Outdated
Show resolved
Hide resolved
…ntation for setJavaScriptCanOpenWindowsAutomatically to accurately reflect that the default value is `false` on iOS and `true` on macOS, matching Apple's official documentation.
LongCatIsLooong
left a comment
There was a problem hiding this comment.
LGTM with nits. Thank you for the contribution!
| /// - iOS: `false` | ||
| /// - macOS: `true` | ||
| /// | ||
| /// See https://developer.apple.com/documentation/webkit/wkpreferences/1536573-javascriptcanopenwindowsautomati |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
I reviewed doc comment again and refined in f630604.
| @@ -1,3 +1,8 @@ | |||
| ## 3.24.0 | |||
|
|
|||
| * Adds support for `javaScriptCanOpenWindowsAutomatically` to allow JavaScript's | |||
There was a problem hiding this comment.
uber nit: maybe
WebKitWebViewControllerCreationParams.javaScriptCanOpenWindowsAutomatically so the reader doesn't have to look for the exact name space.
There was a problem hiding this comment.
There was a problem hiding this comment.
I'm sorry for the confusion but above commit is outdated.
I fixed it again in 7df6f3e
|
Could you re-format the dart code? See https://github.com/flutter/packages/blob/main/script/tool/README.md#format-code |
|
Thank you for your advice! I applied formatter by the following code: |
bparrishMines
left a comment
There was a problem hiding this comment.
Thanks for the contribution! Added a small nit for the implementation.
| await webpagePreferences.setAllowsContentJavaScript(true); | ||
| } | ||
| // Set javaScriptCanOpenWindowsAutomatically on WKPreferences only if explicitly set | ||
| final bool? javaScriptCanOpenWindowsAutomatically = |
There was a problem hiding this comment.
nit:
You should be able to move this code above the try block as to not have duplicate code.
…matically Resolve merge conflicts in webview_flutter_wkwebview CHANGELOG.md and pubspec.yaml, keeping both the 3.24.0 feature entry and the 3.23.6 bugfix entry.
…c in setJavaScriptMode Move the javaScriptCanOpenWindowsAutomatically setting above the try block to eliminate duplication between the iOS 14+ path and the fallback path. The WKPreferences setting is independent of iOS version. Addresses PR flutter#10608 review feedback (bparrishMines)
Remove duplicated behavioral descriptions and Apple URL from the public API doc, keeping pigeon as the single source of truth. This aligns the documentation style with peer parameters in WebKitWebViewControllerCreationParams.
…HANGELOG.md` review comment: flutter#10608 (comment)
…or-javaScriptCanOpenWindowsAutomatically
This PR adds support for
WKPreferences.javaScriptCanOpenWindowsAutomaticallyto allow JavaScript'swindow.open()to work without user interaction on iOS and macOS.Changes
javaScriptCanOpenWindowsAutomaticallyparameter toWebKitWebViewControllerCreationParamssetJavaScriptCanOpenWindowsAutomaticallymethod via Pigeon APIsetJavaScriptModeis calledUsage
Proof
I checked this behavior with a demo in this PR
The screen capture below shows that 5 seconds after pressing the button, the WebView shows the destination only if javaScriptCanOpenWindowsAutomatically is true.
Screen.Recording.2025-12-16.at.3.40.48.mp4