Skip to content

feat: add permission handler API across webview backends#1654

Open
F0RLE wants to merge 15 commits into
tauri-apps:devfrom
F0RLE:feat/permission-handler
Open

feat: add permission handler API across webview backends#1654
F0RLE wants to merge 15 commits into
tauri-apps:devfrom
F0RLE:feat/permission-handler

Conversation

@F0RLE
Copy link
Copy Markdown

@F0RLE F0RLE commented Jan 9, 2026

Description

This PR adds a unified Permission Handler API for intercepting webview permission requests across WebView2, WKWebView, WebKitGTK, and Android.

The API lets applications decide how to handle permission requests at runtime by returning Allow, Deny, Default, or Prompt from a new WebViewBuilder::with_permission_handler callback.

Key Changes

  • Added WebViewBuilder::with_permission_handler.
  • Added PermissionKind for webview permission categories such as camera, microphone, geolocation, notifications, display capture, MIDI, local fonts, file system access, autoplay, and more.
  • Added PermissionResponse with Allow, Deny, Default, and Prompt.
  • Added a permission_handler example using permission.site.

Platform Implementations

  • Windows (WebView2)

    • Handles WebView2 PermissionRequested events.
    • Maps WebView2 permission kinds to PermissionKind.
    • Applies Allow and Deny; Default and Prompt leave WebView2 default handling in place.
  • macOS / iOS (WKWebView)

    • Handles requestMediaCapturePermission.
    • Maps camera and microphone capture requests to PermissionKind.
    • Handles combined CameraAndMicrophone requests by checking camera and microphone separately, with deny taking precedence.
  • Linux (WebKitGTK)

    • Handles the permission-request signal.
    • Supports geolocation, notifications, pointer lock, camera, microphone, and display capture where available.
    • Uses is_for_display_device() with the v2_42 feature and falls back to display-capture detection for older WebKitGTK versions.
  • Android

    • Handles WebChromeClient.onPermissionRequest and geolocation permission prompts through JNI.
    • Supports camera, microphone, protected media, MIDI, and geolocation requests.
    • Scopes permission handlers per WebView so multi-webview apps route requests to the correct handler.
    • Android runtime permissions may still trigger native OS prompts before access is granted.

Example

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
Copy Markdown
Contributor

github-actions Bot commented Jan 9, 2026

Package Changes Through 954e3e6

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.55.0 0.56.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
Copy Markdown
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.

Comment thread src/wkwebview/class/wry_web_view_ui_delegate.rs
Comment thread src/wkwebview/class/wry_web_view_ui_delegate.rs Outdated
Comment thread src/lib.rs Outdated
Copy link
Copy Markdown
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

Comment thread src/lib.rs Outdated
Legend-Master
Legend-Master previously approved these changes Feb 14, 2026
Copy link
Copy Markdown
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

Comment thread src/lib.rs Outdated
Comment thread src/webview2/mod.rs
Comment thread src/webview2/mod.rs Outdated
@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
Copy Markdown
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.

Comment thread src/wkwebview/class/wry_web_view_ui_delegate.rs Outdated
Comment thread src/wkwebview/class/wry_web_view_ui_delegate.rs Outdated
Copy link
Copy Markdown
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.

Comment thread examples/permission_handler.rs Outdated
Comment thread src/lib.rs Outdated
@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
Copy Markdown
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
Comment thread src/lib.rs Outdated
Comment thread src/lib.rs Outdated
@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
Copy Markdown
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
Copy Markdown
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

Comment thread src/lib.rs Outdated
Legend-Master
Legend-Master previously approved these changes Feb 24, 2026
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread src/webkitgtk/mod.rs Outdated
Comment thread src/webkitgtk/mod.rs Outdated
Comment thread src/wkwebview/class/wry_web_view_ui_delegate.rs
Copy link
Copy Markdown
Author

@F0RLE F0RLE left a comment

Choose a reason for hiding this comment

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

Thanks for the review @FabianLars! Addressed your comments in the latest commit:

  1. Combined audio+video on webkitgtk — fixed. Now each permission (mic/camera) is checked individually via is_for_audio_device() / is_for_video_device(). If either is denied, the whole request is denied.

  2. WebKitGTK >2.42is_for_display_device() is gated behind the v2_42 feature flag. For older versions we fall back to !is_audio && !is_video as a heuristic for display capture.

  3. CameraAndMicrophone — on both webkitgtk and macOS/iOS the combined request is now handled by checking PermissionKind::Microphone and PermissionKind::Camera separately, so the handler can grant one and deny the other independently. I think keeping them separate is cleaner than adding a combined variant.

@F0RLE F0RLE force-pushed the feat/permission-handler branch from 33d810e to b9d86ef Compare April 11, 2026 17:12
@F0RLE F0RLE requested a review from Legend-Master April 16, 2026 23:17
@F0RLE F0RLE changed the title feat: add permission handler API for WebView2 feat: add permission handler API across webview backends Apr 25, 2026
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

4 participants