1

I am developing a simple prototype with Java + Playwright + Browserless. I was wondering if is possible avoid downloading the browsers in AWS.

Playwright build of chromium v956323 downloaded to /home/ec2-user/.cache/ms-playwright/chromium-956323
Playwright build of ffmpeg v1007 downloaded to /home/ec2-user/.cache/ms-playwright/ffmpeg-1007
Playwright build of firefox v1313 downloaded to /home/ec2-user/.cache/ms-playwright/firefox-1313
Playwright build of webkit v1596 downloaded to /home/ec2-user/.cache/ms-playwright/webkit-1596

Sometimes it will run in browserless and i think if so i wont need the browser but i dont really know is this possible? or even running in browserless i would need the browsers?

If so how can i do that in Java.

I want to do it programmatically because depending of the parameters sometime i need them sometimes dont is this possible?

chiperortiz
  • 4,751
  • 9
  • 45
  • 79

2 Answers2

2

You can skip the browser download by setting an environment variable PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1

See the docs here: https://playwright.dev/java/docs/browsers#skip-browser-downloads

Christian Baumann
  • 3,188
  • 3
  • 20
  • 37
  • But i want to do it programmatically i mean depending of the configuration sometimes it will run in the browsers in the same machine and sometimes in different providers. – chiperortiz Mar 15 '22 at 19:15
  • 1
    Sorry, missed that bit. How to set an env var programmatically in Java depends on your OS, lots of possibilities covered here: https://stackoverflow.com/questions/318239/how-do-i-set-environment-variables-from-java – Christian Baumann Mar 15 '22 at 19:36
2
Map<String,String> env = new HashMap<>();
env.put("PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD","1");
try (Playwright playwright = Playwright.create(new Playwright.CreateOptions().setEnv(env))) {
        BrowserType chromium = playwright.chromium();
        Browser browser = chromium.launch();
        Page page = browser.newPage();
        page.onRequest(request -> System.out.println(">> " + request.method() + " " + request.url()));
        page.onResponse(response -> System.out.println("<<" + response.status() + " " + response.url()));
        page.navigate("https://example.com");
        browser.close();
    }
}
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
Shaheaz
  • 23
  • 5