在Windows上的WebView2中,异步脚本对话框提示

huangapple go评论69阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年4月20日 08:13:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76059672.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定