Skip to content

Commit 2c349af

Browse files
authored
[browser] Update wasmbrowser template (#116690)
1 parent 41aa5d5 commit 2c349af

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/mono/wasm/host/DevServer/WebAssemblyNetDebugProxyAppBuilderExtensions.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using System.Web;
1919
using Microsoft.AspNetCore.Builder;
2020
using Microsoft.AspNetCore.Http;
21+
using Microsoft.AspNetCore.Http.Extensions;
2122

2223
namespace Microsoft.WebAssembly.AppHost.DevServer;
2324

@@ -428,9 +429,31 @@ private string GetDevToolsUrlWithProxy(BrowserTab tabToDebug)
428429
{
429430
var underlyingV8Endpoint = new Uri(tabToDebug.WebSocketDebuggerUrl);
430431
var proxyEndpoint = new Uri(_debugProxyUrl);
431-
var devToolsUrlAbsolute = new Uri(_browserHost + tabToDebug.DevtoolsFrontendUrl);
432+
var devToolsUrlAbsolute = new Uri(new Uri(_browserHost), relativeUri: NormalizeDevtoolsFrontendUrl(tabToDebug.DevtoolsFrontendUrl));
432433
var devToolsUrlWithProxy = $"{devToolsUrlAbsolute.Scheme}://{devToolsUrlAbsolute.Authority}{devToolsUrlAbsolute.AbsolutePath}?{underlyingV8Endpoint.Scheme}={proxyEndpoint.Authority}{underlyingV8Endpoint.PathAndQuery}";
433434
return devToolsUrlWithProxy;
435+
436+
static string NormalizeDevtoolsFrontendUrl(string devtoolsFrontendUrl)
437+
{
438+
// Currently frontend url can be:
439+
// - absolute (since v135 of chrome and edge)
440+
// chrome example: https://chrome-devtools-frontend.appspot.com/serve_rev/@031848bc6ad02b97854f3d6154d3aefd0434756a/inspector.html?ws=localhost:9222/devtools/page/719FE9D3B43570193235446E0AB36859
441+
// edge example: https://aka.ms/docs-landing-page/serve_rev/@4e2c41645f24197463afa2ab6aa999352ee8255c/inspector.html?ws=localhost:9222/devtools/page/3A4D56E09776321628432588FC9299F4
442+
// - relative (managed as fallback for brosers with prior version)
443+
// example: /devtools/inspector.html?ws=localhost:9222/devtools/page/DAB7FB6187B554E10B0BD18821265734
444+
// 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
445+
// before "inspector.html" but we can keep the query string and append to the default "devtools/inspector.html" browser devtools page
446+
447+
const string DefaultBrowserDevToolsPagePath = "devtools/inspector.html";
448+
449+
if (devtoolsFrontendUrl.AsSpan().TrimStart('/').StartsWith(DefaultBrowserDevToolsPagePath))
450+
{
451+
return devtoolsFrontendUrl;
452+
}
453+
454+
UriHelper.FromAbsolute(devtoolsFrontendUrl, out _, out _, out _, out var query, out _);
455+
return $"{DefaultBrowserDevToolsPagePath}{query}";
456+
}
434457
}
435458

436459
private string GetLaunchChromeInstructions(string targetApplicationUrl)

src/mono/wasm/templates/templates/browser/browser.0.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@
44
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
55
<OverrideHtmlAssetPlaceholders>true</OverrideHtmlAssetPlaceholders>
66
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<StaticWebAssetFingerprintPattern Include="JS" Pattern="*.js" />
10+
</ItemGroup>
711
</Project>

0 commit comments

Comments
 (0)