WebKit mic permission

Hello.

I'm trying to stop my webview from asking for mic permission every time it runs, as I already handle it out in the application. This is the code I use, but it doesn't seem to run the code for the permission at all (tried printing and debugging, and it doesn't go into it at all). I am using visionOs if that makes a difference. Are there any alternative solutions to this?

import SwiftUI
import WebKit
import AVFAudio

struct WebView: UIViewRepresentable {
    let urlString: String
    
    func makeUIView(context: Context) -> WKWebView {
        let webView = WKWebView()
        webView.navigationDelegate = context.coordinator
        if let url = URL(string: urlString) {
            let request = URLRequest(url: url)
            webView.load(request)
        }
        return webView
    }
    
    func updateUIView(_ uiView: WKWebView, context: Context) {}
    
    func makeCoordinator() -> Coordinator {
        Coordinator()
    }
    
    class Coordinator: NSObject, WKUIDelegate, WKNavigationDelegate {
        
        // Handle media capture permissions
        func webView(_ webView: WKWebView,
                     decideMediaCapturePermissionsFor origin: WKSecurityOrigin,
                     initiatedBy frame: WKFrameInfo,
                     type: WKMediaCaptureType) async -> WKPermissionDecision {
            return .grant
        }
        // Handle URL authentication challenges
        func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
            let username = "user"
            let password = "password"
            let credential = URLCredential(user: username, password: password, persistence: .forSession)
            completionHandler(.useCredential, credential)
        }
    }

}

struct AssistantView: View {
    @Environment(\.dismissWindow) private var dismissWindow
    var body: some View {
        WebView(urlString: "https://somelink.com/")
            .edgesIgnoringSafeArea(.all)
            .frame(width: 500, height: 800)
        
    }
    
}

We certainly don't (purposefully) do anything different on VisionOS betas here.

That said, you have a WKUIDelegate implementation to grant permission, but in the code you included you never actually set the ui delegate on the WKWebView. Probably where you set the navigationDelegate is a good place.

WebKit mic permission
 
 
Q