Collegamento e motore: correzioni regole-1, regole-2, regole-6, websec-1, websec-5, websec-6, engine-1, engine-2, sched-1
Pagine aperte da Alberto non sono segnali (regole-1); cookie perso fuori sessione = disconnessione (regole-2); pagina a riposo quando Alberto lascia il browser (regole-6); la lease di «Accedi»/«Usa il browser» finisce da sola dopo 2 minuti senza vista remota né finestra (websec-1); ping con scadenza sulla vista remota (websec-5); aperture della vista remota serializzate (websec-6); orologio virtuale senza fine anticipata (engine-1); la sincronizzazione della coda non duplica il compito in corso (engine-2); raccolte in evidenza programmate (sched-1). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Mzbb6zeFTjT6Rp8b92AVkA
This commit is contained in:
19 files changed
+1122
-92
No files matched your search
@@ -202,15 +202,28 @@ internal sealed class FakeBrowser : IFebeBrowser
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>A CDP session answering like a page: frame tree, navigation, the session cookie (name only).</summary>
|
||||
/// <summary>
|
||||
/// A CDP session answering like a page: frame tree, navigation (with its <c>Page.frameNavigated</c> event, as the
|
||||
/// collection pipeline hears it), the session cookie (name only).
|
||||
/// </summary>
|
||||
internal sealed class FakeCdp : ICdpSession
|
||||
{
|
||||
private readonly Lock _gate = new();
|
||||
private readonly Dictionary<string, List<Action<JsonElement>>> _handlers = new(StringComparer.Ordinal);
|
||||
|
||||
public bool LoggedIn { get; set; }
|
||||
|
||||
public string Url { get; private set; } = "about:blank";
|
||||
|
||||
public ConcurrentQueue<string> Methods { get; } = new();
|
||||
|
||||
/// <summary>The main frame moved to <paramref name="url"/> by itself (a redirect of the site), not by a command.</summary>
|
||||
public void Navigated(string url)
|
||||
{
|
||||
Url = url;
|
||||
Raise("Page.frameNavigated", new JsonObject { ["frame"] = new JsonObject { ["id"] = "F1", ["url"] = url } });
|
||||
}
|
||||
|
||||
public Task<JsonElement> SendAsync(string method, object? parameters = null, CancellationToken ct = default)
|
||||
{
|
||||
CdpCommandPolicy.EnsureAllowed(method);
|
||||
@@ -225,18 +238,57 @@ internal sealed class FakeCdp : ICdpSession
|
||||
return Task.FromResult(JsonDocument.Parse(result.ToJsonString()).RootElement.Clone());
|
||||
}
|
||||
|
||||
public IDisposable On(string eventName, Action<JsonElement> handler) => new Nothing();
|
||||
public IDisposable On(string eventName, Action<JsonElement> handler)
|
||||
{
|
||||
lock (_gate)
|
||||
{
|
||||
if (!_handlers.TryGetValue(eventName, out var list))
|
||||
{
|
||||
_handlers[eventName] = list = [];
|
||||
}
|
||||
|
||||
list.Add(handler);
|
||||
}
|
||||
|
||||
return new Removal(() =>
|
||||
{
|
||||
lock (_gate)
|
||||
{
|
||||
_handlers[eventName].Remove(handler);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private JsonObject Navigate(object? parameters)
|
||||
{
|
||||
Url = (parameters as JsonObject)?["url"]?.GetValue<string>() ?? Url;
|
||||
var url = (parameters as JsonObject)?["url"]?.GetValue<string>();
|
||||
if (url is not null)
|
||||
{
|
||||
Navigated(url);
|
||||
}
|
||||
|
||||
return new JsonObject { ["frameId"] = "F1" };
|
||||
}
|
||||
|
||||
private sealed class Nothing : IDisposable
|
||||
private void Raise(string eventName, JsonObject parameters)
|
||||
{
|
||||
public void Dispose()
|
||||
Action<JsonElement>[] handlers;
|
||||
lock (_gate)
|
||||
{
|
||||
handlers = _handlers.TryGetValue(eventName, out var list) ? [.. list] : [];
|
||||
}
|
||||
|
||||
var element = JsonDocument.Parse(parameters.ToJsonString()).RootElement.Clone();
|
||||
foreach (var handler in handlers)
|
||||
{
|
||||
handler(element);
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class Removal(Action remove) : IDisposable
|
||||
{
|
||||
private Action? _remove = remove;
|
||||
|
||||
public void Dispose() => Interlocked.Exchange(ref _remove, null)?.Invoke();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user