BrowserWindow SetProxyAsync sets proxy for all new windows #475

Open
opened 2026-01-29 16:40:45 +00:00 by claunia · 0 comments
Owner

Originally created by @thomvandevin on GitHub (May 6, 2020).

Originally assigned to: @GregorBiswanger on GitHub.

  • Version: 8.31.1 (and earlier)
  • Target: .NET Core 3.1 & nodejs v12.16.2

Steps to Reproduce:
I spawn a browserwindow like this:

public static async AsyncTask OpenCaptchaWindow(string hostUrl, string hostSitekey) {
    BrowserWindowOptions captchaWindowOptions = new BrowserWindowOptions {
        Show = false,
        Title = "Captcha",
        Width = Constants.CAPTCHA_WINDOW_WIDTH,
        Height = Constants.CAPTCHA_WINDOW_HEIGHT,
        Frame = false,
        Resizable = false,
        WebPreferences = new WebPreferences() {
            BackgroundThrottling = false,
            NodeIntegration = true,
            DisableBlinkFeatures = "Auxclick",
            AllowRunningInsecureContent = true,
            WebSecurity = false,
        }
    };

    CaptchaWindow = BrowserWindowService.CreateHiddenWindow(captchaWindowOptions, "");
    CaptchaWindow.OnClose += OnCaptchaWindowClosed;
    CaptchaWindow.OnMove += OnCaptchaWindowMoved;
    SetWindowPosition();

    string captchaViewUrl = $"http://127.0.0.1:{viewPort}";

    ProxyConfig proxyConfig = new ProxyConfig("", captchaViewUrl, ".google.com, .gstatic.com");
    await CaptchaWindow.WebContents.Session.SetProxyAsync(proxyConfig);

    bool doneLoading = false;
    CaptchaWindow.WebContents.OnDidFinishLoad += () => doneLoading = true;
    CaptchaWindow.LoadURL($"{hostUrl}?sitekey={hostSitekey}");

    CaptchaWindow.OnReadyToShow += async () => {
        while(!doneLoading) {
            await AsyncTask.Delay(1);
        }
        CaptchaWindow.Show();
    };
}

From here on, if I try to spawn a new BrowserWindow that loads a new url, the previous ProxyConfig seems to affect the traffic of this new window.

My current fix is by setting the proxyConfig again:

BrowserWindowOptions windowSettings = new BrowserWindowOptions {
    Show = false,
    Title = "New Window",
    Width = width,
    Height = height,
    Frame = true,
    Resizable = false,
    WebPreferences = new WebPreferences() {
        BackgroundThrottling = false,
        DisableBlinkFeatures = "Auxclick",
    }
};

BrowserWindow window = BrowserWindowService.CreateHiddenWindow(windowSettings, url);
window.OnClose += onWindowClose;
//window.OnMove += onWindowMove;

ProxyConfig proxyConfig = new ProxyConfig("", "", "");
await window.WebContents.Session.SetProxyAsync(proxyConfig);

bool doneLoading = false;
window.WebContents.OnDidFinishLoad += () => doneLoading = true;

LoadURLOptions urlOptions = new LoadURLOptions {
    ExtraHeaders = headers.ToString()
};
window.LoadURL(url, urlOptions);

window.OnReadyToShow += async () => {
    while(!doneLoading) {
        await AsyncTask.Delay(1);
    }
    window.Show();
};
Originally created by @thomvandevin on GitHub (May 6, 2020). Originally assigned to: @GregorBiswanger on GitHub. <!-- Please search existing issues to avoid creating duplicates. --> <!-- Which version of Electron.NET CLI and API are you using? --> <!-- Please always try to use latest version before report. --> * **Version**: 8.31.1 (and earlier) <!-- Which version of .NET Core and Node.js are you using (if applicable)? --> <!-- What target are you building for? --> * **Target**: .NET Core 3.1 & nodejs v12.16.2 <!-- Enter your issue details below this comment. --> <!-- If you want, you can donate to increase issue priority (https://donorbox.org/electron-net) --> Steps to Reproduce: I spawn a browserwindow like this: ```csharp public static async AsyncTask OpenCaptchaWindow(string hostUrl, string hostSitekey) { BrowserWindowOptions captchaWindowOptions = new BrowserWindowOptions { Show = false, Title = "Captcha", Width = Constants.CAPTCHA_WINDOW_WIDTH, Height = Constants.CAPTCHA_WINDOW_HEIGHT, Frame = false, Resizable = false, WebPreferences = new WebPreferences() { BackgroundThrottling = false, NodeIntegration = true, DisableBlinkFeatures = "Auxclick", AllowRunningInsecureContent = true, WebSecurity = false, } }; CaptchaWindow = BrowserWindowService.CreateHiddenWindow(captchaWindowOptions, ""); CaptchaWindow.OnClose += OnCaptchaWindowClosed; CaptchaWindow.OnMove += OnCaptchaWindowMoved; SetWindowPosition(); string captchaViewUrl = $"http://127.0.0.1:{viewPort}"; ProxyConfig proxyConfig = new ProxyConfig("", captchaViewUrl, ".google.com, .gstatic.com"); await CaptchaWindow.WebContents.Session.SetProxyAsync(proxyConfig); bool doneLoading = false; CaptchaWindow.WebContents.OnDidFinishLoad += () => doneLoading = true; CaptchaWindow.LoadURL($"{hostUrl}?sitekey={hostSitekey}"); CaptchaWindow.OnReadyToShow += async () => { while(!doneLoading) { await AsyncTask.Delay(1); } CaptchaWindow.Show(); }; } ``` From here on, if I try to spawn a new BrowserWindow that loads a new url, **the previous ProxyConfig seems to affect the traffic of this new window**. My current fix is by setting the proxyConfig again: ```csharp BrowserWindowOptions windowSettings = new BrowserWindowOptions { Show = false, Title = "New Window", Width = width, Height = height, Frame = true, Resizable = false, WebPreferences = new WebPreferences() { BackgroundThrottling = false, DisableBlinkFeatures = "Auxclick", } }; BrowserWindow window = BrowserWindowService.CreateHiddenWindow(windowSettings, url); window.OnClose += onWindowClose; //window.OnMove += onWindowMove; ProxyConfig proxyConfig = new ProxyConfig("", "", ""); await window.WebContents.Session.SetProxyAsync(proxyConfig); bool doneLoading = false; window.WebContents.OnDidFinishLoad += () => doneLoading = true; LoadURLOptions urlOptions = new LoadURLOptions { ExtraHeaders = headers.ToString() }; window.LoadURL(url, urlOptions); window.OnReadyToShow += async () => { while(!doneLoading) { await AsyncTask.Delay(1); } window.Show(); }; ```
claunia added the bug label 2026-01-29 16:40:45 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/Electron.NET#475