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

1 participant