{"record":{"id":"cae0ee8f218989d1","repo":"microsoft/aspire","slug":"tracked-browser-protocol-event-method-was-not-a-string","errorCode":null,"errorMessage":"Tracked browser protocol event method was not a string.","messagePattern":"Tracked browser protocol event method was not a string\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Browsers/BrowserLogsCdpProtocol.cs","lineNumber":105,"sourceCode":"            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;\n                case \"method\":\n                    method = reader.TokenType == JsonTokenType.String\n                        ? reader.GetString()\n                        : throw new InvalidOperationException(\"Tracked browser protocol event method was not a string.\");\n                    break;\n                case \"sessionId\":\n                    sessionId = reader.TokenType == JsonTokenType.String\n                        ? reader.GetString()\n                        : null;\n                    break;\n                default:\n                    reader.Skip();\n                    break;\n            }\n        }\n\n        return new BrowserLogsCdpProtocolMessageHeader(id, method, sessionId);\n    }\n\n    internal static byte[] CreateCommandFrame(long id, string method, string? sessionId, Action<Utf8JsonWriter>? writeParameters)\n    {\n        var buffer = new ArrayBufferWriter<byte>();","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Browsers/BrowserLogsCdpProtocol.cs#L87-L123","documentation":"In a CDP event frame, the \"method\" property must be a string naming the event (e.g. \"Log.entryAdded\"). If the \"method\" property is present but its value is not a JSON string, ParseMessageHeader throws this InvalidOperationException. Note \"sessionId\" tolerates non-strings (treated as null), but \"method\" is strict because the method name drives event dispatch.","triggerScenarios":"ParseMessageHeader reads property name \"method\" and finds TokenType is not JsonTokenType.String - e.g. \"method\": 42, null, or an object.","commonSituations":"A non-Chromium automation endpoint or mocking tool emits malformed CDP events, a proxy mangles the frame, or a hand-crafted test payload has the wrong value type.","solutions":["Inspect the offending frame with DescribeFrame","Confirm the browser endpoint is real Chromium CDP, not a custom/mock server","Fix test fixtures or mocks to emit \"method\" as a JSON string","Wrap parsing in try-catch and skip malformed frames"],"exampleFix":"// before\nvar header = BrowserLogsCdpProtocol.ParseMessageHeader(frame); // frame: {\"method\":123}\n// after\n// fix the emitting side (mock/fixture):\nvar json = \"\"\"{\"method\":\"Log.entryAdded\"}\"\"\"; // method must be a string","handlingStrategy":"validation","validationCode":"// ensure fixtures/mocks emit \"method\" as a JSON string\nvar valid = rawFrame.Contains(\"\\\"method\\\":\\\"\"); // quick sanity check for test payloads","typeGuard":null,"tryCatchPattern":"try\n{\n    var header = BrowserLogsCdpProtocol.ParseMessageHeader(frame);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"method was not a string\"))\n{\n    logger.LogWarning(\"CDP event with non-string method skipped: {Frame}\", BrowserLogsCdpProtocol.DescribeFrame(frame));\n}","preventionTips":["Emit \"method\" as a JSON string in mocks/fixtures","Connect only to genuine Chromium DevTools endpoints","Skip-and-log malformed frames instead of failing the log-tracking session"],"tags":["cdp","browser","type-mismatch","json"],"backgroundTag":"type-mismatch","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"}