Skip to content

Conversation

@fummicc1
Copy link

@fummicc1 fummicc1 commented Dec 11, 2025

This PR adds support for WKPreferences.javaScriptCanOpenWindowsAutomatically to allow JavaScript's window.open() to work without user interaction on iOS and macOS.

Changes

  • Added javaScriptCanOpenWindowsAutomatically parameter to WebKitWebViewControllerCreationParams
  • Exposed setJavaScriptCanOpenWindowsAutomatically method via Pigeon API
  • The setting is applied when setJavaScriptMode is called

Usage

final controller = WebKitWebViewController(
  WebKitWebViewControllerCreationParams(
    javaScriptCanOpenWindowsAutomatically: true,
  ),
)
  ..setJavaScriptMode(JavaScriptMode.unrestricted)
  ..loadRequest(Uri.parse('https://example.com'));

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

…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
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@fummicc1 fummicc1 marked this pull request as ready for review December 15, 2025 20:00
Copy link
Contributor

@LongCatIsLooong LongCatIsLooong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with nits. Thank you for the contribution!

/// - iOS: `false`
/// - macOS: `true`
///
/// See https://developer.apple.com/documentation/webkit/wkpreferences/1536573-javascriptcanopenwindowsautomati
Copy link
Contributor

@LongCatIsLooong LongCatIsLooong Dec 30, 2025

Choose a reason for hiding this comment

The 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).

@@ -1,3 +1,8 @@
## 3.24.0

* Adds support for `javaScriptCanOpenWindowsAutomatically` to allow JavaScript's
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uber nit: maybe
WebKitWebViewControllerCreationParams.javaScriptCanOpenWindowsAutomatically so the reader doesn't have to look for the exact name space.

@LongCatIsLooong
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants