2

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?

Christian Baumann
  • 3,188
  • 3
  • 20
  • 37

2 Answers2

2

Try the --proxy-server command line switch:

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

(via)

cachius
  • 1,743
  • 1
  • 8
  • 21
1

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.

Juraj
  • 3,490
  • 4
  • 18
  • 25