Repository: flutter
Issue: window.print has no effect in webview_flutter
Labels: p: webview,package,team-ecosystem,has reproducible steps,P3,triaged-ecosystem,found in release: 3.24,found in release: 3.27

### What package does this bug report belong to?

webview_flutter

### What target platforms are you seeing this bug on?

Android, iOS

### Have you already upgraded your packages?

Yes

### Dependency versions

<details><summary>pubspec.lock</summary>

```lock
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
  async:
    dependency: transitive
    description:
      name: async
      sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c"
      url: "https://pub.dev"
    source: hosted
    version: "2.11.0"
  boolean_selector:
    dependency: transitive
    description:
      name: boolean_selector
      sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66"
      url: "https://pub.dev"
    source: hosted
    version: "2.1.1"
  characters:
    dependency: transitive
    description:
      name: characters
      sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605"
      url: "https://pub.dev"
    source: hosted
    version: "1.3.0"
  clock:
    dependency: transitive
    description:
      name: clock
      sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf
      url: "https://pub.dev"
    source: hosted
    version: "1.1.1"
  collection:
    dependency: transitive
    description:
      name: collection
      sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
      url: "https://pub.dev"
    source: hosted
    version: "1.18.0"
  cupertino_icons:
    dependency: "direct main"
    description:
      name: cupertino_icons
      sha256: ba631d1c7f7bef6b729a622b7b752645a2d076dba9976925b8f25725a30e1ee6
      url: "https://pub.dev"
    source: hosted
    version: "1.0.8"
  fake_async:
    dependency: transitive
    description:
      name: fake_async
      sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78"
      url: "https://pub.dev"
    source: hosted
    version: "1.3.1"
  flutter:
    dependency: "direct main"
    description: flutter
    source: sdk
    version: "0.0.0"
  flutter_lints:
    dependency: "direct dev"
    description:
      name: flutter_lints
      sha256: "5398f14efa795ffb7a33e9b6a08798b26a180edac4ad7db3f231e40f82ce11e1"
      url: "https://pub.dev"
    source: hosted
    version: "5.0.0"
  flutter_test:
    dependency: "direct dev"
    description: flutter
    source: sdk
    version: "0.0.0"
  leak_tracker:
    dependency: transitive
    description:
      name: leak_tracker
      sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05"
      url: "https://pub.dev"
    source: hosted
    version: "10.0.5"
  leak_tracker_flutter_testing:
    dependency: transitive
    description:
      name: leak_tracker_flutter_testing
      sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806"
      url: "https://pub.dev"
    source: hosted
    version: "3.0.5"
  leak_tracker_testing:
    dependency: transitive
    description:
      name: leak_tracker_testing
      sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3"
      url: "https://pub.dev"
    source: hosted
    version: "3.0.1"
  lints:
    dependency: transitive
    description:
      name: lints
      sha256: "3315600f3fb3b135be672bf4a178c55f274bebe368325ae18462c89ac1e3b413"
      url: "https://pub.dev"
    source: hosted
    version: "5.0.0"
  matcher:
    dependency: transitive
    description:
      name: matcher
      sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb
      url: "https://pub.dev"
    source: hosted
    version: "0.12.16+1"
  material_color_utilities:
    dependency: transitive
    description:
      name: material_color_utilities
      sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
      url: "https://pub.dev"
    source: hosted
    version: "0.11.1"
  meta:
    dependency: transitive
    description:
      name: meta
      sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7
      url: "https://pub.dev"
    source: hosted
    version: "1.15.0"
  path:
    dependency: transitive
    description:
      name: path
      sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af"
      url: "https://pub.dev"
    source: hosted
    version: "1.9.0"
  plugin_platform_interface:
    dependency: transitive
    description:
      name: plugin_platform_interface
      sha256: "4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02"
      url: "https://pub.dev"
    source: hosted
    version: "2.1.8"
  sky_engine:
    dependency: transitive
    description: flutter
    source: sdk
    version: "0.0.99"
  source_span:
    dependency: transitive
    description:
      name: source_span
      sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c"
      url: "https://pub.dev"
    source: hosted
    version: "1.10.0"
  stack_trace:
    dependency: transitive
    description:
      name: stack_trace
      sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
      url: "https://pub.dev"
    source: hosted
    version: "1.11.1"
  stream_channel:
    dependency: transitive
    description:
      name: stream_channel
      sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
      url: "https://pub.dev"
    source: hosted
    version: "2.1.2"
  string_scanner:
    dependency: transitive
    description:
      name: string_scanner
      sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde"
      url: "https://pub.dev"
    source: hosted
    version: "1.2.0"
  term_glyph:
    dependency: transitive
    description:
      name: term_glyph
      sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84
      url: "https://pub.dev"
    source: hosted
    version: "1.2.1"
  test_api:
    dependency: transitive
    description:
      name: test_api
      sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb"
      url: "https://pub.dev"
    source: hosted
    version: "0.7.2"
  vector_math:
    dependency: transitive
    description:
      name: vector_math
      sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803"
      url: "https://pub.dev"
    source: hosted
    version: "2.1.4"
  vm_service:
    dependency: transitive
    description:
      name: vm_service
      sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d"
      url: "https://pub.dev"
    source: hosted
    version: "14.2.5"
  webview_flutter:
    dependency: "direct main"
    description:
      name: webview_flutter
      sha256: "889a0a678e7c793c308c68739996227c9661590605e70b1f6cf6b9a6634f7aec"
      url: "https://pub.dev"
    source: hosted
    version: "4.10.0"
  webview_flutter_android:
    dependency: "direct main"
    description:
      name: webview_flutter_android
      sha256: "285cedfd9441267f6cca8843458620b5fda1af75b04f5818d0441acda5d7df19"
      url: "https://pub.dev"
    source: hosted
    version: "4.1.0"
  webview_flutter_platform_interface:
    dependency: transitive
    description:
      name: webview_flutter_platform_interface
      sha256: d937581d6e558908d7ae3dc1989c4f87b786891ab47bb9df7de548a151779d8d
      url: "https://pub.dev"
    source: hosted
    version: "2.10.0"
  webview_flutter_wkwebview:
    dependency: "direct main"
    description:
      name: webview_flutter_wkwebview
      sha256: b7e92f129482460951d96ef9a46b49db34bd2e1621685de26e9eaafd9674e7eb
      url: "https://pub.dev"
    source: hosted
    version: "3.16.3"
sdks:
  dart: ">=3.5.3 <4.0.0"
  flutter: ">=3.24.0"
```

