diff --git a/src/mono/wasm/debugger/BrowserDebugProxy/DevToolsProxy.cs b/src/mono/wasm/debugger/BrowserDebugProxy/DevToolsProxy.cs index a80470119b40f..0b5c83d8e8480 100644 --- a/src/mono/wasm/debugger/BrowserDebugProxy/DevToolsProxy.cs +++ b/src/mono/wasm/debugger/BrowserDebugProxy/DevToolsProxy.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net; using System.Net.WebSockets; using System.Text; using System.Threading; @@ -29,9 +30,11 @@ internal class DevToolsProxy public bool IsRunning => _runLoop?.IsRunning == true; public RunLoopExitState Stopped => _runLoop?.StoppedState; - public DevToolsProxy(ILogger logger, string loggerId) + protected readonly ProxyOptions _options; + public DevToolsProxy(ProxyOptions options, ILogger logger, string loggerId) { _loggerId = loggerId; + _options = options; this.logger = logger; } @@ -235,6 +238,9 @@ public async Task RunForDevTools(Uri browserUri, WebSocket ideSocket, Cancellati ClientWebSocket browserSocket = new(); browserSocket.Options.KeepAliveInterval = Timeout.InfiniteTimeSpan; + var proxy = WebRequest.DefaultWebProxy; + if (_options is not null && _options.IgnoreProxyForLocalAddress && proxy is not null && !proxy.IsBypassed(browserUri)) //only bypass the proxy for local addresses if it is not already an exception in the OS settings + browserSocket.Options.Proxy = new WebProxy(proxy.GetProxy(browserUri), true); await browserSocket.ConnectAsync(browserUri, cts.Token); using var ideConn = new DevToolsDebuggerConnection(ideSocket, "ide", logger); diff --git a/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs b/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs index c77f961fea9bd..a13b3910b50d9 100644 --- a/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs +++ b/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs @@ -34,13 +34,10 @@ internal class MonoProxy : DevToolsProxy public bool JustMyCode { get; private set; } private PauseOnExceptionsKind _defaultPauseOnExceptions { get; set; } - protected readonly ProxyOptions _options; - - public MonoProxy(ILogger logger, int runtimeId = 0, string loggerId = "", ProxyOptions options = null) : base(logger, loggerId) + public MonoProxy(ILogger logger, int runtimeId = 0, string loggerId = "", ProxyOptions options = null) : base(options, logger, loggerId) { UrlSymbolServerList = new List(); RuntimeId = runtimeId; - _options = options; _defaultPauseOnExceptions = PauseOnExceptionsKind.Unset; JustMyCode = options?.JustMyCode ?? false; } diff --git a/src/mono/wasm/debugger/BrowserDebugProxy/ProxyOptions.cs b/src/mono/wasm/debugger/BrowserDebugProxy/ProxyOptions.cs index 140958f738292..665d2e71d500c 100644 --- a/src/mono/wasm/debugger/BrowserDebugProxy/ProxyOptions.cs +++ b/src/mono/wasm/debugger/BrowserDebugProxy/ProxyOptions.cs @@ -28,6 +28,7 @@ public int DevToolsDebugPort } public string? LogPath { get; set; } public bool RunningForBlazor { get; set; } + public bool IgnoreProxyForLocalAddress { get; set; } public bool IsFirefoxDebugging { get; set; } public bool JustMyCode { get; set; } }