{"record":{"id":"0aaccb02f535b2ec","repo":"microsoft/aspire","slug":"tracked-browser-protocol-frame-was-malformed","errorCode":null,"errorMessage":"Tracked browser protocol frame was malformed.","messagePattern":"Tracked browser protocol frame was malformed\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Browsers/BrowserLogsCdpProtocol.cs","lineNumber":83,"sourceCode":"        if (!reader.Read() || reader.TokenType != JsonTokenType.StartObject)\n        {\n            throw new InvalidOperationException(\"Tracked browser protocol frame was not a JSON object.\");\n        }\n\n        long? id = null;\n        string? method = null;\n        string? sessionId = null;\n\n        while (reader.Read())\n        {\n            if (reader.TokenType == JsonTokenType.EndObject)\n            {\n                break;\n            }\n\n            if (reader.TokenType != JsonTokenType.PropertyName)\n            {\n                throw new InvalidOperationException(\"Tracked browser protocol frame was malformed.\");\n            }\n\n            var propertyName = reader.GetString();\n            if (!reader.Read())\n            {\n                throw new InvalidOperationException(\"Tracked browser protocol frame ended unexpectedly.\");\n            }\n\n            switch (propertyName)\n            {\n                case \"id\":\n                    if (!reader.TryGetInt64(out var parsedId))\n                    {\n                        throw new InvalidOperationException(\"Tracked browser protocol response id was not an integer.\");\n                    }\n\n                    id = parsedId;\n                    break;","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Browsers/BrowserLogsCdpProtocol.cs#L65-L101","documentation":"This library tracks browser (Chrome DevTools Protocol) traffic and parses each CDP frame's header with a Utf8JsonReader. After parsing an opening '{', it expects an object property name; anything else (a bare value, array, invalid structure) means the frame is not a valid CDP message object, so this InvalidOperationException is thrown. It signals the tracked browser sent a frame the parser cannot interpret.","triggerScenarios":"ParseMessageHeader receives a frame payload whose JSON is not an object with property names at the expected position - e.g. a JSON array, a bare scalar like \"hello\" or 42, or a malformed/desynchronized stream where the reader lands on a non-PropertyName token.","commonSituations":"The browser or proxy sends a non-CDP message over the socket (e.g. an HTML error page, a plain text keepalive), a custom Chrome/Edge channel or headless shell emits an unexpected framing, or the frame framing layer mis-splits boundaries so partial/garbled JSON reaches the parser.","solutions":["Log the raw frame with DescribeFrame to inspect what was actually received","Verify the browser binary/version is a standard Chromium build supporting CDP over the expected transport","Check for proxies or wrappers intercepting the browser DevTools websocket/stream","Ensure frame boundaries are read correctly before calling ParseMessageHeader (no partial frames)","Catch InvalidOperationException around frame parsing and skip/reconnect to the browser"],"exampleFix":"// before\nvar header = BrowserLogsCdpProtocol.ParseMessageHeader(frame);\n// after\nBrowserLogsCdpMessageHeader? header;\ntry\n{\n    header = BrowserLogsCdpProtocol.ParseMessageHeader(frame);\n}\ncatch (InvalidOperationException ex)\n{\n    logger.LogWarning(ex, \"Skipping malformed browser protocol frame\");\n    return;\n}","handlingStrategy":"try-catch","validationCode":"if (framePayload.IsEmpty || framePayload[0] != (byte)'{')\n{\n    logger.LogWarning(\"Skipping non-object browser frame: {Frame}\", BrowserLogsCdpProtocol.DescribeFrame(framePayload));\n    return;\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    var header = BrowserLogsCdpProtocol.ParseMessageHeader(frame);\n}\ncatch (InvalidOperationException ex)\n{\n    logger.LogWarning(ex, \"Malformed CDP frame skipped\");\n}","preventionTips":["Use a standard Chromium-based browser binary","Validate frame starts with '{' before parsing","Log raw frames via DescribeFrame when debugging","Keep frame framing (length-prefix) logic in sync with the wire format"],"tags":["cdp","browser","json","protocol-parsing"],"backgroundTag":"unexpected-response-shape","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}