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>
131 lines
5.0 KiB
C#
131 lines
5.0 KiB
C#
using Febe.App;
|
|
using Febe.Core.Abstractions;
|
|
using Febe.Core.Library;
|
|
using Febe.Data;
|
|
using Febe.Desktop.Browser;
|
|
using Febe.Desktop.Core;
|
|
using Febe.Web.Engine;
|
|
|
|
namespace Febe.Tests.Windows.Support;
|
|
|
|
/// <summary>
|
|
/// The browser of Febe for Windows on its own, as the composition builds it (<see cref="DesktopPlatform"/> through
|
|
/// <c>DesktopShell</c>): a <see cref="WebView2Browser"/> with its window «Browser di Febe» and WebView2 on a real UI
|
|
/// thread, a profile in a temporary Data folder, the switches of S2 and the log of Febe captured.
|
|
/// </summary>
|
|
internal sealed class BrowserBed : IAsyncDisposable
|
|
{
|
|
private BrowserBed(TestFolder folder, UiThread ui, LogLines lines, FebeLog log, FebeDatabase database, BrowserUseTracker tracker, WebView2Browser browser)
|
|
{
|
|
Folder = folder;
|
|
Ui = ui;
|
|
Lines = lines;
|
|
Log = log;
|
|
Database = database;
|
|
Tracker = tracker;
|
|
Browser = browser;
|
|
}
|
|
|
|
public TestFolder Folder { get; }
|
|
|
|
public UiThread Ui { get; }
|
|
|
|
/// <summary>What Febe wrote in its log.</summary>
|
|
public LogLines Lines { get; }
|
|
|
|
public FebeLog Log { get; }
|
|
|
|
public FebeDatabase Database { get; }
|
|
|
|
/// <summary>When Alberto last used the browser («Riprendi» after a verification).</summary>
|
|
public BrowserUseTracker Tracker { get; }
|
|
|
|
public WebView2Browser Browser { get; }
|
|
|
|
/// <param name="name">Prefix of the temporary folder.</param>
|
|
/// <param name="hosting">How WebView2 draws (S2).</param>
|
|
/// <param name="startPage">Where «Pagina iniziale» goes; null: the login page of the options.</param>
|
|
public static async Task<BrowserBed> CreateAsync(string name, BrowserHosting hosting = BrowserHosting.Window, Func<string>? startPage = null)
|
|
{
|
|
var folder = new TestFolder(name);
|
|
var ui = await UiThread.StartAsync();
|
|
var lines = new LogLines();
|
|
var clock = new SystemClock();
|
|
var log = new FebeLog(null, lines, clock);
|
|
var data = new DataFolderLayout(folder.Combine("dati"));
|
|
var database = await FebeDatabase.OpenAsync(data.Root);
|
|
var options = new FebeAppOptions { DataFolder = data.Root, LibraryFolder = folder.Combine("libreria") };
|
|
var tracker = new BrowserUseTracker();
|
|
var context = new FebePlatformContext(options, data, database, clock, log, tracker, startPage);
|
|
var settings = new WebView2BrowserSettings(data.BrowserProfile, 1280, 900, hosting, BrowserArguments.ForWebView2());
|
|
|
|
// Built off the UI thread, as DesktopPlatform.CreateBrowserAsync does after its awaits.
|
|
var browser = new WebView2Browser(ui.Dispatcher, settings, context, icon: null);
|
|
return new BrowserBed(folder, ui, lines, log, database, tracker, browser);
|
|
}
|
|
|
|
/// <summary>Waits (real time) until <paramref name="condition"/> holds; fails with <paramref name="what"/> and the log otherwise.</summary>
|
|
public async Task WaitUntilAsync(Func<bool> condition, TimeSpan timeout, string what, CancellationToken ct)
|
|
{
|
|
var deadline = DateTime.UtcNow + timeout;
|
|
while (!condition())
|
|
{
|
|
if (DateTime.UtcNow > deadline)
|
|
{
|
|
Assert.Fail($"Tempo scaduto: {what}.\n{Lines.Text}");
|
|
}
|
|
|
|
await Task.Delay(50, ct);
|
|
}
|
|
}
|
|
|
|
/// <summary>Reads a value of the UI thread (the window, its position) through the dispatcher.</summary>
|
|
public Task<T> OnUiAsync<T>(Func<T> read) => Ui.InvokeAsync(read);
|
|
|
|
/// <summary>The class names of the child windows of «Browser di Febe»: one per WebView hosted in it.</summary>
|
|
public Task<IReadOnlyList<string>> ChildWindowsAsync() =>
|
|
OnUiAsync(() => Browser.Host.Window is { } window ? ChildWindows.Of(window.Handle) : (IReadOnlyList<string>)[]);
|
|
|
|
/// <summary>
|
|
/// Starts the browser from a thread-pool thread, like <c>FebeApp.BringUpBrowserAsync</c>, and waits until
|
|
/// <see cref="WebView2Browser.RunAsync"/> returns. Fails at once when the log reports a failed start: the loop of
|
|
/// retries would otherwise go on for ever.
|
|
/// </summary>
|
|
public async Task StartAsync(CancellationToken ct, TimeSpan? timeout = null)
|
|
{
|
|
var run = Task.Run(() => Browser.RunAsync(ct), ct);
|
|
var deadline = DateTime.UtcNow + (timeout ?? TimeSpan.FromSeconds(60));
|
|
while (!run.IsCompleted)
|
|
{
|
|
if (Lines.Any("non parte"))
|
|
{
|
|
Assert.Fail("Il browser di Febe non è partito al primo tentativo:\n" + Lines.Text);
|
|
}
|
|
|
|
if (DateTime.UtcNow > deadline)
|
|
{
|
|
Assert.Fail("Il browser di Febe non è diventato disponibile in tempo:\n" + Lines.Text);
|
|
}
|
|
|
|
await Task.Delay(50, ct);
|
|
}
|
|
|
|
await run;
|
|
}
|
|
|
|
public async ValueTask DisposeAsync()
|
|
{
|
|
try
|
|
{
|
|
await Browser.DisposeAsync();
|
|
}
|
|
finally
|
|
{
|
|
await Ui.DisposeAsync();
|
|
await Database.DisposeAsync();
|
|
Log.Dispose();
|
|
Folder.Dispose();
|
|
}
|
|
}
|
|
}
|