Browser mai bianco né muto: pagina iniziale, finestra che resta, fotogrammi che ripartono (#52)
Il browser di Febe a volte era bianco o non mostrava nulla. Le cause erano
diverse e si correggono insieme.
- Pagina iniziale. Se il browser è a riposo su about:blank e Alberto lo apre
(«Usa il browser», «Apri il browser»), Febe lo porta sulla home del sito
quando è collegato, altrimenti sulla pagina di accesso. È un'azione di
Alberto, sotto il suo permesso di guida, non del motore: Febe aspetta che
la sessione finisca e prende il turno della pagina.
Il nuovo pulsante «Pagina iniziale» sta nella barra della finestra di
Windows e nella vista remota. Su about:blank la barra dice «Il browser è a
riposo su una pagina vuota». «Indietro» non torna più sulla pagina di
riposo.
- Disconnessione. «Apri il browser» nella striscia rossa apre la pagina di
accesso. Con --accesso-di-prova il primo controllo all'avvio non segnala
più una disconnessione finta.
- Windows: la finestra resta.
- Lasciare una pagina di Febe non nasconde più la finestra «Browser di
Febe» e non la rimette a riposo: finisce solo il permesso tenuto dalla
pagina (cancel con pageLeft, IConnectionService.ReleaseAsync).
- Sullo schermo la finestra ha il suo pulsante nella barra delle
applicazioni, così ridurla a icona non la fa sparire. Dopo 2 minuti
ridotta a icona torna fuori vista (S2).
- Se lo schermo è troppo piccolo, la finestra si restringe all'area di
lavoro e la pagina si rimpicciolisce con ZoomFactor, con le stesse misure
CSS.
- I bordi della pagina si riapplicano, con NotifyParentWindowPositionChanged,
quando la finestra si mostra, si sposta o riparte il processo GPU.
- Una pagina che non risponde mentre Alberto guida resta com'è.
- IBrowserWindow.ShowAsync lascia il posto a
IConnectionService.ShowBrowserAsync.
- Docker: fotogrammi che ripartono. La vista remota ha un watchdog. Riavvia
i fotogrammi dopo una pagina nuova caricata senza fotogrammi e dopo circa
2 s di silenzio. L'attesa raddoppia fino a 30 s finché la pagina resta
ferma. Se il riavvio non porta nulla, la vista riceve un'immagine ferma
(Page.captureScreenshot, già fra i comandi ammessi).
RemoteViewSession ha ora un registro vero: avvii, riavvii e silenzi vanno
a livello Info, categoria «vista», senza indirizzi.
Se dopo 8 s non arriva nessuna immagine, l'interfaccia mostra «Nessuna
immagine dal browser» con «Riprova».
Nessun comando CDP nuovo e nessuna dipendenza nuova. Aggiornati PROTOCOLLO.md
e la guida (Primo collegamento, Attività e arresti, Installazione Windows,
Problemi comuni).
Prove nuove:
- ScreencastWatchdogTests, RemoteViewFramesTests (Chromium vero, solo CI
Linux)
- Home e Indietro in RemoteViewStartTests
- RemoteViewSocketTests
- ConnectionApiTests
- BrowserStartPageTests
- BrowserWindowDecisionTests e BrowserWindowTests (WebView2 vero)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
65c0c4470e
commit
c49df4ca7b
49 files changed
+2056
-177
No files matched your search
@@ -18,7 +18,24 @@ namespace Febe.Desktop.Browser;
|
||||
/// <param name="AdditionalBrowserArguments">The switches of S2 (<see cref="BrowserArguments.ForWebView2"/>).</param>
|
||||
/// <param name="Icon">The icon of the window.</param>
|
||||
/// <param name="MarkUsed">Called when Alberto uses the browser and when he is done with it («Riprendi»).</param>
|
||||
internal sealed record WebView2HostOptions(BrowserHosting Hosting, string AdditionalBrowserArguments, ImageSource? Icon, Action MarkUsed);
|
||||
/// <param name="StartPage">Where «Pagina iniziale» goes: the site's home when connected, the login page otherwise (issue #52).</param>
|
||||
internal sealed record WebView2HostOptions(BrowserHosting Hosting, string AdditionalBrowserArguments, ImageSource? Icon, Action MarkUsed, Func<string>? StartPage = null);
|
||||
|
||||
/// <summary>What the host does when a process of WebView2 fails (issue #52).</summary>
|
||||
internal enum ProcessFailureResponse
|
||||
{
|
||||
/// <summary>Nothing: WebView2 recovers by itself (an unresponsive page while Alberto looks at it, a helper process).</summary>
|
||||
None,
|
||||
|
||||
/// <summary>The whole browser is gone: the owner starts it again.</summary>
|
||||
Restart,
|
||||
|
||||
/// <summary>The page crashed (or hangs while nobody looks): back to the rest page (spec §6.1).</summary>
|
||||
Rest,
|
||||
|
||||
/// <summary>The GPU process restarted: the bounds are given again, or the window may stay blank or black.</summary>
|
||||
Redraw,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The browser host of the Windows edition (spec §5, §6.1, §12): WebView2 in the window «Browser di Febe», with its own
|
||||
@@ -36,6 +53,9 @@ internal sealed record WebView2HostOptions(BrowserHosting Hosting, string Additi
|
||||
/// «Ho finito»; using and closing it marks the browser as used for «Riprendi».</item>
|
||||
/// <item>Stopping closes the WebView and waits for its browser process to exit, so the session is on disk (S3);
|
||||
/// <see cref="RestartAsync"/> («Scollega») does the same before deleting the profile.</item>
|
||||
/// <item>Issue #52: the bounds (and the zoom of a window shrunk to fit the screen) are given again, and WebView2 told of
|
||||
/// the window's new place, whenever the window moves on or off screen and after the GPU process restarted; a page that
|
||||
/// hangs while Alberto looks at it is left to recover instead of being replaced by the rest page.</item>
|
||||
/// <item>Threads: every WebView2 object (environment, controller, <c>CoreWebView2</c>, its settings and DevTools
|
||||
/// receivers) and the window are touched only on the UI thread, through its dispatcher; WebView2 throws on any other
|
||||
/// thread. Callers on other threads (the composition, the engine) get only plain values captured on the UI thread
|
||||
@@ -147,12 +167,20 @@ internal sealed class WebView2Host : IBrowserHost
|
||||
}
|
||||
|
||||
window.MoveOnScreen();
|
||||
if (window.WindowState == System.Windows.WindowState.Minimized)
|
||||
{
|
||||
window.WindowState = System.Windows.WindowState.Normal;
|
||||
}
|
||||
|
||||
window.Activate();
|
||||
window.Topmost = true;
|
||||
window.Topmost = false;
|
||||
|
||||
// The lease first: once the window is on screen the engine must be still, whatever happens to the focus.
|
||||
TakeLease();
|
||||
|
||||
// On screen, perhaps shrunk to fit it: WebView2 gets its bounds again and learns where its window is now.
|
||||
UpdateBounds();
|
||||
try
|
||||
{
|
||||
_controller?.MoveFocus(CoreWebView2MoveFocusReason.Programmatic);
|
||||
@@ -169,9 +197,24 @@ internal sealed class WebView2Host : IBrowserHost
|
||||
{
|
||||
_window?.MoveOffScreen();
|
||||
ReleaseLease();
|
||||
NotifyPositionChanged();
|
||||
return Task.CompletedTask;
|
||||
});
|
||||
|
||||
/// <summary>
|
||||
/// What a failed process of WebView2 asks of the host (issue #52). A page that does not answer while Alberto is at
|
||||
/// the window is his to wait for (WebView2 recovers, or he reloads): replacing it with the rest page would turn it
|
||||
/// white under his eyes. Nobody looking, it goes to rest as a crashed page does.
|
||||
/// </summary>
|
||||
internal static ProcessFailureResponse ResponseTo(CoreWebView2ProcessFailedKind kind, bool userIsDriving) => kind switch
|
||||
{
|
||||
CoreWebView2ProcessFailedKind.BrowserProcessExited => ProcessFailureResponse.Restart,
|
||||
CoreWebView2ProcessFailedKind.RenderProcessExited => ProcessFailureResponse.Rest,
|
||||
CoreWebView2ProcessFailedKind.RenderProcessUnresponsive => userIsDriving ? ProcessFailureResponse.None : ProcessFailureResponse.Rest,
|
||||
CoreWebView2ProcessFailedKind.GpuProcessExited => ProcessFailureResponse.Redraw,
|
||||
_ => ProcessFailureResponse.None,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Closes the WebView, waits for its browser process to exit (the profile is free and written), runs
|
||||
/// <paramref name="whileStopped"/> — «Scollega» deletes the profile there — and starts it again. <see cref="Cdp"/>
|
||||
@@ -302,7 +345,14 @@ internal sealed class WebView2Host : IBrowserHost
|
||||
window.DoneRequested += (_, _) => Done();
|
||||
window.BackRequested += (_, _) => UserNavigation(core => core.GoBack(), core => core.CanGoBack);
|
||||
window.ReloadRequested += (_, _) => UserNavigation(core => core.Reload(), _ => true);
|
||||
window.HomeRequested += (_, _) => UserNavigation(core => core.Navigate(_settings.StartPage!()), _ => _settings.StartPage is not null);
|
||||
window.DpiChanged += (_, _) => UpdateBounds();
|
||||
window.PageAreaChanged += (_, _) => UpdateBounds();
|
||||
|
||||
// The raw controller does not follow its parent by itself: popups (lists of a <select>, menus, suggestions)
|
||||
// would open where the window was, out of view.
|
||||
window.LocationChanged += (_, _) => NotifyPositionChanged();
|
||||
window.ShowAddress(null);
|
||||
_window = window;
|
||||
}
|
||||
|
||||
@@ -336,6 +386,7 @@ internal sealed class WebView2Host : IBrowserHost
|
||||
|
||||
controller.BoundsMode = CoreWebView2BoundsMode.UseRawPixels;
|
||||
controller.Bounds = _window.PageBounds;
|
||||
controller.ZoomFactor = _window.Fit;
|
||||
|
||||
// WebView2 stops painting when IsVisible is false (S2): it stays true for the whole life of the browser.
|
||||
controller.IsVisible = true;
|
||||
@@ -436,24 +487,38 @@ internal sealed class WebView2Host : IBrowserHost
|
||||
return;
|
||||
}
|
||||
|
||||
if (kind == CoreWebView2ProcessFailedKind.BrowserProcessExited)
|
||||
switch (ResponseTo(kind, UserIsDriving))
|
||||
{
|
||||
// The whole browser is gone: commands fail from now on, and the owner starts it again (same profile), as
|
||||
// the supervisor does with Chromium — once this handler has returned (threading model of WebView2).
|
||||
_session.Detach();
|
||||
_ = _ui.InvokeAsync(() => BrowserProcessFailed?.Invoke(this, EventArgs.Empty), DispatcherPriority.Background);
|
||||
}
|
||||
else if (kind is CoreWebView2ProcessFailedKind.RenderProcessExited or CoreWebView2ProcessFailedKind.RenderProcessUnresponsive)
|
||||
{
|
||||
// The page crashed: back to the rest page (spec §6.1); a running recipe ends on its own errors.
|
||||
try
|
||||
{
|
||||
(sender as CoreWebView2)?.Navigate(CdpPageExtensions.RestUrl);
|
||||
}
|
||||
catch (Exception ex) when (ex is COMException or InvalidOperationException)
|
||||
{
|
||||
// The browser went with the page: its own ProcessFailed follows.
|
||||
}
|
||||
case ProcessFailureResponse.Restart:
|
||||
// The whole browser is gone: commands fail from now on, and the owner starts it again (same profile), as
|
||||
// the supervisor does with Chromium — once this handler has returned (threading model of WebView2).
|
||||
_session.Detach();
|
||||
_ = _ui.InvokeAsync(() => BrowserProcessFailed?.Invoke(this, EventArgs.Empty), DispatcherPriority.Background);
|
||||
break;
|
||||
case ProcessFailureResponse.Rest:
|
||||
// The page crashed: back to the rest page (spec §6.1); a running recipe ends on its own errors.
|
||||
try
|
||||
{
|
||||
(sender as CoreWebView2)?.Navigate(CdpPageExtensions.RestUrl);
|
||||
}
|
||||
catch (Exception ex) when (ex is COMException or InvalidOperationException)
|
||||
{
|
||||
// The browser went with the page: its own ProcessFailed follows.
|
||||
}
|
||||
|
||||
break;
|
||||
case ProcessFailureResponse.Redraw:
|
||||
// A windowed WebView can stay blank or black after the GPU process restarted until its bounds change:
|
||||
// they are given again (never IsVisible = false, S2), once this handler has returned.
|
||||
_ = _ui.InvokeAsync(UpdateBounds, DispatcherPriority.Background);
|
||||
break;
|
||||
default:
|
||||
if (kind == CoreWebView2ProcessFailedKind.RenderProcessUnresponsive)
|
||||
{
|
||||
_log.Info("browser", "WebView2: la pagina non risponde mentre usi il browser; Febe la lascia com'è (Ricarica, se non si riprende).");
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -481,11 +546,12 @@ internal sealed class WebView2Host : IBrowserHost
|
||||
TakeLease();
|
||||
}
|
||||
|
||||
/// <summary>Alberto closed or minimised the window: done, out of view.</summary>
|
||||
/// <summary>Alberto closed the window (or left it minimised too long): done, out of view.</summary>
|
||||
private void Done()
|
||||
{
|
||||
_window?.MoveOffScreen();
|
||||
ReleaseLease();
|
||||
NotifyPositionChanged();
|
||||
}
|
||||
|
||||
private void UserNavigation(Action<CoreWebView2> action, Func<CoreWebView2, bool> allowed)
|
||||
@@ -520,6 +586,10 @@ internal sealed class WebView2Host : IBrowserHost
|
||||
try
|
||||
{
|
||||
controller.Bounds = window.PageBounds;
|
||||
|
||||
// Shrunk to fit a small screen, the page is zoomed out by as much: its size in CSS pixels stays the same.
|
||||
controller.ZoomFactor = window.Fit;
|
||||
controller.NotifyParentWindowPositionChanged();
|
||||
}
|
||||
catch (Exception ex) when (ex is COMException or InvalidOperationException)
|
||||
{
|
||||
@@ -527,6 +597,18 @@ internal sealed class WebView2Host : IBrowserHost
|
||||
}
|
||||
}
|
||||
|
||||
private void NotifyPositionChanged()
|
||||
{
|
||||
try
|
||||
{
|
||||
_controller?.NotifyParentWindowPositionChanged();
|
||||
}
|
||||
catch (Exception ex) when (ex is COMException or InvalidOperationException)
|
||||
{
|
||||
// The browser process is gone: the next start places the new WebView.
|
||||
}
|
||||
}
|
||||
|
||||
private void TakeLease()
|
||||
{
|
||||
if (_lease is null)
|
||||
|
||||
Reference in new issue
Block a user