Skip to content

Commit 302d79a

Browse files
committed
Initial working end-to-end
1 parent 691910c commit 302d79a

File tree

6 files changed

+35
-25
lines changed

6 files changed

+35
-25
lines changed

eng/Version.Details.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,9 @@
306306
<Uri>https://github.com/dotnet/runtime</Uri>
307307
<Sha>1dfd9438149f74ae11918a7b0709b8d58c61443f</Sha>
308308
</Dependency>
309-
<Dependency Name="Microsoft.NETCore.BrowserDebugHost.Transport" Version="5.0.0-rc.1.20414.5">
309+
<Dependency Name="Microsoft.NETCore.BrowserDebugHost.Transport" Version="5.0.0-rc.1.20428.3">
310310
<Uri>https://github.com/dotnet/runtime</Uri>
311-
<Sha>6cc7cffaff2e0413ee84d9a7736f9ae1aa9a3f12</Sha>
311+
<Sha>1dfd9438149f74ae11918a7b0709b8d58c61443f</Sha>
312312
</Dependency>
313313
</ProductDependencies>
314314
<ToolsetDependencies>

eng/Versions.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
<MicrosoftNETCoreAppInternalPackageVersion>5.0.0-rc.1.20428.3</MicrosoftNETCoreAppInternalPackageVersion>
6969
<MicrosoftNETCoreAppRefPackageVersion>5.0.0-rc.1.20428.3</MicrosoftNETCoreAppRefPackageVersion>
7070
<MicrosoftNETCoreAppRuntimewinx64PackageVersion>5.0.0-rc.1.20428.3</MicrosoftNETCoreAppRuntimewinx64PackageVersion>
71+
<MicrosoftNETCoreBrowserDebugHostTransportPackageVersion>5.0.0-rc.1.20428.3</MicrosoftNETCoreBrowserDebugHostTransportPackageVersion>
7172
<MicrosoftWin32RegistryPackageVersion>5.0.0-rc.1.20428.3</MicrosoftWin32RegistryPackageVersion>
7273
<MicrosoftWin32SystemEventsPackageVersion>5.0.0-rc.1.20428.3</MicrosoftWin32SystemEventsPackageVersion>
7374
<MicrosoftExtensionsCachingAbstractionsPackageVersion>5.0.0-rc.1.20428.3</MicrosoftExtensionsCachingAbstractionsPackageVersion>

src/Components/WebAssembly/Server/src/DebugProxyLauncher.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
using System.Text.RegularExpressions;
1111
using System.Threading;
1212
using System.Threading.Tasks;
13+
using System.Web;
1314
using Microsoft.AspNetCore.Hosting;
15+
using Microsoft.AspNetCore.Http;
1416
using Microsoft.Extensions.CommandLineUtils;
1517
using Microsoft.Extensions.DependencyInjection;
1618

@@ -24,31 +26,32 @@ internal static class DebugProxyLauncher
2426
private static readonly Regex NowListeningRegex = new Regex(@"^\s*Now listening on: (?<url>.*)$", RegexOptions.None, TimeSpan.FromSeconds(10));
2527
private static readonly Regex ApplicationStartedRegex = new Regex(@"^\s*Application started\. Press Ctrl\+C to shut down\.$", RegexOptions.None, TimeSpan.FromSeconds(10));
2628

27-
public static Task<string> EnsureLaunchedAndGetUrl(IServiceProvider serviceProvider)
29+
public static Task<string> EnsureLaunchedAndGetUrl(IServiceProvider serviceProvider, string devToolsHost)
2830
{
2931
lock (LaunchLock)
3032
{
3133
if (LaunchedDebugProxyUrl == null)
3234
{
33-
LaunchedDebugProxyUrl = LaunchAndGetUrl(serviceProvider);
35+
LaunchedDebugProxyUrl = LaunchAndGetUrl(serviceProvider, devToolsHost);
3436
}
3537

3638
return LaunchedDebugProxyUrl;
3739
}
3840
}
3941

