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 System.Diagnostics;
|
|
using Febe.Browser.Cdp;
|
|
using Febe.Browser.RemoteView;
|
|
using Febe.Tests.Browser.TestSupport;
|
|
|
|
namespace Febe.Tests.Browser;
|
|
|
|
/// <summary>
|
|
/// The remote view that stayed white (Gitea issue #52), on a real Chromium on Xvfb and the local test site: a page that
|
|
/// does not move still shows itself, and the frames keep coming when the page changes renderer (another site, the rest
|
|
/// page and back). Only in the Linux CI; never Instagram.
|
|
/// </summary>
|
|
[TestClass]
|
|
[DoNotParallelize]
|
|
public sealed class RemoteViewFramesTests
|
|
{
|
|
public TestContext TestContext { get; set; } = null!;
|
|
|
|
[TestInitialize]
|
|
public void RequireBrowser()
|
|
{
|
|
if (RealBrowser.UnavailableReason() is { } reason)
|
|
{
|
|
Assert.Inconclusive(reason);
|
|
}
|
|
}
|
|
|
|
[TestMethod]
|
|
[Timeout(120_000, CooperativeCancellation = true)]
|
|
public async Task AStillPageAndTheRestPageShowAPictureWithinFiveSeconds()
|
|
{
|
|
var ct = TestContext.CancellationToken;
|
|
await using var browser = await RealBrowser.StartAsync();
|
|
var cdp = browser.Cdp;
|
|
var opened = await cdp.NavigateAsync(browser.Site.Url("/accesso"), ct);
|
|
Assert.IsTrue(opened.Succeeded, opened.ErrorText);
|
|
await cdp.WaitForLoadAsync(new Febe.Core.Abstractions.SystemClock(), TimeSpan.FromSeconds(15), ct);
|
|
|
|
var view = new RemoteViewSession(cdp, browser.Host.UserDriving);
|
|
try
|
|
{
|
|
await view.StartAsync(new ScreencastOptions(Quality: 60, MaxWidth: 1280, MaxHeight: 900, Watchdog: ScreencastWatchdog.Default), ct);
|
|
Assert.IsTrue(await PictureAfterAsync(view.Screencast, null, TimeSpan.FromSeconds(5), ct), "a picture of the login page");
|
|
|
|
var last = view.Screencast.LastFrame;
|
|
var rest = await cdp.RestAsync(ct);
|
|
Assert.IsTrue(rest.Succeeded, rest.ErrorText);
|
|
Assert.IsTrue(await PictureAfterAsync(view.Screencast, last, TimeSpan.FromSeconds(5), ct), "a picture of the rest page too");
|
|
}
|
|
finally
|
|
{
|
|
await view.DisposeAsync();
|
|
}
|
|
}
|
|
|
|
[TestMethod]
|
|
[Timeout(180_000, CooperativeCancellation = true)]
|
|
public async Task FramesKeepComingWhenThePageChangesRenderer()
|
|
{
|
|
var ct = TestContext.CancellationToken;
|
|
await using var browser = await RealBrowser.StartAsync();
|
|
var cdp = browser.Cdp;
|
|
var first = await cdp.NavigateAsync(browser.Site.Url("/animata"), ct);
|
|
Assert.IsTrue(first.Succeeded, first.ErrorText);
|
|
|
|
var view = new RemoteViewSession(cdp, browser.Host.UserDriving);
|
|
try
|
|
{
|
|
await view.StartAsync(new ScreencastOptions(Quality: 60, MaxWidth: 1280, MaxHeight: 900, Watchdog: ScreencastWatchdog.Default), ct);
|
|
Assert.IsTrue(await FramesAfterAsync(view.Screencast, ct), "frames of the animated page");
|
|
|
|
foreach (var (address, moving) in new[]
|
|
{
|
|
(browser.Site.LocalhostUrl("/animata"), true),
|
|
("about:blank", false),
|
|
(browser.Site.Url("/animata"), true),
|
|
})
|
|
{
|
|
var last = view.Screencast.LastFrame;
|
|
var watch = Stopwatch.StartNew();
|
|
var navigated = await cdp.NavigateAsync(address, ct);
|
|
Assert.IsTrue(navigated.Succeeded, $"{address}: {navigated.ErrorText}");
|
|
var shown = moving
|
|
? await FramesAfterAsync(view.Screencast, ct)
|
|
: await PictureAfterAsync(view.Screencast, last, TimeSpan.FromSeconds(5), ct);
|
|
TestContext.WriteLine($"{address}: {(shown ? "immagini" : "niente")} dopo {watch.ElapsedMilliseconds} ms, riavvii {view.Screencast.Restarts}.");
|
|
Assert.IsTrue(shown, $"{address}: the view is not white");
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
await view.DisposeAsync();
|
|
}
|
|
}
|
|
|
|
/// <summary>A frame or a still picture other than <paramref name="last"/>, within <paramref name="timeout"/>.</summary>
|
|
private static async Task<bool> PictureAfterAsync(ScreencastSession screencast, ScreencastFrame? last, TimeSpan timeout, CancellationToken ct)
|
|
{
|
|
var deadline = Stopwatch.StartNew();
|
|
while (deadline.Elapsed < timeout)
|
|
{
|
|
if (screencast.LastFrame is { Jpeg: [0xFF, 0xD8, ..] } frame && !ReferenceEquals(frame, last))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
await Task.Delay(50, ct);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/// <summary>A few real frames of the screencast (not still pictures) after now, within ten seconds.</summary>
|
|
private static async Task<bool> FramesAfterAsync(ScreencastSession screencast, CancellationToken ct)
|
|
{
|
|
var before = screencast.FramesReceived;
|
|
var deadline = Stopwatch.StartNew();
|
|
while (deadline.Elapsed < TimeSpan.FromSeconds(10))
|
|
{
|
|
if (screencast.FramesReceived >= before + 3)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
await Task.Delay(50, ct);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|