Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

feat: add permission handler API for WebView2#1654

Open
F0RLE wants to merge 7 commits intotauri-apps:devfrom
F0RLE:feat/permission-handler
Open

feat: add permission handler API for WebView2#1654
F0RLE wants to merge 7 commits intotauri-apps:devfrom
F0RLE:feat/permission-handler

Conversation

@F0RLE
Copy link

@F0RLE F0RLE commented Jan 9, 2026

Description

This PR introduces an expanded and unified Permission Handler API across all supported WebView backends (WebView2, WKWebView, WebKitGTK, and Android).

The goal is to provide developers with granular control over how hardware and web API permissions are requested by the webview, replacing auto-granting behaviors with secure defaults and providing the ability to intercept these requests dynamically.

Key Changes

  • Expanded PermissionKind Enum: Now explicitly covers 15 permission types, adding DisplayCapture, Midi, Sensors, MediaKeySystemAccess, LocalFonts, WindowManagement, PointerLock, AutomaticDownloads, FileSystemAccess, and Autoplay.
  • Unified PermissionResponse: Applications can now respond to permission requests with Allow, Deny, Default (let the system handle it natively), or Prompt (explicitly trigger a system dialog).
  • WebViewBuilder::with_permission_handler: Added a new builder method taking a closure Fn(PermissionKind) -> PermissionResponse to handle incoming permission requests.

Platform-Specific Implementations

  • 🍏 macOS / iOS (WKWebView)

    • Fully mapped WKMediaCaptureType to PermissionKind.
    • Added specific handling for combined CameraAndMicrophone requests: properly determines the final WKPermissionDecision based on the individual responses for Camera and Microphone.
    • Defaults to secure Prompt instead of automatically granting access.
  • 🪟 Windows (WebView2)

    • Exhaustively mapped all 12 COREWEBVIEW2_PERMISSION_KIND variations to the new PermissionKind API, ensuring complete coverage over Windows permissions.
    • Properly maps response states to COREWEBVIEW2_PERMISSION_STATE_ALLOW and COREWEBVIEW2_PERMISSION_STATE_DENY.
  • 🐧 Linux (WebKitGTK)

    • Intercepts the permission-request signal.
    • Added robust detection for DisplayCapture screen sharing on older WebKitGTK versions (< 2.42), bypassing the lack of is_for_display_device().
  • 🤖 Android

    • JNI bridge support to intercept onPermissionRequest in RustWebChromeClient.kt.
    • Routes Android WebKit resource types (e.g. AUDIO_CAPTURE, VIDEO_CAPTURE, PROTECTED_MEDIA_ID) to Rust and applies the user's PermissionResponse.

Examples

Added a permission_handler example using permission.site to easily test permission dialogs and intercepts across platforms. Run with:

cargo run --example permission_handler

@F0RLE F0RLE requested a review from a team as a code owner January 9, 2026 11:14
@github-actions
Copy link
Contributor

github-actions bot commented Jan 9, 2026

Package Changes Through 09814aa

There are 1 changes which include wry with minor

Planned Package Versions

The following package releases are the planned based on the context of changes in this pull request.

package current next
wry 0.54.2 0.55.0

Add another change file through the GitHub UI by following this link.


Read about change files or the docs at github.com/jbolda/covector

Copy link
Contributor

@pewsheen pewsheen left a comment

Choose a reason for hiding this comment

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

I currently only have a MacBook, so I'll share some thoughts about the macOS implementation here. For WebView2, maybe @Legend-Master can give some advice?

Personally, I tend not to loosen permission controls, to avoid them being used for malicious purposes.

Copy link
Contributor

@Legend-Master Legend-Master left a comment

Choose a reason for hiding this comment

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

Looks good for the webview2 implementation at least at a glance, awesome work!

Could you also add a change file?

https://github.com/tauri-apps/wry/blob/dev/.changes/readme.md

Legend-Master
Legend-Master previously approved these changes Feb 14, 2026
Copy link
Contributor

@Legend-Master Legend-Master left a comment

Choose a reason for hiding this comment

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

The webview2 code looks good to me and works well when tested on my computer, just a few small nitpicks, you might need to wait for other members to give some feedbacks on other platforms though

Also, you'll need to sign your commits before we can merge them

@F0RLE F0RLE force-pushed the feat/permission-handler branch 2 times, most recently from 6a52c11 to 7aae5c4 Compare February 20, 2026 19:42
@F0RLE F0RLE requested a review from Legend-Master February 20, 2026 21:03
Copy link
Contributor

@pewsheen pewsheen left a comment

Choose a reason for hiding this comment

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

macOS implementation looks good to me. Only a nit that I think we can improve.

Copy link
Contributor

@Legend-Master Legend-Master left a comment

Choose a reason for hiding this comment

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

@F0RLE F0RLE force-pushed the feat/permission-handler branch 2 times, most recently from 28c368b to bad81dd Compare February 23, 2026 16:20
@F0RLE
Copy link
Author

F0RLE commented Feb 23, 2026

The webview2 code looks good to me and works well when tested on my computer, just a few small nitpicks, you might need to wait for other members to give some feedbacks on other platforms though

Also, you'll need to sign your commits before we can merge

Done. The commit is now digitally signed with an SSH key.

@F0RLE F0RLE force-pushed the feat/permission-handler branch from bad81dd to 2f0df9e Compare February 23, 2026 20:47
@F0RLE F0RLE force-pushed the feat/permission-handler branch 2 times, most recently from fa4bba7 to 8ccc02e Compare February 24, 2026 05:24
pewsheen
pewsheen previously approved these changes Feb 24, 2026
Copy link
Contributor

@pewsheen pewsheen left a comment

Choose a reason for hiding this comment

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

wkwebview looks good to me 👍 . Let's see if there's something that needs to be discussed in other platform.

…n handler API, fix combined camera and microphone logic on macOS, update documentation to clarify NFC and Bluetooth support, and simplify permission_handler example using permission.site
@F0RLE F0RLE force-pushed the feat/permission-handler branch from 8ccc02e to f884930 Compare February 24, 2026 11:14
Copy link
Contributor

@Legend-Master Legend-Master left a comment

Choose a reason for hiding this comment

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

Looking good for the webview2 part and general APIs, I'll take a look at the webkitgtk implementation later when I got time. The Android implementation will need someone who's more familiar with the mobile part to review though

Thanks for the patience and awesome work!

Also please don't force push to a single commit on every change, it makes it hard to follow what's changed between each reviews, we will squash merge at the end

Copy link
Contributor

@Legend-Master Legend-Master left a comment

Choose a reason for hiding this comment

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

I have gone ahead and did some adjustments, hope you don't mind

The Windows and Linux implementations are looking good to me, waiting for a reviewer who's more familiar with the mobile implementations to take a final look before merging

@F0RLE
Copy link
Author

F0RLE commented Feb 24, 2026

Thanks for the review and for the adjustments as well! They look good. Let me know if there's anything else for the Android or webkitgtk implementation.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for web APIs that require permissions

3 participants