Skip to content

Commit 09b5b4a

Browse files
jbomhold3pranavkm
authored andcommitted
Add MS Edge support for debugging
1 parent 65585c1 commit 09b5b4a

File tree

2 files changed

+49
-18
lines changed

2 files changed

+49
-18
lines changed

src/Components/Blazor/Server/src/MonoDebugProxy/BlazorMonoDebugProxyAppBuilderExtensions.cs

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.Diagnostics;
7+
using System.IO;
68
using System.Linq;
79
using System.Net;
810
using System.Net.Http;
@@ -89,19 +91,26 @@ private static async Task DebugHome(HttpContext context)
8991
}
9092
catch (Exception ex)
9193
{
92-
9394
await context.Response.WriteAsync($@"
94-
<h1>Unable to find debuggable browser tab</h1>
95-
<p>
96-
Could not get a list of browser tabs from <code>{debuggerTabsListUrl}</code>.
97-
Ensure Chrome is running with debugging enabled.
98-
</p>
99-
<h2>Resolution</h2>
95+
<h1>Unable to find debuggable browser tab</h1>
96+
<p>
97+
Could not get a list of browser tabs from <code>{debuggerTabsListUrl}</code>.
98+
Ensure your browser is running with debugging enabled.
99+
</p>
100+
<h2>Resolution</h2>
101+
<p>
102+
<h4>If you are using Google Chrome for your development, follow these instructions:</h4>
100103
{GetLaunchChromeInstructions(appRootUrl)}
101-
<p>... then use that new tab for debugging.</p>
102-
<h2>Underlying exception:</h2>
103-
<pre>{ex}</pre>
104-
");
104+
</p>
105+
<p>
106+
<h4>If you are using Microsoft Edge (Chromium) for your development, follow these instructions:</h4>
107+
{GetLaunchEdgeInstructions(appRootUrl)}
108+
</p>
109+
<strong>This should launch a new browser window with debugging enabled..</p>
110+
<h2>Underlying exception:</h2>
111+
<pre>{ex}</pre>
112+
");
113+
105114
return;
106115
}
107116

@@ -144,20 +153,42 @@ There is more than one browser tab at <code>{targetTabUrl}</code>.
144153

145154
private static string GetLaunchChromeInstructions(string appRootUrl)
146155
{
156+
var profilePath = Path.Combine(Path.GetTempPath(), "blazor-edge-debug");
157+
147158
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
148159
{
149-
return $@"<p>Close all Chrome instances, then press Win+R and enter the following:</p>
150-
<p><strong><code>""%programfiles(x86)%\Google\Chrome\Application\chrome.exe"" --remote-debugging-port=9222 {appRootUrl}</code></strong></p>";
160+
return $@"<p>Press Win+R and enter the following:</p>
161+
<p><strong><code>chrome --remote-debugging-port=9222 --user-data-dir=""{profilePath}"" {appRootUrl}</code></strong></p>";
151162
}
152163
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
153164
{
154-
return $@"<p>Close all Chrome instances, then in a terminal window execute the following:</p>
155-
<p><strong><code>google-chrome --remote-debugging-port=9222 {appRootUrl}</code></strong></p>";
165+
return $@"<p>In a terminal window execute the following:</p>
166+
<p><strong><code>google-chrome --remote-debugging-port=9222 --user-data-dir={profilePath} {appRootUrl}</code></strong></p>";
167+
}
168+
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
169+
{
170+
return $@"<p>Execute the following:</p>
171+
<p><strong><code>open /Applications/Google\ Chrome.app --args --remote-debugging-port=9222 --user-data-dir={profilePath} {appRootUrl}</code></strong></p>";
172+
}
173+
else
174+
{
175+
throw new InvalidOperationException("Unknown OS platform");
176+
}
177+
}
178+
179+
private static string GetLaunchEdgeInstructions(string appRootUrl)
180+
{
181+
var profilePath = Path.Combine(Path.GetTempPath(), "blazor-chrome-debug");
182+
183+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
184+
{
185+
return $@"<p>Press Win+R and enter the following:</p>
186+
<p><strong><code>msedge --remote-debugging-port=9222 --user-data-dir=""{profilePath}"" {appRootUrl}</code></strong></p>";
156187
}
157188
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
158189
{
159-
return $@"<p>Close all Chrome instances, then in a terminal window execute the following:</p>
160-
<p><strong><code>open /Applications/Google\ Chrome.app --args --remote-debugging-port=9222 {appRootUrl}</code></strong></p>";
190+
return $@"<p>In a terminal window execute the following:</p>
191+
<p><strong><code>open /Applications/Microsoft\ Edge\ Dev.app --args --remote-debugging-port=9222 --user-data-dir={profilePath} {appRootUrl}</code></strong></p>";
161192
}
162193
else
163194
{

src/Components/Web.JS/src/Platform/Mono/MonoDebugger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function attachDebuggerHotkey(loadAssemblyUrls: string[]) {
2626
if (!hasReferencedPdbs) {
2727
console.error('Cannot start debugging, because the application was not compiled with debugging enabled.');
2828
} else if (!currentBrowserIsChrome) {
29-
console.error('Currently, only Chrome is supported for debugging.');
29+
console.error('Currently, only Edge(Chromium) or Chrome is supported for debugging.');
3030
} else {
3131
launchDebugger();
3232
}

0 commit comments

Comments
 (0)