feat: add permission handler API for WebView2#1654
feat: add permission handler API for WebView2#1654F0RLE wants to merge 7 commits intotauri-apps:devfrom
Conversation
Package Changes Through 09814aaThere are 1 changes which include wry with minor Planned Package VersionsThe following package releases are the planned based on the context of changes in this pull request.
Add another change file through the GitHub UI by following this link. Read about change files or the docs at github.com/jbolda/covector |
56cc0d1 to
755877e
Compare
pewsheen
left a comment
There was a problem hiding this comment.
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.
Legend-Master
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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
6a52c11 to
7aae5c4
Compare
pewsheen
left a comment
There was a problem hiding this comment.
macOS implementation looks good to me. Only a nit that I think we can improve.
Legend-Master
left a comment
There was a problem hiding this comment.
And you'll need to sign your commits
https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits
28c368b to
bad81dd
Compare
Done. The commit is now digitally signed with an SSH key. |
bad81dd to
2f0df9e
Compare
fa4bba7 to
8ccc02e
Compare
pewsheen
left a comment
There was a problem hiding this comment.
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
8ccc02e to
f884930
Compare
Legend-Master
left a comment
There was a problem hiding this comment.
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
Legend-Master
left a comment
There was a problem hiding this comment.
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
|
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. |
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
PermissionKindEnum: Now explicitly covers 15 permission types, addingDisplayCapture,Midi,Sensors,MediaKeySystemAccess,LocalFonts,WindowManagement,PointerLock,AutomaticDownloads,FileSystemAccess, andAutoplay.PermissionResponse: Applications can now respond to permission requests withAllow,Deny,Default(let the system handle it natively), orPrompt(explicitly trigger a system dialog).WebViewBuilder::with_permission_handler: Added a new builder method taking a closureFn(PermissionKind) -> PermissionResponseto handle incoming permission requests.Platform-Specific Implementations
🍏 macOS / iOS (WKWebView)
WKMediaCaptureTypetoPermissionKind.CameraAndMicrophonerequests: properly determines the finalWKPermissionDecisionbased on the individual responses forCameraandMicrophone.Promptinstead of automatically granting access.🪟 Windows (WebView2)
COREWEBVIEW2_PERMISSION_KINDvariations to the newPermissionKindAPI, ensuring complete coverage over Windows permissions.COREWEBVIEW2_PERMISSION_STATE_ALLOWandCOREWEBVIEW2_PERMISSION_STATE_DENY.🐧 Linux (WebKitGTK)
permission-requestsignal.DisplayCapturescreen sharing on older WebKitGTK versions (< 2.42), bypassing the lack ofis_for_display_device().🤖 Android
onPermissionRequestinRustWebChromeClient.kt.AUDIO_CAPTURE,VIDEO_CAPTURE,PROTECTED_MEDIA_ID) to Rust and applies the user'sPermissionResponse.Examples
Added a
permission_handlerexample using permission.site to easily test permission dialogs and intercepts across platforms. Run with: