Skip to content

Commit

Permalink
[wasm][debug]Press alt-shift-d and open firefox debug tab attached to…
Browse files Browse the repository at this point in the history
… the blazor app (dotnet#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 <radical@gmail.com>

* addressing @radical comments

Co-authored-by: Ankit Jain <radical@gmail.com>
  • Loading branch information
2 people authored and mdh1418 committed Jan 24, 2023
1 parent 434d4f1 commit 781f524
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/mono/wasm/debugger/BrowserDebugHost/DebugProxyHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static async Task RunDebugProxyAsync(ProxyOptions options, string[] args,
{
RunDevToolsProxyAsync(options, args, loggerFactory, token)
};
if (!options.RunningForBlazor)
if (!options.RunningForBlazor || options.IsFirefoxDebugging)
tasks.Add(RunFirefoxServerLoopAsync(options, args, loggerFactory, token));

Task completedTask = await Task.WhenAny(tasks);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -26,10 +28,17 @@ public static void StartListener(int proxyPort, ILogger logger, int browserPort
{
if (s_tcpListener is null)
{
// If there is an existing listener on @proxyPort, then use a new dynamic port.
// Blazor always tries to open the same port (specified in @proxyPort) to avoid
// creating a lot of remote debugging connections on firefox
if (proxyPort != 0 && IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners().Any(x => x.Port == proxyPort))
{
proxyPort = 0;
}
s_tcpListener = new TcpListener(IPAddress.Parse("127.0.0.1"), proxyPort);
s_tcpListener.Start();
Console.WriteLine($"Debug proxy for firefox now listening on tcp://{s_tcpListener.LocalEndpoint}." +
(browserPort >= 0 ? $" And expecting firefox at port {browserPort} ." : string.Empty));
(browserPort >= 0 ? $" And expecting firefox at port {browserPort}." : string.Empty));
}
}

Expand Down
1 change: 1 addition & 0 deletions src/mono/wasm/debugger/BrowserDebugProxy/ProxyOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ public int DevToolsDebugPort
}
public string? LogPath { get; set; }
public bool RunningForBlazor { get; set; }
public bool IsFirefoxDebugging { get; set; }
}

0 comments on commit 781f524

Please sign in to comment.