Revisione: il browser che non risponde nemmeno alla navigazione viene comunque in primo piano (#67)
Con la correzione #67 un browser che resta muto per tutta l'attesa conta come a riposo, e Febe prova ad aprire la pagina iniziale. Un browser che si sta ancora riavviando dopo «Scollega» rifiuta però anche Page.navigate: l'errore risaliva fino all'API e Alberto vedeva, dopo dieci secondi, un errore interno al posto della finestra. Ora quella navigazione mancata si annota nel registro («non aperta (il browser non risponde)») e la finestra viene in primo piano come prima. Nuova prova con un browser che non risponde a nulla, per «Usa il browser» e «Apri il browser». Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8edb706e06
commit
8d1b344366
3 files changed
+56
-1
No files matched your search
@@ -1136,7 +1136,19 @@ public sealed class BrowserConnectionService : IConnectionService, IAsyncDisposa
|
||||
return;
|
||||
}
|
||||
|
||||
var result = await _browser.Cdp.NavigateAsync(target, ct).ConfigureAwait(false);
|
||||
// A browser still silent (restarting after «Scollega», issue #67) usually refuses the navigation too: the window
|
||||
// comes to the front all the same, as when its page was unknown before, never an internal error.
|
||||
NavigationResult result;
|
||||
try
|
||||
{
|
||||
result = await _browser.Cdp.NavigateAsync(target, ct).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex) when (ex is CdpDisconnectedException or BrowserUnavailableException or CdpCommandException or TimeoutException)
|
||||
{
|
||||
_log.Info("collegamento", $"Alberto usa il browser: {what} non aperta (il browser non risponde).");
|
||||
return;
|
||||
}
|
||||
|
||||
_log.Info("collegamento", result.Succeeded
|
||||
? $"Alberto usa il browser: {what} aperta."
|
||||
: $"Alberto usa il browser: {what} non aperta (errore di rete del browser).");
|
||||
|
||||
@@ -149,6 +149,33 @@ public sealed class BrowserStartPageTests
|
||||
Assert.AreEqual(Login, browser.FakeCdp.Url);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Timeout(60_000, CooperativeCancellation = true)]
|
||||
public async Task ABrowserThatAnswersNothingStillComesToTheFrontWithoutAnError()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
await using var bed = await DesktopTestBed.StartAsync();
|
||||
await bed.App.Running.WaitAsync(TimeSpan.FromSeconds(20), ct);
|
||||
var browser = bed.Browser!;
|
||||
bed.App.Connection!.AddressWait = TimeSpan.FromMilliseconds(300);
|
||||
|
||||
// Still restarting (issue #67): no page and no navigation either. The window comes all the same, never a 500.
|
||||
browser.FakeCdp.Silent = true;
|
||||
browser.FakeCdp.RefusesNavigation = true;
|
||||
var shown = browser.Shown;
|
||||
await BeginAsync(bed, openLogin: false);
|
||||
Assert.AreEqual(shown + 1, browser.Shown, "«Usa il browser»: the window came to the front");
|
||||
|
||||
var result = await bed.JsonAsync(HttpMethod.Post, "/api/browser/show");
|
||||
StringAssert.Contains(result.GetProperty("message").GetString(), "primo piano");
|
||||
Assert.AreEqual(shown + 2, browser.Shown, "«Apri il browser»: the window came to the front");
|
||||
Assert.AreEqual("about:blank", browser.FakeCdp.Url, "nothing could open");
|
||||
Assert.DoesNotContain(Login, browser.FakeCdp.Visited);
|
||||
|
||||
browser.FakeCdp.Silent = false;
|
||||
browser.FakeCdp.RefusesNavigation = false;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Timeout(60_000, CooperativeCancellation = true)]
|
||||
public async Task ApriIlBrowserBringsTheWindowWithItsStartPageAndTheLoginAfterADisconnection()
|
||||
|
||||
@@ -265,6 +265,7 @@ internal sealed class FakeCdp : ICdpSession
|
||||
private int _cookieReads;
|
||||
private bool _silent;
|
||||
private int _silentAnswers;
|
||||
private bool _refusesNavigation;
|
||||
|
||||
public bool LoggedIn { get; set; }
|
||||
|
||||
@@ -328,6 +329,16 @@ internal sealed class FakeCdp : ICdpSession
|
||||
/// <summary>How many times <c>Page.getFrameTree</c> was asked while <see cref="Silent"/>.</summary>
|
||||
public int SilentAnswers => Volatile.Read(ref _silentAnswers);
|
||||
|
||||
/// <summary>
|
||||
/// While true <c>Page.navigate</c> fails as a closed connection too, like a browser that has not finished restarting
|
||||
/// (issue #67): with <see cref="Silent"/>, a browser that answers nothing at all.
|
||||
/// </summary>
|
||||
public bool RefusesNavigation
|
||||
{
|
||||
get => Volatile.Read(ref _refusesNavigation);
|
||||
set => Volatile.Write(ref _refusesNavigation, value);
|
||||
}
|
||||
|
||||
public ConcurrentQueue<string> Methods { get; } = new();
|
||||
|
||||
/// <summary>Every address a <c>Page.navigate</c> asked for, in order.</summary>
|
||||
@@ -350,6 +361,11 @@ internal sealed class FakeCdp : ICdpSession
|
||||
return Task.FromException<JsonElement>(new CdpDisconnectedException());
|
||||
}
|
||||
|
||||
if (method == "Page.navigate" && RefusesNavigation)
|
||||
{
|
||||
return Task.FromException<JsonElement>(new CdpDisconnectedException());
|
||||
}
|
||||
|
||||
JsonNode result = method switch
|
||||
{
|
||||
"Page.getFrameTree" => new JsonObject { ["frameTree"] = new JsonObject { ["frame"] = new JsonObject { ["id"] = "F1", ["url"] = Url } } },
|
||||
|
||||
Reference in new issue
Block a user