playwright-community / playwright-go

Playwright for Go a browser automation library to control Chromium, Firefox and WebKit with a single API.
https://playwright-community.github.io/playwright-go/
MIT License
2.11k stars 157 forks source link

Documentation doesn't seem to shed light on using the local chrome driver most users have installed instead of downloading it. #329

Closed dracoDevs closed 6 months ago

dracoDevs commented 1 year ago

I did see a push referencing the "local chrome path" pull request but I cannot tell the difference when I run the code it still's installs the playwright-md files.

I want to be able to use my installation of chrome as a driver not what the package wants to install.

huoxue1 commented 1 year ago
_, b := os.LookupEnv("PLAYWRIGHT_BROWSERS_PATH")
    if !b {
        err = os.Setenv("PLAYWRIGHT_BROWSERS_PATH", dir+"/tools/browser/")
        if err != nil {
            log.Errorln("set env PLAYWRIGHT_BROWSERS_PATH fail" + err.Error())
            err = nil
        }
    }
pwo := &playwright.RunOptions{
        DriverDirectory:     dir + "/tools/driver/",
        SkipInstallBrowsers: true,
        Browsers:            []string{"msedge"},
    }

pwt, err := playwright.Run(pwo)
    if err != nil {
        log.Errorln("[core]", "init the playwright fail")
        log.Errorln("[core] ", err.Error())

        return
    }
if path == "" {
        path = "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe"
    }

browser, err := pwt.Chromium.Launch(playwright.BrowserTypeLaunchOptions{
        ExecutablePath:  playwright.String(path),
    })

You can customize the location of the browser by setting ExecutablePath, and set SkipInstallBrowsers to determine whether to skip downloading the browser. If you need to download the browser, you can use the environment variable PLAYWRIGHT_BROWSERS_PATH to set the location of the browser download,my roommate's playwright-go version is v0.2000.1.

you can see https://playwright.bootcss.com/docs/installation?_highlight=playwright_browsers_path#managing-browser-binaries

canstand commented 6 months ago

Refer https://playwright.dev/docs/browsers#google-chrome--microsoft-edge and #340

browser, err := pw.Chromium.Launch(playwright.BrowserTypeLaunchOptions{
        Channel: playwright.String("chrome"),
    })