Skip to content

Commit cc482bd

Browse files
committed
fix: route CDP responses by callback id when sessionId missing (upstream #14975)
Chrome can occasionally respond without a sessionId. Before this fix the response was dropped because the message id did not exist in the connection-level callbacks. Now we fall back to scanning per-session callbacks so the response reaches the session that issued the command. Upstream: puppeteer/puppeteer#14975
1 parent 8e11f0b commit cc482bd

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

lib/PuppeteerSharp/Cdp/CdpCDPSession.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ public override void Close(string closeReason)
144144

145145
internal bool HasPendingCallbacks() => !_callbacks.IsEmpty;
146146

147+
internal bool HasCallback(int id) => _callbacks.ContainsKey(id);
148+
147149
internal List<string> GetPendingProtocolErrors()
148150
{
149151
var result = new List<string>();

lib/PuppeteerSharp/Cdp/Connection.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,20 @@ private void ProcessIncomingMessage(ConnectionResponse obj)
368368
{
369369
MessageQueue.Enqueue(callback, obj);
370370
}
371+
else
372+
{
373+
// Chrome can occasionally omit the sessionId on responses. Fall back
374+
// to a per-session callback lookup so the response is routed to the
375+
// session that originally issued the command (upstream #14975).
376+
foreach (var session in _sessions.Values)
377+
{
378+
if (session.HasCallback(obj.Id.Value))
379+
{
380+
session.OnMessage(obj);
381+
break;
382+
}
383+
}
384+
}
371385
}
372386
else
373387
{

0 commit comments

Comments
 (0)