How to set proxy for Chromium on Windows with Playwright Java?

2.9k Views Asked by At

I'm trying to use a proxy for Chromium on Windows:

BrowserType.LaunchOptions launchOptions = new BrowserType.LaunchOptions();
launchOptions.setProxy(new Proxy("localhost:8888"));

Browser browser = Playwright.create().chromium().launch(launchOptions);

In the settings I see that the proxy has been set properly, but the option Use proxyserver is set to false.

Windows' proxy settings

How to change that?

2

There are 2 best solutions below

0
On BEST ANSWER

Try the --proxy-server command line switch:

launchOptions.setArgs(List.of("--proxy-server=http://localhost:8888"))

(via)

2
On

I tested this with version 1.22.0 and it works:

package test;

import com.microsoft.playwright.Browser;
import com.microsoft.playwright.BrowserType;
import com.microsoft.playwright.Page;
import com.microsoft.playwright.Playwright;
import com.microsoft.playwright.options.Proxy;

public class Example {
  public static void main(String[] args) {
    try (Playwright playwright = Playwright.create()) {
      BrowserType.LaunchOptions launchOptions = new BrowserType.LaunchOptions();
      launchOptions.headless = false;
      launchOptions.setProxy(new Proxy("localhost:8888"));
      Browser browser = playwright.chromium().launch(launchOptions);
      Page page = browser.newPage();
      page.navigate("http://playwright.dev");
      System.out.println(page.title());
    }
  }
}

The launchOptions don't cause the system proxy setting to be set. Values on your screenshot must have been entered before.