Search code examples
playwrightplaywright-testplaywright-java

Error while downloading Playwright browser binaries


I'm getting an error that reads "UNABLE_TO_GET_ISSUER_CERT_LOCALLY" (entire stack trace pasted below) while I'm trying to run a simple playwright code written in Java (code pasted below).

I'm trying to run playwright on the new laptop I have got from my organization, since this is the very first run hence it is downloading the browser binaries, however while downloading it is throwing me an error which is mentioned below.

I tried setting the proxy as mentioned in the playwright documentation but that didn't help.

Any help is appreciated!

Environment: OS - Windows 11 Language - java (java version "1.8.0_421") Tool - Playwright v1.45

Code

import com.microsoft.playwright.*;

public class Trial {
    public static void main(String[] args) {
        try (Playwright playwright = Playwright.create()) {
            Browser browser = playwright.chromium().launch();
            Page page = browser.newPage();
            page.navigate("http://playwright.dev");
            System.out.println(page.title());
        }
    }
}

Error

Downloading Chromium 127.0.6533.17 (playwright build v1124) from https://playwright.azureedge.net/builds/chromium/1124/chromium-win64.zip
Error: unable to get local issuer certificate
    at TLSSocket.onConnectSecure (node:_tls_wrap:1674:34)
    at TLSSocket.emit (node:events:519:28)
    at TLSSocket._finishInit (node:_tls_wrap:1085:8)
    at ssl.onhandshakedone (node:_tls_wrap:871:12) {
  code: 'UNABLE_TO_GET_ISSUER_CERT_LOCALLY'
}
Downloading Chromium 127.0.6533.17 (playwright build v1124) from https://playwright-akamai.azureedge.net/builds/chromium/1124/chromium-win64.zip
Error: unable to get local issuer certificate
    at TLSSocket.onConnectSecure (node:_tls_wrap:1674:34)
    at TLSSocket.emit (node:events:519:28)
    at TLSSocket._finishInit (node:_tls_wrap:1085:8)
    at ssl.onhandshakedone (node:_tls_wrap:871:12) {
  code: 'UNABLE_TO_GET_ISSUER_CERT_LOCALLY'
}
Downloading Chromium 127.0.6533.17 (playwright build v1124) from https://playwright-verizon.azureedge.net/builds/chromium/1124/chromium-win64.zip
Error: unable to get local issuer certificate
    at TLSSocket.onConnectSecure (node:_tls_wrap:1674:34)
    at TLSSocket.emit (node:events:519:28)
    at TLSSocket._finishInit (node:_tls_wrap:1085:8)
    at ssl.onhandshakedone (node:_tls_wrap:871:12) {
  code: 'UNABLE_TO_GET_ISSUER_CERT_LOCALLY'
}
Failed to install browsers
Error: Failed to download Chromium 127.0.6533.17 (playwright build v1124), caused by
Error: Download failure, code=1
    at ChildProcess.<anonymous> (C:\Users\soswal\AppData\Local\Temp\playwright-java-7340062122137613393\package\lib\server\registry\browserFetcher.js:91:16)
    at ChildProcess.emit (node:events:519:28)
    at ChildProcess._handle.onexit (node:internal/child_process:294:12)
Exception in thread "main" java.lang.RuntimeException: Failed to create driver
    at com.microsoft.playwright.impl.driver.Driver.createAndInstall(Driver.java:105)
    at com.microsoft.playwright.impl.driver.Driver.ensureDriverInstalled(Driver.java:57)
    at com.microsoft.playwright.impl.PlaywrightImpl.createImpl(PlaywrightImpl.java:46)
    at com.microsoft.playwright.impl.PlaywrightImpl.create(PlaywrightImpl.java:36)
    at com.microsoft.playwright.Playwright.create(Playwright.java:110)
    at com.microsoft.playwright.Playwright.create(Playwright.java:114)
    at common.InitiatePlaywright.<init>(InitiatePlaywright.java:19)
    at testing.Test.main(Test.java:8)
Caused by: java.lang.RuntimeException: Failed to install browsers, exit code: 1
    at com.microsoft.playwright.impl.driver.jar.DriverJar.installBrowsers(DriverJar.java:99)
    at com.microsoft.playwright.impl.driver.jar.DriverJar.initialize(DriverJar.java:68)
    at com.microsoft.playwright.impl.driver.Driver.initialize(Driver.java:64)
    at com.microsoft.playwright.impl.driver.Driver.createAndInstall(Driver.java:101)
    ... 7 more

Process finished with exit code 1

Solution

  • Resolved now. The issue was with the certificates.

    Solution Reference - https://github.com/microsoft/playwright/issues/19622

    Steps performed to resolve:

    1. Visit "https://playwright.azureedge.net/" (or the url from which playwright is trying to download)
    2. Download all the certificates i.e root certificate and all child certificates
    3. Creating a new .pem file in which all the above downloaded certificates are appended with the help of the command "gc "{filepath}{certificate_file_name}.crt" | ac "{filepath}{target_filename}.crt"", which is executed powershell
    4. Once done download the browsers using CLI or run the program

    Note - all the mentioned steps are taken from the reference provided