From 28c0d2c1ff15ea8f8dbbe5b114fea5f89a9ac72f Mon Sep 17 00:00:00 2001 From: Safia Abdalla Date: Mon, 21 Sep 2020 23:31:34 +0000 Subject: [PATCH] Add support for associating BrowserDebugHost with parent process (#42541) --- src/mono/wasm/debugger/BrowserDebugHost/Program.cs | 2 ++ src/mono/wasm/debugger/BrowserDebugHost/Startup.cs | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/mono/wasm/debugger/BrowserDebugHost/Program.cs b/src/mono/wasm/debugger/BrowserDebugHost/Program.cs index c203cd0..6c4a79d 100644 --- a/src/mono/wasm/debugger/BrowserDebugHost/Program.cs +++ b/src/mono/wasm/debugger/BrowserDebugHost/Program.cs @@ -16,6 +16,8 @@ namespace Microsoft.WebAssembly.Diagnostics public class ProxyOptions { public Uri DevToolsUrl { get; set; } = new Uri("http://localhost:9222"); + + public int? OwnerPid { get; set; } } public class Program diff --git a/src/mono/wasm/debugger/BrowserDebugHost/Startup.cs b/src/mono/wasm/debugger/BrowserDebugHost/Startup.cs index 01974d8..70ce455 100644 --- a/src/mono/wasm/debugger/BrowserDebugHost/Startup.cs +++ b/src/mono/wasm/debugger/BrowserDebugHost/Startup.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Net.Http; using System.Text.Json; @@ -13,6 +14,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Microsoft.Extensions.Primitives; @@ -33,9 +35,23 @@ namespace Microsoft.WebAssembly.Diagnostics public IConfiguration Configuration { get; } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IOptionsMonitor optionsAccessor, IWebHostEnvironment env) + public void Configure(IApplicationBuilder app, IOptionsMonitor optionsAccessor, IWebHostEnvironment env, IHostApplicationLifetime applicationLifetime) { ProxyOptions options = optionsAccessor.CurrentValue; + + if (options.OwnerPid.HasValue) + { + Process ownerProcess = Process.GetProcessById(options.OwnerPid.Value); + if (ownerProcess != null) + { + ownerProcess.EnableRaisingEvents = true; + ownerProcess.Exited += (sender, eventArgs) => + { + applicationLifetime.StopApplication(); + }; + } + } + app.UseDeveloperExceptionPage() .UseWebSockets() .UseDebugProxy(options); -- 2.7.4