microsoft/aspire · error · InvalidOperationException
Tracked browser protocol frame ended unexpectedly.
Error message
Tracked browser protocol frame ended unexpectedly.
What it means
While parsing a CDP frame header, the parser reads the value for each property name. If the JSON stream ends right after a property name (no value token follows), the frame is truncated and this InvalidOperationException is thrown. It indicates the tracked browser's frame ended mid-object.
Solutions
- Verify frame-length framing so only complete frames are handed to the parser
- Log the raw payload via DescribeFrame to confirm truncation
- Check browser process health - a crash can truncate the last frame
- Buffer and reassemble partial reads before parsing
- Catch the exception and re-establish the browser connection
Example fix
// before
var header = BrowserLogsCdpProtocol.ParseMessageHeader(partialBuffer);
// after
if (!frameReader.TryReadCompleteFrame(out var frame))
{
pendingBuffer = frame; // wait for more data
return;
}
var header = BrowserLogsCdpProtocol.ParseMessageHeader(frame); Defensive patterns
Strategy: validation
Validate before calling
// Only parse frames known to be complete per the framing protocol
if (!TryReadCompleteFrame(ref buffer, out var frame))
{
return; // wait for remainder
} Prevention
- Implement full frame-length reassembly before parsing
- Handle partial socket reads by buffering
- Monitor browser process liveness to detect crash-truncation
- Log truncated frames with DescribeFrame
When it happens
Trigger: ParseMessageHeader encounters a property name token but Utf8JsonReader.Read() returns false - i.e. the payload ends immediately after a key like {"id": or a final dangling key, typically a truncated or partial frame.
Common situations: Socket/stream read returned a partial frame, buffer boundary split a JSON object mid-key, the browser process crashed or was killed mid-write, or network disconnect during DevTools message delivery.
Understand the failure class
Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.
Related errors
- Tracked browser protocol event method was not a string.
- Tracked browser protocol frame was malformed.
- Tracked browser protocol response id was not an integer.
- Browser debug connection closed by the remote endpoint with…
- Chromium profile metadata in
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/c51a2e452fb5b1e3.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Browsers/BrowserLogsCdpProtocol.cs:89
string? method = null;
string? sessionId = null;
while (reader.Read())
{
if (reader.TokenType == JsonTokenType.EndObject)
{
break;
}
if (reader.TokenType != JsonTokenType.PropertyName)
{
throw new InvalidOperationException("Tracked browser protocol frame was malformed.");
}
var propertyName = reader.GetString();
if (!reader.Read())
{
throw new InvalidOperationException("Tracked browser protocol frame ended unexpectedly.");
}
switch (propertyName)
{
case "id":
if (!reader.TryGetInt64(out var parsedId))
{
throw new InvalidOperationException("Tracked browser protocol response id was not an integer.");
}
id = parsedId;
break;
case "method":
method = reader.TokenType == JsonTokenType.String
? reader.GetString()
: throw new InvalidOperationException("Tracked browser protocol event method was not a string.");
break;
case "sessionId":View on GitHub (pinned to 25830f84bd)