Due to some restrictions, I have to use a Proxy to visit one specific web site. To this end, I subscribe one paid proxy service, and tried to visit that web site, it worked. However, to use the proxy service by Google Chrome, I have to configure the proxy settings from Windows Edge browser, so the proxy settings affect all the web browsers in my PC, which I don’t want; because, except that specific web site, I can visit all other web sites directly using my ISP without any issue. I have tried the following C# code to see if I can visit “WhatIsMyIP” web site using proxy settings only during the underlying Chromium session.
private static readonly LaunchOptions puppeteer_launchOptions = new LaunchOptions
{
Headless = false,
IgnoreHTTPSErrors = true,
Args = new[] {
"--no-sandbox",
"--disable-infobars",
"--disable-setuid-sandbox",
"--ignore-certificate-errors",
$"--proxy-server='1.2.3.4:5678'",
},
};
static async Task Main()
{
await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);
_browser = await Puppeteer.LaunchAsync(puppeteer_launchOptions);
Page _page = await _browser.NewPageAsync();
await _page.SetViewportAsync((new ViewPortOptions { Width = 1920, Height = 938 }));
_page.DefaultNavigationTimeout = 100000;
await _page.GoToAsync("https://www.whatismyip.com/");
await _page.WaitForTimeoutAsync(2000);
Console.WriteLine("My Public IP is:");
}
However, my code did NOT work, I got error message: PuppeteerSharp.NavigationException HResult=0x80131500 Message=net::ERR_NO_SUPPORTED_PROXIES at https://www.whatismyip.com/ at https://www.whatismyip.com/ Source=PuppeteerSharp StackTrace: at PuppeteerSharp.FrameManager.d__42.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at ProxyWhatIsMyIP.Program.d__3.MoveNext() in C:\DualDataLiveBet\BetFairProxy\ProxyWhatIsMyIP\ProxyWhatIsMyIP\Program.cs:line 31
Inner Exception 1: NavigationException: net::ERR_NO_SUPPORTED_PROXIES at https://www.whatismyip.com/
But if I changed the global proxy settings in Microsoft Edge browser, and deleted the proxy settings in my C# code, it worked. The following was the working code:
using PuppeteerSharp;
using System;
using System.Threading.Tasks;
namespace ProxyWhatIsMyIP
{
class Program
{
public static Browser _browser;
private static readonly LaunchOptions puppeteer_launchOptions = new LaunchOptions
{
Headless = false,
IgnoreHTTPSErrors = true,
Args = new[] {
"--no-sandbox",
"--disable-infobars",
"--disable-setuid-sandbox",
"--ignore-certificate-errors",
},
};
static async Task Main()
{
await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);
_browser = await Puppeteer.LaunchAsync(puppeteer_launchOptions);
Page _page = await _browser.NewPageAsync();
await _page.SetViewportAsync((new ViewPortOptions { Width = 1920, Height = 938 }));
_page.DefaultNavigationTimeout = 100000;
await _page.GoToAsync("https://www.whatismyip.com/");
await _page.WaitForTimeoutAsync(2000);
Console.WriteLine("My Public IP is:");
}
}
But it is not what I want. I only want to use Proxy during this Chromium session, but keep the global proxy settings untouched (not to use any proxy in my PC.) Please advice how I can do this? By the way, I am using Visual Studio 2019 Version 16.3.2 with PuppeteerSharp 1.20.0, targetting .NET Core 3.0. My PC is running on Windows 10 (Version 1903) with latest updates applied. Thanks,
I made a stupid typo when searching answers from other people. Actually, it was simple. The launch option has some wrong text, delete the http:// is enough, since I am using direct IP address. So the correct syntax is:
rivate static readonly LaunchOptions puppeteer_launchOptions = new LaunchOptions
{
Headless = false,
IgnoreHTTPSErrors = true,
Args = new [] {
"--proxy-server=1.2.3.4:5678",
"--no-sandbox",
"--disable-infobars",
"--disable-setuid-sandbox",
"--ignore-certificate-errors",
},
};
By the way, --disable-infobars seems not working since 1.19.0 until 1.20.0; I always see the information: Chrome is being controlled by automated test software. I remember someone said since 1.19.0 Google Chrome changed something, so --disable-infobars not working, but he also provide some example how to disable the warning, but his method did NOT include PuppeteerSharp, Puppeteer was included.
Now, I can't figure it out yet.
Hope my question can help some other people. It is just a typo, not a big issue!
User contributions licensed under CC BY-SA 3.0