40-
private static async Task<string> LaunchAndGetUrl(IServiceProvider serviceProvider)
42+
private static async Task<string> LaunchAndGetUrl(IServiceProvider serviceProvider, string devToolsHost)
4143
{
4244
var tcs = new TaskCompletionSource<string>();
4345

4446
var environment = serviceProvider.GetRequiredService<IWebHostEnvironment>();
4547
var executablePath = LocateDebugProxyExecutable(environment);
4648
var muxerPath = DotNetMuxer.MuxerPathOrDefault();
4749
var ownerPid = Process.GetCurrentProcess().Id;
50+
4851
var processStartInfo = new ProcessStartInfo
4952
{
5053
FileName = muxerPath,
51-
Arguments = $"exec \"{executablePath}\"",
54+
Arguments = $"exec \"{executablePath}\" --owner-pid {ownerPid} --DevToolsUrl {devToolsHost}",
5255
UseShellExecute = false,
5356
RedirectStandardOutput = true,
5457
};

src/Components/WebAssembly/Server/src/Microsoft.AspNetCore.Components.WebAssembly.Server.csproj

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212

1313
<ItemGroup>
1414
<Reference Include="Microsoft.AspNetCore.StaticFiles" />
15-
<Reference Include="Microsoft.NETCore.BrowserDebugHost.Transport" GeneratePathProperty="true"/>
16-
<!-- Dependencies needed by DebugProxy. -->
17-
<Reference Include= "Newtonsoft.Json" />
15+
<Reference Include="Microsoft.NETCore.BrowserDebugHost.Transport" GeneratePathProperty="true" />
1816
</ItemGroup>
1917

2018
<ItemGroup>
@@ -32,12 +30,7 @@
3230
<Target Name="IncludeDebugProxyBinariesAsContent" BeforeTargets="AssignTargetPaths">
3331
<ItemGroup>
3432
<DebugProxyBinaries Include="$(PkgMicrosoft_NETCore_BrowserDebugHost_Transport)\tools\$(DefaultNetCoreTargetFramework)\**" />
35-
<Content
36-
Include="@(DebugProxyBinaries)"
37-
Pack="true"
38-
PackagePath="tools\BlazorDebugProxy\%(RecursiveDir)%(FileName)%(Extension)"
39-
Link="BlazorDebugProxy\%(RecursiveDir)%(FileName)%(Extension)"
40-
CopyToOutputDirectory="PreserveNewest" />
33+
<Content Include="@(DebugProxyBinaries)" Pack="true" PackagePath="tools\BlazorDebugProxy\%(RecursiveDir)%(FileName)%(Extension)" Link="BlazorDebugProxy\%(RecursiveDir)%(FileName)%(Extension)" CopyToOutputDirectory="PreserveNewest" />
4134
</ItemGroup>
4235
</Target>
4336

src/Components/WebAssembly/Server/src/TargetPickerUi.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ public class TargetPickerUi
2323
IgnoreNullValues = true
2424
};
2525

26-
private readonly string BrowserHost = "http://localhost:9222";
26+
private string _browserHost;
2727
private string _debugProxyUrl;
2828

29-
public TargetPickerUi(string debugProxyUrl)
29+
public TargetPickerUi(string debugProxyUrl, string devToolsHost)
3030
{
3131
_debugProxyUrl = debugProxyUrl;
32+
_browserHost = devToolsHost;
3233
}
3334

3435
public async Task Display(HttpContext context)
@@ -38,7 +39,7 @@ public async Task Display(HttpContext context)
3839
var request = context.Request;
3940
var targetApplicationUrl = request.Query["url"];
4041

41-
var debuggerTabsListUrl = $"{BrowserHost}/json";
42+
var debuggerTabsListUrl = $"{_browserHost}/json";
4243
IEnumerable<BrowserTab> availableTabs;
4344

