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:
Alby96andClaude Opus 5.5 committed 2026-11-16 12:51:12 +01:00
1 parent 65c0c4470e
commit c49df4ca7b
49 files changed
+2056 -177

No files matched your search

+39 -10
View File
@@ -2,6 +2,7 @@ using System.Runtime.CompilerServices;
using System.Text.Json;
using Febe.App;
using Febe.Browser.Cdp;
using Febe.Browser.Diagnostics;
using Febe.Browser.Gestures;
using Febe.Browser.RemoteView;
using Febe.Core.Abstractions;
@@ -24,6 +25,7 @@ internal sealed class BrowserRemoteViewHost : IRemoteViewHost
private readonly IClock _clock;
private readonly IClock _browserClock;
private readonly FebeLog _log;
private readonly Func<string>? _startPage;
private readonly Lock _gate = new();
private readonly SemaphoreSlim _opening = new(1, 1);
private BrowserRemoteViewConnection? _current;
@@ -34,18 +36,26 @@ internal sealed class BrowserRemoteViewHost : IRemoteViewHost
/// <param name="clock">The composition's clock (the time of that note).</param>
/// <param name="log">Febe's log.</param>
/// <param name="browserClock">
/// Time for the waits on the browser itself; null: the wall clock, because the browser commits a navigation in real
/// time whatever clock the engine runs on (the tests compress it).
/// Time for the waits on the browser itself and for the frames' watchdog; null: the wall clock, because the browser
/// commits a navigation and paints in real time whatever clock the engine runs on (the tests compress it).
/// </param>
public BrowserRemoteViewHost(IFebeBrowser browser, BrowserUseTracker tracker, IClock clock, FebeLog log, IClock? browserClock = null)
/// <param name="startPage">Where «Pagina iniziale» goes (issue #52); null: the button does nothing.</param>
public BrowserRemoteViewHost(IFebeBrowser browser, BrowserUseTracker tracker, IClock clock, FebeLog log, IClock? browserClock = null, Func<string>? startPage = null)
{
_browser = browser ?? throw new ArgumentNullException(nameof(browser));
_tracker = tracker ?? throw new ArgumentNullException(nameof(tracker));
_clock = clock ?? throw new ArgumentNullException(nameof(clock));
_log = log ?? throw new ArgumentNullException(nameof(log));
_browserClock = browserClock ?? new SystemClock(clock.LocalZone);
_startPage = startPage;
}
/// <summary>
/// How an open view notices that frames stopped coming and starts them again (issue #52); null: never (tests whose
/// clock moves only when asked).
/// </summary>
public ScreencastWatchdog? Watchdog { get; set; } = ScreencastWatchdog.Default;
public async Task<IRemoteViewConnection> OpenAsync(CancellationToken ct)
{
if (!_browser.IsAvailable)
@@ -83,7 +93,7 @@ internal sealed class BrowserRemoteViewHost : IRemoteViewHost
await previous.EndAsync(RemoteViewEnd.Replaced).ConfigureAwait(false);
}
var connection = new BrowserRemoteViewConnection(this, _browser, _tracker, _clock, _browserClock);
var connection = new BrowserRemoteViewConnection(this, _browser, _tracker, _clock, _browserClock, _log.ForBrowser("vista"), _startPage, Watchdog);
try
{
await connection.StartAsync(_browser.WindowWidth, _browser.WindowHeight, ct).ConfigureAwait(false);
@@ -167,6 +177,8 @@ internal sealed class BrowserRemoteViewConnection : IRemoteViewConnection
private readonly BrowserUseTracker _tracker;
private readonly IClock _clock;
private readonly RemoteViewSession _session;
private readonly Func<string>? _startPage;
private readonly ScreencastWatchdog? _watchdog;
private readonly Lock _gate = new();
private readonly Queue<RemoteViewMeta> _meta = new();
private readonly SemaphoreSlim _signal = new(0, int.MaxValue);
@@ -184,13 +196,17 @@ internal sealed class BrowserRemoteViewConnection : IRemoteViewConnection
private int _disposed;
private bool _used;
public BrowserRemoteViewConnection(BrowserRemoteViewHost owner, IFebeBrowser browser, BrowserUseTracker tracker, IClock clock, IClock browserClock)
public BrowserRemoteViewConnection(BrowserRemoteViewHost owner, IFebeBrowser browser, BrowserUseTracker tracker, IClock clock, IClock browserClock, IBrowserLog log, Func<string>? startPage, ScreencastWatchdog? watchdog)
{
_owner = owner;
_browser = browser;
_tracker = tracker;
_clock = clock;
_session = new RemoteViewSession(browser.Cdp, browser.UserDriving, clock: browserClock);
_startPage = startPage;
_watchdog = watchdog;
// A real log (issue #52): the starts, restarts and silences of the frames reach the registro.
_session = new RemoteViewSession(browser.Cdp, browser.UserDriving, log, browserClock);
}
public RemoteViewEnd? Ended { get; private set; }
@@ -216,7 +232,7 @@ internal sealed class BrowserRemoteViewConnection : IRemoteViewConnection
_signal.Release();
_session.Screencast.FrameReceived += OnFrame;
await _session.StartAsync(new ScreencastOptions(Quality: 70, MaxWidth: width, MaxHeight: height), ct).ConfigureAwait(false);
await _session.StartAsync(new ScreencastOptions(Quality: 70, MaxWidth: width, MaxHeight: height, Watchdog: _watchdog), ct).ConfigureAwait(false);
}
public async IAsyncEnumerable<RemoteViewOutput> ReadAsync([EnumeratorCancellation] CancellationToken ct)
@@ -303,14 +319,25 @@ internal sealed class BrowserRemoteViewConnection : IRemoteViewConnection
string? target;
lock (_gate)
{
if (action == RemoteViewNavigation.Back)
if (action == RemoteViewNavigation.Home)
{
if (_history.Count < 2)
target = _startPage?.Invoke();
}
else if (action == RemoteViewNavigation.Back)
{
// Back never lands on the empty rest page (issue #52): it skips it, and with nothing before it stays.
var previous = _history.Count - 2;
while (previous >= 0 && IsRest(_history[previous]))
{
previous--;
}
if (previous < 0)
{
return;
}
_history.RemoveAt(_history.Count - 1);
_history.RemoveRange(previous + 1, _history.Count - previous - 1);
target = _history[^1];
}
else
@@ -452,6 +479,8 @@ internal sealed class BrowserRemoteViewConnection : IRemoteViewConnection
/// <summary>The address without query string or fragment (they may carry tokens).</summary>
internal static string WithoutQuery(string url) => Addresses.WithoutQuery(url);
private static bool IsRest(string url) => url is "" or CdpPageExtensions.RestUrl;
}
/// <summary>Turns the DOM key of the page into what <c>Input.dispatchKeyEvent</c> needs (virtual key codes).</summary>