Ricerca dei profili con suggerimenti e foto (#37)
«Aggiungi account» ha una sola casella: mentre Alberto scrive compaiono subito i suggerimenti locali, poi i profili di Instagram con la foto, come chiesto in #37. Il browser di Febe scrive nella casella «Cerca» di Instagram con tasti veri da una mappa chiusa (mai Invio, Tab o Esc), controlla prima il fuoco, legge la risposta della pagina e non clicca mai un risultato. La ricerca ha una categoria propria nel Governatore, con tetti larghi che non consumano quelli della raccolta, e si dà il turno con il motore sull'unica pagina; a fine sessione la pagina torna comunque al riposo. Le foto passano dal CDN con un permesso ciascuna e restano solo in memoria. Le risposte di Alberto del 15 novembre (controllo del fuoco, turni, evento requestWillBeSent, niente foto dei seguiti per ora) sono in §6.1 e in docs/decisioni.md. Su Instagram vero la ricerca parte quando i bersagli search-open e search-box saranno raccolti dal vivo. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5e417c666d
commit
9941a2fa1f
98 files changed
+8021
-229
No files matched your search
@@ -54,6 +54,7 @@ public sealed record ResponseTapStats(long Responses, long JsonBodies, long Body
|
||||
/// </remarks>
|
||||
public sealed class ResponseTap : IAsyncDisposable
|
||||
{
|
||||
private const int MaxRequestOrders = 4096;
|
||||
private static readonly JsonDocumentOptions BodyOptions = new() { MaxDepth = 256 };
|
||||
|
||||
private readonly ICdpSession _cdp;
|
||||
@@ -68,6 +69,8 @@ public sealed class ResponseTap : IAsyncDisposable
|
||||
private readonly Channel<PendingBody> _queue = Channel.CreateUnbounded<PendingBody>(new UnboundedChannelOptions { SingleReader = true });
|
||||
private readonly CancellationTokenSource _lifetime = new();
|
||||
private readonly List<IDisposable> _subscriptions = [];
|
||||
private readonly Dictionary<string, long> _requestOrders = new(StringComparer.Ordinal);
|
||||
private long _requestCounter;
|
||||
private Task? _worker;
|
||||
private volatile string? _mainFrameId;
|
||||
private long _responses;
|
||||
@@ -137,6 +140,7 @@ public sealed class ResponseTap : IAsyncDisposable
|
||||
throw new InvalidOperationException("La cattura è già avviata.");
|
||||
}
|
||||
|
||||
_subscriptions.Add(_cdp.On("Network.requestWillBeSent", OnRequestWillBeSent));
|
||||
_subscriptions.Add(_cdp.On("Network.responseReceived", OnResponseReceived));
|
||||
_subscriptions.Add(_cdp.On("Network.loadingFinished", OnLoadingFinished));
|
||||
_subscriptions.Add(_cdp.On("Network.loadingFailed", OnLoadingFailed));
|
||||
@@ -216,6 +220,51 @@ public sealed class ResponseTap : IAsyncDisposable
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The page starts a request: a site request gets its order (issue #37), kept until its response. Only the host
|
||||
/// kind of the address is looked at; nothing of the request is kept or logged.
|
||||
/// </summary>
|
||||
private void OnRequestWillBeSent(JsonElement p)
|
||||
{
|
||||
if (p.ValueKind != JsonValueKind.Object
|
||||
|| !p.TryGetProperty("requestId", out var idElement) || idElement.GetString() is not { } requestId
|
||||
|| !p.TryGetProperty("request", out var request) || request.ValueKind != JsonValueKind.Object)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var url = request.TryGetProperty("url", out var u) ? u.GetString() : null;
|
||||
if (_hosts.Classify(url) != HostKind.Site)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var order = Interlocked.Increment(ref _requestCounter);
|
||||
lock (_requestOrders)
|
||||
{
|
||||
if (_requestOrders.Count >= MaxRequestOrders)
|
||||
{
|
||||
// Requests whose response never came: their order is forgotten, and their answers count by arrival.
|
||||
_requestOrders.Clear();
|
||||
}
|
||||
|
||||
// A redirect starts the same request again: the later order holds.
|
||||
_requestOrders[requestId] = order;
|
||||
}
|
||||
|
||||
foreach (var observer in SnapshotObservers())
|
||||
{
|
||||
try
|
||||
{
|
||||
observer.OnRequestStarted(order);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_log.Warn("Cattura: errore in un osservatore delle richieste.", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnResponseReceived(JsonElement p)
|
||||
{
|
||||
if (p.ValueKind != JsonValueKind.Object || !p.TryGetProperty("requestId", out var idElement) || !p.TryGetProperty("response", out var response))
|
||||
@@ -245,7 +294,8 @@ public sealed class ResponseTap : IAsyncDisposable
|
||||
mime,
|
||||
type,
|
||||
isMainDocument,
|
||||
_clock.Now);
|
||||
_clock.Now,
|
||||
TakeRequestOrder(requestId));
|
||||
|
||||
Interlocked.Increment(ref _responses);
|
||||
foreach (var observer in SnapshotObservers())
|
||||
@@ -271,6 +321,14 @@ public sealed class ResponseTap : IAsyncDisposable
|
||||
}
|
||||
}
|
||||
|
||||
private long TakeRequestOrder(string requestId)
|
||||
{
|
||||
lock (_requestOrders)
|
||||
{
|
||||
return _requestOrders.Remove(requestId, out var order) ? order : 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnLoadingFinished(JsonElement p)
|
||||
{
|
||||
if (!p.TryGetProperty("requestId", out var idElement) || idElement.GetString() is not { } requestId)
|
||||
@@ -297,8 +355,13 @@ public sealed class ResponseTap : IAsyncDisposable
|
||||
|
||||
private void OnLoadingFailed(JsonElement p)
|
||||
{
|
||||
if (p.TryGetProperty("requestId", out var idElement) && idElement.GetString() is { } requestId
|
||||
&& _inFlight.TryRemove(requestId, out _))
|
||||
if (!p.TryGetProperty("requestId", out var idElement) || idElement.GetString() is not { } requestId)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
TakeRequestOrder(requestId);
|
||||
if (_inFlight.TryRemove(requestId, out _))
|
||||
{
|
||||
NotifyDropped(requestId, BodyDropReason.LoadingFailed);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user