Skip to content

Commit

Permalink
fix script timing for webview2
Browse files Browse the repository at this point in the history
  • Loading branch information
camnewnham committed Aug 17, 2024
1 parent 0c442ff commit 9ebdc75
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Eto.Wpf/Forms/Controls/WebView2Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,6 @@ void Control_CoreWebView2Ready(object sender, CoreWebView2InitializationComplete
{
throw new WebView2InitializationException("Failed to initialize WebView2", e.InitializationException);
}
InjectScripts();

// can't actually do anything here, so execute them in the main loop
Application.Instance.AsyncInvoke(RunDelayedActions);
Expand All @@ -492,6 +491,7 @@ private void RunDelayedActions()

Control.CoreWebView2.DocumentTitleChanged += CoreWebView2_DocumentTitleChanged;
Control.CoreWebView2.NewWindowRequested += CoreWebView2_NewWindowRequested;
Control.CoreWebView2.DOMContentLoaded += CoreWebView2_DOMContentLoadedInjectScripts;
webView2Ready = true;

if (delayedActions != null)
Expand Down Expand Up @@ -664,9 +664,9 @@ private void Control_WebMessageReceived(object sender, CoreWebView2WebMessageRec
/// <summary>
/// Wraps window.chrome.webview.postMessage to window.eto.postMessage for platform consistency
/// </summary>
private void InjectScripts()
private void CoreWebView2_DOMContentLoadedInjectScripts(object sender, CoreWebView2DOMContentLoadedEventArgs e)
{
CoreWebView2.AddScriptToExecuteOnDocumentCreatedAsync("window.eto = { postMessage: function(message) { window.chrome.webview.postMessage(message); } };");
CoreWebView2.ExecuteScriptAsync("window.eto = { postMessage: function(message) { window.chrome.webview.postMessage(message); } };");
}

public Uri Url
Expand Down

0 comments on commit 9ebdc75

Please sign in to comment.