Safari Webkit, NotAllowedError: The request is not allowed

使用tauri v2,跑前后端项目学习时,遇到这条报错:

Unhandled Promise Rejection: NotAllowedError: The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission.

测试代码

console.log(navigator.userAgent);
navigator.permissions.query({name:'camera'}).then(per=>console.log(per.state));
navigator.mediaDevices.getUserMedia({audio: true}).then(stream => console.log(stream)).catch(err => console.error(err));
navigator.mediaDevices.getUserMedia({video: true}).then(stream => console.log(stream)).catch(err => console.error(err));

结果

[Log] Mozilla/5.0 (X11; Ubuntu; Linux x86_64) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15
[Log] prompt
[Error] NotAllowedError: The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission.
	Console Evaluation (Console Evaluation 26:5:115)
[Error] OverconstrainedError {message: "Invalid constraint", constraint: "", name: "OverconstrainedError"}
	Console Evaluation (Console Evaluation 37:3:115)

虽然是prompt,但没有弹窗申请权限,所以导致NotAllowedError

解决

tauri还不成熟,换用electron吧
https://github.com/tauri-apps/wry/issues/85

posted @ 2024-10-13 22:12  Nolca  阅读(42)  评论(0编辑  收藏  举报