diff --git a/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs b/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs index 95aa6dedcd0069..1f8c498cad9018 100644 --- a/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs +++ b/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs @@ -126,7 +126,11 @@ protected override async Task AcceptEvent(SessionId sessionId, string meth case "Runtime.exceptionThrown": { - if (!GetContext(sessionId).IsRuntimeReady) + // Don't process events from sessions we aren't tracking + if (!contexts.TryGetValue(sessionId, out ExecutionContext context)) + return false; + + if (!context.IsRuntimeReady) { string exceptionError = args?["exceptionDetails"]?["exception"]?["value"]?.Value(); if (exceptionError == sPauseOnUncaught || exceptionError == sPauseOnCaught) @@ -139,7 +143,11 @@ protected override async Task AcceptEvent(SessionId sessionId, string meth case "Debugger.paused": { - if (!GetContext(sessionId).IsRuntimeReady) + // Don't process events from sessions we aren't tracking + if (!contexts.TryGetValue(sessionId, out ExecutionContext context)) + return false; + + if (!context.IsRuntimeReady) { string reason = args?["reason"]?.Value(); if (reason == "exception") @@ -148,13 +156,13 @@ protected override async Task AcceptEvent(SessionId sessionId, string meth if (exceptionError == sPauseOnUncaught) { await SendCommand(sessionId, "Debugger.resume", new JObject(), token); - GetContext(sessionId).PauseOnUncaught = true; + context.PauseOnUncaught = true; return true; } if (exceptionError == sPauseOnCaught) { await SendCommand(sessionId, "Debugger.resume", new JObject(), token); - GetContext(sessionId).PauseOnCaught = true; + context.PauseOnCaught = true; return true; } }