Skip to content

Commit 38ac350

Browse files
thaystgradical
andauthored
[wasm][debug]Press alt-shift-d and open firefox debug tab attached to the blazor app (#80722)
* press alt-shift-d and open tab to debug blazor app on firefox. * Update src/mono/wasm/debugger/BrowserDebugProxy/Firefox/FirefoxDebuggerProxy.cs Co-authored-by: Ankit Jain <[email protected]> * addressing @radical comments Co-authored-by: Ankit Jain <[email protected]>
1 parent 729f22c commit 38ac350

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

src/mono/wasm/debugger/BrowserDebugHost/DebugProxyHost.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static async Task RunDebugProxyAsync(ProxyOptions options, string[] args,
2424
{
2525
RunDevToolsProxyAsync(options, args, loggerFactory, token)
2626
};
27-
if (!options.RunningForBlazor)
27+
if (!options.RunningForBlazor || options.IsFirefoxDebugging)
2828
tasks.Add(RunFirefoxServerLoopAsync(options, args, loggerFactory, token));
2929

3030
Task completedTask = await Task.WhenAny(tasks);

src/mono/wasm/debugger/BrowserDebugProxy/Firefox/FirefoxDebuggerProxy.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55

66
using System;
77
using System.Diagnostics.CodeAnalysis;
8+
using System.Linq;
89
using System.Net;
10+
using System.Net.NetworkInformation;
911
using System.Net.Sockets;
1012
using System.Threading;
1113
using System.Threading.Tasks;
@@ -26,10 +28,17 @@ public static void StartListener(int proxyPort, ILogger logger, int browserPort
2628
{
2729
if (s_tcpListener is null)
2830
{
31+
// If there is an existing listener on @proxyPort, then use a new dynamic port.
32+
// Blazor always tries to open the same port (specified in @proxyPort) to avoid
33+
// creating a lot of remote debugging connections on firefox
34+
if (proxyPort != 0 && IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners().Any(x => x.Port == proxyPort))
35+
{
36+
proxyPort = 0;
37+
}
2938
s_tcpListener = new TcpListener(IPAddress.Parse("127.0.0.1"), proxyPort);
3039
s_tcpListener.Start();
3140
Console.WriteLine($"Debug proxy for firefox now listening on tcp://{s_tcpListener.LocalEndpoint}." +
32-
(browserPort >= 0 ? $" And expecting firefox at port {browserPort} ." : string.Empty));
41+
(browserPort >= 0 ? $" And expecting firefox at port {browserPort}." : string.Empty));
3342
}
3443
}
3544

src/mono/wasm/debugger/BrowserDebugProxy/ProxyOptions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ public int DevToolsDebugPort
2828
}
2929
public string? LogPath { get; set; }
3030
public bool RunningForBlazor { get; set; }
31+
public bool IsFirefoxDebugging { get; set; }
3132
}

0 commit comments

Comments
 (0)