Sessione CDP di WebView2: un errore di chi ascolta la ripartenza non disfa l'avvio
WebView2CdpSession.Attach avvisa chi ascolta Reconnected (cattura delle risposte, vista remota) dentro l'avvio del nuovo WebView, sul thread dell'interfaccia: un'eccezione di uno di loro usciva da Attach e trasformava un avvio riuscito in un avvio fallito, da riprovare, con lo stesso esito ogni volta. Ora ogni gestore è chiamato da solo: il suo errore va nel registro (tipo e prima riga) e gli altri lo ricevono comunque. L'avviso resta sincrono, come prima. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ccfd8b5c08
commit
3f222448ee
2 files changed
+81
-1
No files matched your search
@@ -113,7 +113,7 @@ public sealed class WebView2CdpSession : ICdpSession, ICdpConnectionEvents, IAsy
|
||||
_log.Write(BrowserLogLevel.Debug, "CDP: WebView2 collegato.");
|
||||
if (reconnect)
|
||||
{
|
||||
Reconnected?.Invoke(this, EventArgs.Empty);
|
||||
RaiseReconnected();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,6 +275,31 @@ public sealed class WebView2CdpSession : ICdpSession, ICdpConnectionEvents, IAsy
|
||||
return JsonElement.ParseValue(ref reader);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="Reconnected"/>, on the thread of <see cref="Attach"/> (WebView2's UI thread), one handler at a time: an
|
||||
/// error of a handler is logged and never reaches <see cref="Attach"/>, so it cannot undo the start of the new
|
||||
/// WebView that called it. Handlers only queue their work (re-enabling a domain is a command, never sent from here).
|
||||
/// </summary>
|
||||
private void RaiseReconnected()
|
||||
{
|
||||
if (Reconnected is not { } handlers)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var handler in handlers.GetInvocationList().Cast<EventHandler>())
|
||||
{
|
||||
try
|
||||
{
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
catch (Exception ex) when (ex is not OutOfMemoryException)
|
||||
{
|
||||
_log.Write(BrowserLogLevel.Warning, "CDP: errore in chi ascolta il nuovo collegamento con WebView2.", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IDisposable SubscribeNative(IWebView2DevTools devTools, string eventName) =>
|
||||
devTools.Subscribe(eventName, json => _events.Writer.TryWrite(new QueuedEvent(eventName, json ?? string.Empty, null)));
|
||||
|
||||
|
||||
Reference in new issue
Block a user