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
@@ -17,9 +17,10 @@ namespace Febe.App;
|
||||
/// means that the session cookie exists in the browser profile: only its existence is checked
|
||||
/// (<c>Network.getCookies</c>, names only), never its value. Opening the login page is Alberto's action, not the
|
||||
/// engine's (rule 7, last sentence): it happens only while he holds the «driving» lease and the engine is still.
|
||||
/// On Windows the browser is the window «Browser di Febe»: «Accedi» and «Portalo in primo piano» bring it to the front,
|
||||
/// «Ho finito» and «Annulla» put it back out of view, «Scollega» closes it before deleting the profile. In Docker
|
||||
/// showing and hiding do nothing (the remote view shows the browser).
|
||||
/// On Windows the browser is the window «Browser di Febe»: «Accedi», «Apri il browser» and «Portalo in primo piano»
|
||||
/// bring it to the front, «Ho finito» and «Annulla» put it back out of view, «Scollega» closes it before deleting the
|
||||
/// profile; leaving a page of Febe leaves it as it is. In Docker showing and hiding do nothing (the remote view shows
|
||||
/// the browser).
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
@@ -29,6 +30,11 @@ namespace Febe.App;
|
||||
/// must not stay still for ever.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// Alberto never meets the empty rest page (issue #52): when he takes the browser while it rests there, his own first
|
||||
/// navigation (rule 7, like the login page) opens <see cref="StartPageUrl"/> — the site's home when connected, the login
|
||||
/// page when not connected or after a disconnection.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// A session cookie that disappears outside a session (or is missing at start-up after a connection) is a disconnection
|
||||
/// (spec §7.6): reported to the breaker as the recipes would, so that it is an incident with its alert and only
|
||||
/// «Riprendi» restarts the engine. Not when Alberto himself is at the browser, nor after his «Scollega».
|
||||
@@ -54,6 +60,7 @@ public sealed class BrowserConnectionService : IConnectionService, IAsyncDisposa
|
||||
private readonly IClock _clock;
|
||||
private readonly FebeLog _log;
|
||||
private readonly string _loginUrl;
|
||||
private readonly string _homeUrl;
|
||||
private readonly SessionCookieOptions _cookie;
|
||||
private readonly SemaphoreSlim _commands = new(1, 1);
|
||||
private readonly Lock _gate = new();
|
||||
@@ -65,7 +72,15 @@ public sealed class BrowserConnectionService : IConnectionService, IAsyncDisposa
|
||||
private bool? _disconnectedByUser;
|
||||
private DateTimeOffset _checkedAt = DateTimeOffset.MinValue;
|
||||
|
||||
public BrowserConnectionService(IFebeBrowser browser, IFebeStorage storage, BrowserUseTracker tracker, IClock clock, FebeLog log, string loginUrl, SessionCookieOptions cookie)
|
||||
/// <param name="browser">The browser of Febe.</param>
|
||||
/// <param name="storage">The database (first connection, «Scollega»).</param>
|
||||
/// <param name="tracker">When Alberto last used the browser.</param>
|
||||
/// <param name="clock">The composition's clock.</param>
|
||||
/// <param name="log">Febe's log.</param>
|
||||
/// <param name="loginUrl">The page «Accedi a Instagram» opens.</param>
|
||||
/// <param name="homeUrl">The site's home, the start page once connected.</param>
|
||||
/// <param name="cookie">The session cookie looked for (its name only).</param>
|
||||
public BrowserConnectionService(IFebeBrowser browser, IFebeStorage storage, BrowserUseTracker tracker, IClock clock, FebeLog log, string loginUrl, string homeUrl, SessionCookieOptions cookie)
|
||||
{
|
||||
_browser = browser ?? throw new ArgumentNullException(nameof(browser));
|
||||
_storage = storage ?? throw new ArgumentNullException(nameof(storage));
|
||||
@@ -73,6 +88,7 @@ public sealed class BrowserConnectionService : IConnectionService, IAsyncDisposa
|
||||
_clock = clock ?? throw new ArgumentNullException(nameof(clock));
|
||||
_log = log ?? throw new ArgumentNullException(nameof(log));
|
||||
_loginUrl = loginUrl ?? throw new ArgumentNullException(nameof(loginUrl));
|
||||
_homeUrl = homeUrl ?? throw new ArgumentNullException(nameof(homeUrl));
|
||||
_cookie = cookie ?? throw new ArgumentNullException(nameof(cookie));
|
||||
}
|
||||
|
||||
@@ -91,6 +107,14 @@ public sealed class BrowserConnectionService : IConnectionService, IAsyncDisposa
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Where the browser goes when Alberto takes it from the rest page or presses «Pagina iniziale» (issue #52): the
|
||||
/// site's home when the session is there, the login page when it is not (or not known yet) and after a disconnection
|
||||
/// (spec §7.6), when Instagram's home would only send him there.
|
||||
/// </summary>
|
||||
public string StartPageUrl =>
|
||||
IsConnected == true && _engine?.Services.Breaker.State.Status != BreakerStatus.Disconnected ? _homeUrl : _loginUrl;
|
||||
|
||||
/// <summary>
|
||||
/// Hook for the readers (hypothesis H10): when the data of the page tell which account is connected, the composition
|
||||
/// marks it as «Tu» (<see cref="Account.IsMine"/>); the status shows that account. Raised after every change of the
|
||||
@@ -150,21 +174,7 @@ public sealed class BrowserConnectionService : IConnectionService, IAsyncDisposa
|
||||
}
|
||||
|
||||
_tracker.MarkUsed(_clock.Now);
|
||||
if (openLogin)
|
||||
{
|
||||
// The engine ends its session when the lease starts; wait for it before taking the page. A search step
|
||||
// in progress (issue #37) stops at its next check of the lease: the login page waits for its turn.
|
||||
await WaitForSessionEndAsync(ct).ConfigureAwait(false);
|
||||
using var turn = await TakePageAsync(ct).ConfigureAwait(false);
|
||||
var result = await _browser.Cdp.NavigateAsync(_loginUrl, ct).ConfigureAwait(false);
|
||||
_log.Info("collegamento", result.Succeeded
|
||||
? "Alberto usa il browser: pagina di accesso aperta."
|
||||
: "Alberto usa il browser: la pagina di accesso non si è aperta (errore di rete del browser).");
|
||||
}
|
||||
else
|
||||
{
|
||||
_log.Info("collegamento", "Alberto usa il browser.");
|
||||
}
|
||||
await OpenForAlbertoAsync(openLogin, ct).ConfigureAwait(false);
|
||||
|
||||
// Windows: the window «Browser di Febe» comes to the front (Docker: nothing, the remote view shows it).
|
||||
await ShowQuietlyAsync(ct).ConfigureAwait(false);
|
||||
@@ -175,6 +185,43 @@ public sealed class BrowserConnectionService : IConnectionService, IAsyncDisposa
|
||||
}
|
||||
}
|
||||
|
||||
public async Task ShowBrowserAsync(bool openLogin, CancellationToken ct)
|
||||
{
|
||||
EnsureBrowser();
|
||||
await _commands.WaitAsync(ct).ConfigureAwait(false);
|
||||
|
||||
// Alberto's hold while his page opens: the window takes its own lease when it comes on screen, and holds the
|
||||
// engine still for as long as it stays there (closing it ends it, as before).
|
||||
var hold = _browser.UserDriving.Begin();
|
||||
try
|
||||
{
|
||||
_tracker.MarkUsed(_clock.Now);
|
||||
await OpenForAlbertoAsync(openLogin, ct).ConfigureAwait(false);
|
||||
await _browser.ShowToUserAsync(ct).ConfigureAwait(false);
|
||||
}
|
||||
finally
|
||||
{
|
||||
hold.Dispose();
|
||||
_commands.Release();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task ReleaseAsync(CancellationToken ct)
|
||||
{
|
||||
await _commands.WaitAsync(ct).ConfigureAwait(false);
|
||||
try
|
||||
{
|
||||
if (ReleaseLease())
|
||||
{
|
||||
_log.Info("collegamento", "Pagina di Febe lasciata: la finestra del browser resta com'è finché non la chiudi.");
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_commands.Release();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<FinishResult> FinishAsync(CancellationToken ct)
|
||||
{
|
||||
await _commands.WaitAsync(ct).ConfigureAwait(false);
|
||||
@@ -305,16 +352,18 @@ public sealed class BrowserConnectionService : IConnectionService, IAsyncDisposa
|
||||
/// <summary>
|
||||
/// Looks at the cookie now (outside the cache) and records the change. Used at start-up, by the background loop
|
||||
/// and after the test site's automatic login. A session that went away (or is missing at start-up after a
|
||||
/// connection) while Alberto is not at the browser is reported to the breaker as a disconnection (spec §7.6).
|
||||
/// connection) while Alberto is not at the browser is reported to the breaker as a disconnection (spec §7.6) —
|
||||
/// unless <paramref name="mayReport"/> is false: the first look of a start with the test site's automatic login,
|
||||
/// which is about to open the session itself (issue #52: a false disconnection at every development start).
|
||||
/// </summary>
|
||||
public async Task<bool?> RefreshAsync(CancellationToken ct)
|
||||
public async Task<bool?> RefreshAsync(CancellationToken ct, bool mayReport = true)
|
||||
{
|
||||
if (!_browser.IsAvailable)
|
||||
{
|
||||
return IsConnected;
|
||||
}
|
||||
|
||||
var connected = await CheckAsync(force: true, mayReport: true, ct).ConfigureAwait(false);
|
||||
var connected = await CheckAsync(force: true, mayReport, ct).ConfigureAwait(false);
|
||||
if (connected == true)
|
||||
{
|
||||
await MarkConnectedAsync(ct).ConfigureAwait(false);
|
||||
@@ -528,6 +577,64 @@ public sealed class BrowserConnectionService : IConnectionService, IAsyncDisposa
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Alberto's own first navigation (rule 7: not an engine action, no Governor), under his lease: the login page when
|
||||
/// asked for, and the start page when the browser rests on the empty page (issue #52). Any other page stays as it is
|
||||
/// — the one he was using, or the verification page of a stop.
|
||||
/// </summary>
|
||||
private async Task OpenForAlbertoAsync(bool openLogin, CancellationToken ct)
|
||||
{
|
||||
if (!openLogin && !IsRest(await FullUrlAsync(ct).ConfigureAwait(false)))
|
||||
{
|
||||
_log.Info("collegamento", "Alberto usa il browser.");
|
||||
return;
|
||||
}
|
||||
|
||||
// The engine ends its session when the lease starts; wait for it before taking the page. A search step in
|
||||
// progress (issue #37) stops at its next check of the lease: Alberto's page waits for its turn.
|
||||
await WaitForSessionEndAsync(ct).ConfigureAwait(false);
|
||||
using var turn = await TakePageAsync(ct).ConfigureAwait(false);
|
||||
string target;
|
||||
string what;
|
||||
if (openLogin)
|
||||
{
|
||||
target = _loginUrl;
|
||||
what = "pagina di accesso";
|
||||
}
|
||||
else if (IsRest(await FullUrlAsync(ct).ConfigureAwait(false)))
|
||||
{
|
||||
target = StartPageUrl;
|
||||
what = target == _loginUrl ? "era a riposo, pagina di accesso" : "era a riposo, pagina iniziale del sito";
|
||||
}
|
||||
else
|
||||
{
|
||||
// The session that just ended left its page: his to look at.
|
||||
_log.Info("collegamento", "Alberto usa il browser.");
|
||||
return;
|
||||
}
|
||||
|
||||
var result = await _browser.Cdp.NavigateAsync(target, ct).ConfigureAwait(false);
|
||||
_log.Info("collegamento", result.Succeeded
|
||||
? $"Alberto usa il browser: {what} aperta."
|
||||
: $"Alberto usa il browser: {what} non aperta (errore di rete del browser).");
|
||||
}
|
||||
|
||||
/// <summary>The empty rest page (or no document at all): never what Alberto should be shown.</summary>
|
||||
private static bool IsRest(string? url) => url is "" or CdpPageExtensions.RestUrl;
|
||||
|
||||
/// <summary>The address of the main frame, in full (never logged); null when the browser does not answer.</summary>
|
||||
private async Task<string?> FullUrlAsync(CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
return await _browser.Cdp.GetMainFrameUrlAsync(ct).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex) when (ex is CdpDisconnectedException or BrowserUnavailableException or CdpCommandException or TimeoutException or KeyNotFoundException or InvalidOperationException)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task WaitForSessionEndAsync(CancellationToken ct)
|
||||
{
|
||||
if (_engine is not { } engine)
|
||||
|
||||
+11
-3
@@ -245,9 +245,11 @@ public sealed class FebeApp : IAsyncDisposable
|
||||
}
|
||||
|
||||
// Browser, connection, engine. The engine loop starts only once the browser is up.
|
||||
var browser = await _platform.CreateBrowserAsync(new FebePlatformContext(o, data, Database, Clock, Log, Tracker), ct).ConfigureAwait(false);
|
||||
// The start page (issue #52) is the connection's, which exists only after the browser: read when asked.
|
||||
var context = new FebePlatformContext(o, data, Database, Clock, Log, Tracker, () => Connection?.StartPageUrl ?? o.LoginUrl);
|
||||
var browser = await _platform.CreateBrowserAsync(context, ct).ConfigureAwait(false);
|
||||
Browser = browser;
|
||||
var connection = new BrowserConnectionService(browser, Database, Tracker, Clock, Log, o.LoginUrl, o.Site.SessionCookie);
|
||||
var connection = new BrowserConnectionService(browser, Database, Tracker, Clock, Log, o.LoginUrl, HomeUrl(o.Site.BaseUrl), o.Site.SessionCookie);
|
||||
Connection = connection;
|
||||
var engineOptions = o.FirstSessionDelay is { } delay
|
||||
? EngineOptions.Default with { StartupDelayMin = delay, StartupDelayMax = delay }
|
||||
@@ -458,7 +460,9 @@ public sealed class FebeApp : IAsyncDisposable
|
||||
services.Events.Notified += WakeDownloads;
|
||||
OnStop(() => services.Events.Notified -= WakeDownloads);
|
||||
|
||||
await Connection!.RefreshAsync(ct).ConfigureAwait(false);
|
||||
// With the test site's automatic login the first look reports nothing: the session it may not find yet is
|
||||
// the one the login below opens (issue #52), not a disconnection.
|
||||
await Connection!.RefreshAsync(ct, mayReport: !o.TestSiteAutoLogin).ConfigureAwait(false);
|
||||
if (o.TestSiteAutoLogin && Connection.IsConnected != true)
|
||||
{
|
||||
await TestSiteLoginAsync(ct).ConfigureAwait(false);
|
||||
@@ -514,6 +518,10 @@ public sealed class FebeApp : IAsyncDisposable
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The site's home page as the browser writes it (with its final slash), for «Pagina iniziale».</summary>
|
||||
private static string HomeUrl(string baseUrl) =>
|
||||
Uri.TryCreate(baseUrl, UriKind.Absolute, out var home) ? home.AbsoluteUri : baseUrl;
|
||||
|
||||
/// <summary>
|
||||
/// Development with the test site only (<c>--accesso-di-prova</c>): what Alberto does by hand on Instagram — open
|
||||
/// the site once, so that its session cookie exists — then back to the rest page.
|
||||
|
||||
@@ -101,7 +101,8 @@ public sealed partial class FebeLog : IDisposable
|
||||
}
|
||||
|
||||
/// <summary>The adapter for the browser layer (it logs only CDP command names, states and counts).</summary>
|
||||
public IBrowserLog ForBrowser() => new DelegateBrowserLog((level, message, exception) => Write(
|
||||
/// <param name="category">The category of the lines (the remote view writes as «vista»).</param>
|
||||
public IBrowserLog ForBrowser(string category = "browser") => new DelegateBrowserLog((level, message, exception) => Write(
|
||||
level switch
|
||||
{
|
||||
BrowserLogLevel.Error => LogLevel.Error,
|
||||
@@ -109,7 +110,7 @@ public sealed partial class FebeLog : IDisposable
|
||||
BrowserLogLevel.Information => LogLevel.Information,
|
||||
_ => LogLevel.Debug,
|
||||
},
|
||||
"browser",
|
||||
category,
|
||||
message,
|
||||
exception));
|
||||
|
||||
|
||||
@@ -55,7 +55,15 @@ public interface IFebePlatform
|
||||
/// <param name="Clock">The clock of the engine.</param>
|
||||
/// <param name="Log">The log.</param>
|
||||
/// <param name="Tracker">When Alberto last used the browser: the desktop window marks it when he uses and closes it.</param>
|
||||
public sealed record FebePlatformContext(FebeAppOptions Options, DataFolderLayout Data, IFebeStorage Storage, IClock Clock, FebeLog Log, BrowserUseTracker Tracker);
|
||||
/// <param name="StartPage">
|
||||
/// Where «Pagina iniziale» of the browser window goes (issue #52): the site's home when connected, the login page
|
||||
/// otherwise. Null: the login page.
|
||||
/// </param>
|
||||
public sealed record FebePlatformContext(FebeAppOptions Options, DataFolderLayout Data, IFebeStorage Storage, IClock Clock, FebeLog Log, BrowserUseTracker Tracker, Func<string>? StartPage = null)
|
||||
{
|
||||
/// <summary>The start page now (<see cref="StartPage"/>, or the login page).</summary>
|
||||
public string CurrentStartPage() => StartPage?.Invoke() ?? Options.LoginUrl;
|
||||
}
|
||||
|
||||
/// <summary>Options of the shared composition, filled by each shell from its own configuration.</summary>
|
||||
public sealed record FebeAppOptions
|
||||
|
||||
@@ -47,6 +47,10 @@ public sealed class ProblemConnectionService(IReadOnlyList<ConfigurationProblem>
|
||||
|
||||
public Task CancelAsync(CancellationToken ct) => Task.CompletedTask;
|
||||
|
||||
public Task ShowBrowserAsync(bool openLogin, CancellationToken ct) => throw Refused();
|
||||
|
||||
public Task ReleaseAsync(CancellationToken ct) => Task.CompletedTask;
|
||||
|
||||
public Task DisconnectAsync(CancellationToken ct) => throw Refused();
|
||||
|
||||
private Febe.Web.Api.BadRequestException Refused() =>
|
||||
|
||||
Reference in new issue
Block a user