Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

media permission denied [bug] #4434

Closed
Zhiqiang-Wu opened this issue Jun 22, 2022 · 13 comments
Closed

media permission denied [bug] #4434

Zhiqiang-Wu opened this issue Jun 22, 2022 · 13 comments

Comments

@Zhiqiang-Wu
Copy link

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

@amrbashir
Copy link
Member

please share the full tauri info and if possible a minimal repro.

@Zhiqiang-Wu Zhiqiang-Wu closed this as not planned Won't fix, can't repro, duplicate, stale Jun 23, 2022
@Zhiqiang-Wu Zhiqiang-Wu reopened this Jun 23, 2022
@Zhiqiang-Wu
Copy link
Author

demo.zip

start script:

umi dev
tauri dev

1、open media -> select reject -> console.log(err);

2、open media -> console.log(err); Immediate failure.

Unable to reacquire permissions.

Permission can be reset in the edge browser.

But webview2 can`t.


Reset site permissions in edge browser.

img

@amrbashir
Copy link
Member

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.

@Interpause
Copy link

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.

@FabianLars
Copy link
Member

FabianLars commented Aug 9, 2022

@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 MicrosoftEdge/WebView2Feedback#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 MicrosoftEdge/WebView2Feedback#2672

@nishitha-burman
Copy link

nishitha-burman commented Jan 23, 2023

Hello, we recently added the new experimental Permission Management APIs. Can you check if this meets your needs? MicrosoftEdge/WebView2Feedback#2427 (comment) Thanks!

@fortserious
Copy link

Hi @FabianLars , now that both of those WebView2Feedback issues have been resolved and the Permission Management APIs have been released, is it possible to hook into these APIs to reset permission state while the WebView2 app is open? The Rust solution won't work for us, as we can't expect our users to close down the app and delete the EBWebView directory themselves.

@FabianLars
Copy link
Member

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.

@WeiChens
Copy link

WeiChens commented Aug 5, 2024

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();
}

@rasteiner
Copy link

@WeiChens Thank you very much 😊

In my case I used COREWEBVIEW2_PERMISSION_STATE_ALLOW.

For completeness sake:

await invoke('reset_permission', { origin: window.origin });
const devices = await navigator.mediaDevices.enumerateDevices();
console.log('Weeeee', devices);

@kamalkech
Copy link

@WeiChens cannot find type AppHandle in this scope not found in this scope

@FabianLars
Copy link
Member

Import it then, your code editor should hopefully do it for you.
If not, simply add use tauri::AppHandle;

@kamalkech
Copy link

@FabianLars thank u for response, i already fix this yesterday using Info.plist params without code rust

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

No branches or pull requests

9 participants