我正在嘗試在 Webview2 WPF 控制元件中托管舊版 Web 應用程式,它在打開新視窗并嘗試寫入檔案后一直崩潰。
該解決方案需要與初始視窗和新打開的視窗進行互動,因此我正在處理 Webview2 NewWindowRequested 事件,如下所示:
var deferral = e.GetDeferral();
e.Handled = true;
MainWindow mw = new MainWindow
{
Deferral = deferral,
Args = e
};
mw.Show();
在 CoreWebView2InitializationCompleted 上
if (Deferral != null)
{
Args.NewWindow = wv.CoreWebView2;
Deferral.Complete();
}
這是HTML:
測驗<button onclick="opentwo()">Open</button>
<script type="text/javascript">
function opentwo() {
var two = window.open('');
two.document.open();
two.document.write('<html><head><title>test</title></head><body>this is the body</body></html>')
two.document.close();
}
</script>
我嘗試處理 CoreWebView2 ProcessFailed 事件,它同時為初始 Webview2 和新創建的 Webview2 觸發。ExitCode = -1073741819 ProcessFailedKind = BrowserProcessExited Reason = Unexpected
我正在使用 Webview2 版本 100.0.1185.36
有沒有其他方法可以處理打開新視窗以避免崩潰?如果我讓新視窗使用默認的簡單瀏覽器打開,它作業正常。但是,我需要訪問新創建的視窗。
還有其他想法嗎?
我在這里創建了一個簡單的測驗 - https://github.com/attilamn/webview2-document-write-test
uj5u.com熱心網友回復:
這是 WebView2 運行時中的錯誤。它在版本101.0.1210.8和更高版本中已修復。請參閱測驗即將推出的 API 和功能以獲取有關試用 WebView2 運行時的預覽版本的資訊,該版本應該修復您的錯誤,以及Microsoft Edge 發布日歷以了解修復何時使其穩定(目前預測為 4 月 28 日這一周- 2022)。
在撰寫本文時,WebView2 Runtime 仍然存在該錯誤,但 beta、dev 和 canary 頻道都已修復。WebView2 運行時的下一個版本應包含此修復程式。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/460101.html
上一篇:WPF按鈕在禁用時更改顏色