4445
try
@@ -137,15 +138,15 @@ private string GetDevToolsUrlWithProxy(HttpRequest request, BrowserTab tabToDebu
137138
{
138139
var underlyingV8Endpoint = new Uri(tabToDebug.WebSocketDebuggerUrl);
139140
var proxyEndpoint = new Uri(_debugProxyUrl);
140-
var devToolsUrlAbsolute = new Uri(BrowserHost + tabToDebug.DevtoolsFrontendUrl);
141+
var devToolsUrlAbsolute = new Uri(_browserHost + tabToDebug.DevtoolsFrontendUrl);
141142
var devToolsUrlWithProxy = $"{devToolsUrlAbsolute.Scheme}://{devToolsUrlAbsolute.Authority}{devToolsUrlAbsolute.AbsolutePath}?{underlyingV8Endpoint.Scheme}={proxyEndpoint.Authority}{underlyingV8Endpoint.PathAndQuery}";
142143
return devToolsUrlWithProxy;
143144
}
144145

145146
private string GetLaunchChromeInstructions(string targetApplicationUrl)
146147
{
147148
var profilePath = Path.Combine(Path.GetTempPath(), "blazor-chrome-debug");
148-
var debuggerPort = new Uri(BrowserHost).Port;
149+
var debuggerPort = new Uri(_browserHost).Port;
149150

150151
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
151152
{
@@ -171,7 +172,7 @@ private string GetLaunchChromeInstructions(string targetApplicationUrl)
171172
private string GetLaunchEdgeInstructions(string targetApplicationUrl)
172173
{
173174
var profilePath = Path.Combine(Path.GetTempPath(), "blazor-edge-debug");
174-
var debuggerPort = new Uri(BrowserHost).Port;
175+
var debuggerPort = new Uri(_browserHost).Port;
175176

176177
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
177178
{
@@ -210,7 +211,7 @@ private static Uri GetProxyEndpoint(HttpRequest incomingRequest, string browserE
210211
private async Task<IEnumerable<BrowserTab>> GetOpenedBrowserTabs()
211212
{
212213
using var httpClient = new HttpClient { Timeout = TimeSpan.FromSeconds(5) };
213-
var jsonResponse = await httpClient.GetStringAsync($"{BrowserHost}/json");
214+
var jsonResponse = await httpClient.GetStringAsync($"{_browserHost}/json");
214215
return JsonSerializer.Deserialize<BrowserTab[]>(jsonResponse, JsonOptions);
215216
}
216217

src/Components/WebAssembly/Server/src/WebAssemblyNetDebugProxyAppBuilderExtensions.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using System;
45
using System.Net;
6+
using System.Web;
57
using Microsoft.AspNetCore.Components.WebAssembly.Server;
68

79
namespace Microsoft.AspNetCore.Builder
@@ -21,7 +23,17 @@ public static void UseWebAssemblyDebugging(this IApplicationBuilder app)
2123
{
2224
app.Use(async (context, next) =>
2325
{
24-
var debugProxyBaseUrl = await DebugProxyLauncher.EnsureLaunchedAndGetUrl(context.RequestServices);
26+
var queryParams = HttpUtility.ParseQueryString(context.Request.QueryString.Value);
27+
var browserParam = queryParams.Get("browser");
28+
Uri browserUrl = null;
29+
var devToolsHost = "http://localhost:9222";
30+
if (browserParam != null)
31+
{
32+
browserUrl = new Uri(browserParam);
33+
devToolsHost = $"http://{browserUrl.Host}:{browserUrl.Port}";
34+
}
35+
36+
var debugProxyBaseUrl = await DebugProxyLauncher.EnsureLaunchedAndGetUrl(context.RequestServices, devToolsHost);
2537
var requestPath = context.Request.Path.ToString();
2638
if (requestPath == string.Empty)
2739
{
@@ -31,11 +43,11 @@ public static void UseWebAssemblyDebugging(this IApplicationBuilder app)
3143
switch (requestPath)
3244
{
3345
case "/":
34-
var targetPickerUi = new TargetPickerUi(debugProxyBaseUrl);
46+
var targetPickerUi = new TargetPickerUi(debugProxyBaseUrl, devToolsHost);
3547
await targetPickerUi.Display(context);
3648
break;
3749
case "/ws-proxy":
38-
context.Response.Redirect($"{debugProxyBaseUrl}{requestPath}{context.Request.QueryString}");
50+
context.Response.Redirect($"{debugProxyBaseUrl}{browserUrl.PathAndQuery}");
3951
break;
4052
default:
4153
context.Response.StatusCode = (int)HttpStatusCode.NotFound;

0 commit comments

Comments
 (0)