tauri: media permission denied [bug]

Describe the bug

Unable to call camera,unauthorized. No related items found in devtools.

Reproduction

No response

Expected behavior

No response

Platform and versions

window10 x64
pnpm 7
nodejs 16
tauri 1.0.0

Stack trace

No response

Additional context

No response

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 19 (7 by maintainers)

Most upvoted comments

I also have OCD, it took me several days to find it

tauri version v2 dependencies: webview2-com = “0.31.0” windows = “0.57.0”

use webview2_com::Microsoft::Web::WebView2::Win32::{
    ICoreWebView2Profile4, ICoreWebView2_13, COREWEBVIEW2_PERMISSION_KIND_MICROPHONE,
    COREWEBVIEW2_PERMISSION_STATE_DEFAULT,
};
use windows::core::{Interface, PCWSTR};

/**
 *
 * Reset microphone permissions
 */
#[tauri::command]
fn reset_permission(origin: &str, app: AppHandle) {
    let webview = app.get_webview_window("main").unwrap();
    let mut origin = origin.to_string();
    origin.push('\0');
    let origin = origin.encode_utf16().collect::<Vec<u16>>();
    webview
        .with_webview(move |webview| unsafe {
            let core = webview.controller().CoreWebView2().unwrap();
            let core = Interface::cast::<ICoreWebView2_13>(&core).unwrap();
            let profile = core.Profile().unwrap();
            let profile = Interface::cast::<ICoreWebView2Profile4>(&profile).unwrap();
            let origin = PCWSTR::from_raw(origin.as_ptr());
            profile
                .SetPermissionState(
                    COREWEBVIEW2_PERMISSION_KIND_MICROPHONE,
                    origin,
                    COREWEBVIEW2_PERMISSION_STATE_DEFAULT,
                    None,
                )
                .unwrap();
        })
        .unwrap();
}

Hello, we recently added the new experimental Permission Management APIs. Can you check if this meets your needs? https://github.com/MicrosoftEdge/WebView2Feedback/issues/2427#issuecomment-1399097515 Thanks!

Weichens code is just a normal command https://v2.tauri.app/develop/calling-rust/#commands (the code they showed is windows only btw), so it probably belongs in your src-tauri/src/lib.rs file.

if you’re using v2, yes (in v1 the webview bindings are too old). Then you can use the mentioned SetPermissionState in with_webview (via the bindings). If all this is new to you, it would look something like this, just to get a feel for it.

@Interpause You can handle that for your users in rust too. And i know that’s not what you were aiming at, the problem here is that actual solutions are blocked by https://github.com/MicrosoftEdge/WebView2Feedback/issues/2427 😕

Edit: Since this issue was just linked to from a really extensive issue a short additional note: In case someone wonders why we don’t work around the missing permissions api by hooking into the PermissionRequested event (which by itself would be kinda annoying imo), the reason is: it doesn’t work, see https://github.com/MicrosoftEdge/WebView2Feedback/issues/2672

I don’t think that is a proper solution, it certainly isn’t user-friendly to request the user to do the above to reset permission state.

users can delete C:\Users\<user-name>\AppData\Local\<your-app-bundle-identifieer>\EBWebView directory and it will reset the permissions state, so you can prompt them for it again.