Skip to content

Commit f0a43e8

Browse files
authored
[Blazor] Fixed devtools url used for debug with chrome and edge (#61813)
* Fixed devtools url used for debug with newer versions of chrome and edge Fixes #61559
1 parent debb78a commit f0a43e8

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using System.Text.Json;
1111
using System.Text.Json.Serialization;
1212
using Microsoft.AspNetCore.Http;
13+
using Microsoft.AspNetCore.Http.Extensions;
1314
using System.Dynamic;
1415

1516
namespace Microsoft.AspNetCore.Components.WebAssembly.Server;
@@ -366,9 +367,31 @@ private string GetDevToolsUrlWithProxy(BrowserTab tabToDebug)
366367
{
367368
var underlyingV8Endpoint = new Uri(tabToDebug.WebSocketDebuggerUrl);
368369
var proxyEndpoint = new Uri(_debugProxyUrl);
369-
var devToolsUrlAbsolute = new Uri(_browserHost + tabToDebug.DevtoolsFrontendUrl);
370+
var devToolsUrlAbsolute = new Uri(new Uri(_browserHost), relativeUri: NormalizeDevtoolsFrontendUrl(tabToDebug.DevtoolsFrontendUrl));
370371
var devToolsUrlWithProxy = $"{devToolsUrlAbsolute.Scheme}://{devToolsUrlAbsolute.Authority}{devToolsUrlAbsolute.AbsolutePath}?{underlyingV8Endpoint.Scheme}={proxyEndpoint.Authority}{underlyingV8Endpoint.PathAndQuery}";
371372
return devToolsUrlWithProxy;
373+
374+
static string NormalizeDevtoolsFrontendUrl(string devtoolsFrontendUrl)
375+
{
376+
// Currently frontend url can be:
377+
// - absolute (since v135 of chrome and edge)
378+
// chrome example: https://chrome-devtools-frontend.appspot.com/serve_rev/@031848bc6ad02b97854f3d6154d3aefd0434756a/inspector.html?ws=localhost:9222/devtools/page/719FE9D3B43570193235446E0AB36859
379+
// edge example: https://aka.ms/docs-landing-page/serve_rev/@4e2c41645f24197463afa2ab6aa999352ee8255c/inspector.html?ws=localhost:9222/devtools/page/3A4D56E09776321628432588FC9299F4
380+
// - relative (managed as fallback for brosers with prior version)
381+
// example: /devtools/inspector.html?ws=localhost:9222/devtools/page/DAB7FB6187B554E10B0BD18821265734
382+
// The absolute url can't be used as-is because is not valid for debugging and cannot be made relative because of lack "devtools" segment
383+
// before "inspector.html" but we can keep the query string and append to the default "devtools/inspector.html" browser devtools page
384+
385+
const string DefaultBrowserDevToolsPagePath = "devtools/inspector.html";
386+
387+
if (devtoolsFrontendUrl.AsSpan().TrimStart('/').StartsWith(DefaultBrowserDevToolsPagePath))
388+
{
389+
return devtoolsFrontendUrl;
390+
}
391+
392+
UriHelper.FromAbsolute(devtoolsFrontendUrl, out _, out _, out _, out var query, out _);
393+
return $"{DefaultBrowserDevToolsPagePath}{query}";
394+
}
372395
}
373396

374397
private string GetLaunchChromeInstructions(string targetApplicationUrl)

0 commit comments

Comments
 (0)