英文:
Asynchronous script dialog prompts in WebView2 on Windows
问题
I'm developing a MAUI application in C# that implements a WebView2 and I need to change the style of the alert, prompt, and confirm dialogs. In WinUI applications everything is very modern, avoiding synchrony, but apparently only when it suits Microsoft, let me explain:
如果我执行以下操作:
webView.CoreWebView2.Settings.AreDefaultScriptDialogsEnabled = false;
webView.CoreWebView2.ScriptDialogOpening += CustomScriptDialogOpening;
I can intercept the default JavaScript dialogs, but even if the CustomScriptDialogOpening
function is async, the WebView doesn't await it.
So,
How the heck can I make a prompt if I can't await it,
And there's no way to launch the user prompt window synchronously, and if I launch it asynchronously, WebView2 doesn't await it?
I don't know if this has a solution...
Thank you!
英文:
I'm developing a MAUI application in C# that implements a WebView2 and I need to change the style of the alert, prompt, and confirm dialogs. In WinUI applications everything is very modern, avoiding synchrony, but apparently only when it suits Microsoft, let me explain:
If I do:
webView.CoreWebView2.Settings.AreDefaultScriptDialogsEnabled = false;
webView.CoreWebView2.ScriptDialogOpening += CustomScriptDialogOpening;
I can intercept the default JavaScript dialogs, but even if the CustomScriptDialogOpening
function is async, the WebView doesn't await it.
So,
How the heck can I make a prompt if I can't await it,
And there's no way to launch the user prompt window synchronously, and if I launch it asynchronously, WebView2 doesn't await it?
I don't know if this has a solution...
Thank you!
答案1
得分: 1
这是解决方案:e.GetDeferral();
这将允许在等待响应时继续异步执行工作。
然后,执行 e.Completed(); 它将正常工作。
英文:
The solution is e.GetDeferral();
This will allow to continue doing work async while wait for response.
Then you do e.Completed(); and it works properly.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论