</details>


### Steps to reproduce

Create a webview and open a webpage that contains a javascript call to `window.print()`

A call to `console.log(window.print)` confirms that `window.print` is defined with native code as expected:
```
I/flutter (10914): Console message: function print() { [native code] }
```

Calling the `window.print()` has no effect.

### Expected results


A native print dialog should open to print the page, or there should at least be a callback that can be defined similar to the other `setOn...` methods on the `WebViewController`.

### Actual results

Nothing happens, there is also no configurable callback or any other documented way to use the print functionality.

### Code sample

<details open><summary>Code sample</summary>

```dart
// main.dart
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';

void main() {
  runApp(SafeArea(
    child: WebViewDemo(),
  ));
}

class WebViewDemo extends StatelessWidget {
  WebViewDemo({super.key});
  final WebViewController controller = WebViewController()
      ..setJavaScriptMode(JavaScriptMode.unrestricted);

  @override
  Widget build(BuildContext context) {
    controller.loadHtmlString(html);
    return WebViewWidget(controller: controller);
  }
}

const String html = """
<button onclick="window.print();">Print</button>
""";
```

</details>


### Screenshots or Videos

_No response_

### Logs

<details open><summary>Logs</summary>

```console
Launching lib/main.dart on sdk gphone64 arm64 in debug mode...
Running Gradle task 'assembleDebug'...
✓ Built build/app/outputs/flutter-apk/app-debug.apk
Debug service listening on ws://127.0.0.1:60619/nzRYAXrcRdA=/ws
Syncing files to device sdk gphone64 arm64...
W/ziparchive(10914): Unable to open '/data/app/~~Vme_rk0-AslMu3303wjosQ==/com.google.android.trichromelibrary_677803933-XkffO01gI6R9ejGrXcUYvA==/base.dm': No such file or directory
W/ziparchive(10914): Unable to open '/data/app/~~Vme_rk0-AslMu3303wjosQ==/com.google.android.trichromelibrary_677803933-XkffO01gI6R9ejGrXcUYvA==/base.dm': No such file or directory
W/e.webview_print(10914): Entry not found
D/nativeloader(10914): Configuring clns-7 for other apk /data/app/~~Vme_rk0-AslMu3303wjosQ==/com.google.android.trichromelibrary_677803933-XkffO01gI6R9ejGrXcUYvA==/base.apk. target_sdk_version=34, uses_libraries=ALL, library_path=/data/app/~~8gwkLz-FZPyeh0xFCaWjgQ==/com.google.android.webview-tPjHsVuT-xUfucET8eEAng==/lib/arm64:/data/app/~~8gwkLz-FZPyeh0xFCaWjgQ==/com.google.android.webview-tPjHsVuT-xUfucET8eEAng==/base.apk!/lib/arm64-v8a:/data/app/~~Vme_rk0-AslMu3303wjosQ==/com.google.android.trichromelibrary_677803933-XkffO01gI6R9ejGrXcUYvA==/base.apk!/lib/arm64-v8a, permitted_path=/data:/mnt/expand
D/ApplicationLoaders(10914): Returning zygote-cached class loader: /system_ext/framework/androidx.window.extensions.jar
D/nativeloader(10914): Configuring clns-8 for other apk /data/app/~~8gwkLz-FZPyeh0xFCaWjgQ==/com.google.android.webview-tPjHsVuT-xUfucET8eEAng==/base.apk. target_sdk_version=34, uses_libraries=, library_path=/data/app/~~8gwkLz-FZPyeh0xFCaWjgQ==/com.google.android.webview-tPjHsVuT-xUfucET8eEAng==/lib/arm64:/data/app/~~8gwkLz-FZPyeh0xFCaWjgQ==/com.google.android.webview-tPjHsVuT-xUfucET8eEAng==/base.apk!/lib/arm64-v8a:/data/app/~~Vme_rk0-AslMu3303wjosQ==/com.google.android.trichromelibrary_677803933-XkffO01gI6R9ejGrXcUYvA==/base.apk!/lib/arm64-v8a, permitted_path=/data:/mnt/expand
I/WebViewFactory(10914): Loading com.google.android.webview version 131.0.6778.39 (code 677803933)
I/cr_WVCFactoryProvider(10914): version=131.0.6778.39 (677803933) minSdkVersion=29 isBundle=true multiprocess=true packageId=2
E/chromium(10914): [1126/091900.622208:ERROR:variations_seed_loader.cc(39)] Seed missing signature.
I/chromium(10914): [1126/091900.623419:INFO:variations_seed_loader.cc(68)] Failed to open file for reading.: No such file or directory (2)
I/cr_LibraryLoader(10914): Successfully loaded native library
I/cr_CachingUmaRecorder(10914): Flushed 6 samples from 6 histograms, 0 samples were dropped.
I/cr_CombinedPProvider(10914): #registerProvider() provider:WV.y8@cb1aef0 isPolicyCacheEnabled:false policyProvidersSize:0
I/cr_PolicyProvider(10914): #setManagerAndSource() 0
I/cr_CombinedPProvider(10914): #linkNativeInternal() 1
D/CompatibilityChangeReporter(10914): Compat change id reported: 183155436; UID 10198; state: ENABLED
I/cr_AppResProvider(10914): #getApplicationRestrictionsFromUserManager() Bundle[EMPTY_PARCEL]
I/cr_PolicyProvider(10914): #notifySettingsAvailable() 0
I/cr_CombinedPProvider(10914): #onSettingsAvailable() 0
I/cr_CombinedPProvider(10914): #flushPolicies()
W/chromium(10914): [WARNING:dns_config_service_android.cc(81)] Failed to read DnsConfig.
D/CompatibilityChangeReporter(10914): Compat change id reported: 214741472; UID 10198; state: ENABLED
D/CompatibilityChangeReporter(10914): Compat change id reported: 171228096; UID 10198; state: ENABLED
W/cr_media(10914): BLUETOOTH_CONNECT permission is missing.
W/cr_media(10914): getBluetoothAdapter() requires BLUETOOTH permission
W/cr_media(10914): registerBluetoothIntentsIfNeeded: Requires BLUETOOTH permission
I/PlatformViewsController(10914): Hosting view in view hierarchy for platform view: 0
I/PlatformViewsController(10914): PlatformView is using SurfaceProducer backend
D/CompatibilityChangeReporter(10914): Compat change id reported: 236825255; UID 10198; state: ENABLED
E/FrameEvents(10914): updateAcquireFence: Did not find frame.
D/CompatibilityChangeReporter(10914): Compat change id reported: 193247900; UID 10198; state: ENABLED
W/chromium(10914): [WARNING:viz_main_impl.cc(85)] VizNullHypothesis is disabled (not a warning)
E/FrameEvents(10914): updateAcquireFence: Did not find frame.
E/FrameEvents(10914): updateAcquireFence: Did not find frame.
D/EGL_emulation(10914): app_time_stats: avg=355.47ms min=49.46ms max=882.58ms count=3
E/FrameEvents(10914): updateAcquireFence: Did not find frame.
E/FrameEvents(10914): updateAcquireFence: Did not find frame.
D/EGL_emulation(10914): app_time_stats: avg=378.97ms min=171.96ms max=508.60ms count=4
E/FrameEvents(10914): updateAcquireFence: Did not find frame.
E/FrameEvents(10914): updateAcquireFence: Did not find frame.
E/FrameEvents(10914): updateAcquireFence: Did not find frame.
E/FrameEvents(10914): updateAcquireFence: Did not find frame.
E/FrameEvents(10914): updateAcquireFence: Did not find frame.
E/FrameEvents(10914): updateAcquireFence: Did not find frame.
E/FrameEvents(10914): updateAcquireFence: Did not find frame.
D/EGL_emulation(10914): app_time_stats: avg=145.45ms min=11.97ms max=460.91ms count=10
D/EGL_emulation(10914): app_time_stats: avg=111.88ms min=2.87ms max=463.58ms count=9
D/ProfileInstaller(10914): Installing profile for com.example.webview_print
D/CompatibilityChangeReporter(10914): Compat change id reported: 289878283; UID 10198; state: ENABLED
E/FrameEvents(10914): updateAcquireFence: Did not find frame.
D/EGL_emulation(10914): app_time_stats: avg=11490.51ms min=11490.51ms max=11490.51ms count=1
D/EGL_emulation(10914): app_time_stats: avg=1485.16ms min=22.76ms max=11471.93ms count=8
E/FrameEvents(10914): updateAcquireFence: Did not find frame.
D/EGL_emulation(10914): app_time_stats: avg=11484.67ms min=11484.67ms max=11484.67ms count=1
I/flutter (10914): Console message: function print() { [native code] }
E/FrameEvents(10914): updateAcquireFence: Did not find frame.
I/e.webview_print(10914): NativeAlloc concurrent copying GC freed 46037(2715KB) AllocSpace objects, 4(80KB) LOS objects, 49% free, 3312KB/6625KB, paused 281us,14us total 187.689ms
E/FrameEvents(10914): updateAcquireFence: Did not find frame.
E/FrameEvents(10914): updateAcquireFence: Did not find frame.
D/EGL_emulation(10914): app_time_stats: avg=1550.96ms min=18.14ms max=5938.52ms count=4
D/EGL_emulation(10914): app_time_stats: avg=1542.25ms min=15.84ms max=5937.07ms count=4
D/EGL_emulation(10914): app_time_stats: avg=1231.06ms min=25.68ms max=5922.11ms count=5
E/FrameEvents(10914): updateAcquireFence: Did not find frame.
E/FrameEvents(10914): updateAcquireFence: Did not find frame.
```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
flutter doctor -v
[✓] Flutter (Channel stable, 3.24.3, on macOS 15.1.1 24B91 darwin-arm64, locale en-US)
    • Flutter version 3.24.3 on channel stable at /Users/xxx/Tools/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 2663184aa7 (3 months ago), 2024-09-11 16:27:48 -0500
    • Engine revision 36335019a8
    • Dart version 3.5.3
    • DevTools version 2.37.3

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
    • Android SDK at /Users/xxx/Library/Android/sdk
    • Platform android-35, build-tools 35.0.0
    • ANDROID_HOME = /Users/xxx/Library/Android
    • Java binary at: /Users/xxx/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 21.0.3+-79915917-b509.11)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 16.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16B40
    • CocoaPods version 1.16.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2024.2)
    • Android Studio at /Users/xxx/Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 21.0.3+-79915917-b509.11)

[✓] IntelliJ IDEA Ultimate Edition (version 2024.3)
    • IntelliJ at /Users/xxx/Applications/IntelliJ IDEA Ultimate.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] VS Code (version 1.95.3)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (5 available)
    • sdk gphone64 arm64 (mobile)         • emulator-5554                        • android-arm64  • Android 14 (API 34) (emulator)
    • iPhone SE (3rd generation) (mobile) • F36E9547-5F62-4989-9B36-7692CA2AADEC • ios            • com.apple.CoreSimulator.SimRuntime.iOS-17-5 (simulator)
    • macOS (desktop)                     • macos                                • darwin-arm64   • macOS 15.1.1 24B91 darwin-arm64
    • Mac Designed for iPad (desktop)     • mac-designed-for-ipad                • darwin         • macOS 15.1.1 24B91 darwin-arm64
    • Chrome (web)                        • chrome                               • web-javascript • Google Chrome 131.0.6778.86
    ! Error: Browsing on the local area network for Ownership of Hana. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code -27)

[✓] Network resources
    • All expected network resources are available.

• No issues found!
```

</details>