linux环境继续使用chrome浏览器

This commit is contained in:
johlanse 2022-06-04 16:33:56 +08:00
parent 160bf6777e
commit 51a0ac51df
1 changed files with 15 additions and 11 deletions

View File

@ -297,15 +297,19 @@ func (c *Core) initNotWindows() {
if err != nil { if err != nil {
return return
} }
err = os.Setenv("PLAYWRIGHT_BROWSERS_PATH", dir+"/tools/browser/") _, b := os.LookupEnv("PLAYWRIGHT_BROWSERS_PATH")
if err != nil { if !b {
log.Errorln("设置环境变量PLAYWRIGHT_BROWSERS_PATH失败" + err.Error()) err = os.Setenv("PLAYWRIGHT_BROWSERS_PATH", dir+"/tools/browser/")
err = nil if err != nil {
log.Errorln("设置环境变量PLAYWRIGHT_BROWSERS_PATH失败" + err.Error())
err = nil
}
} }
pwt, err := playwright.Run(&playwright.RunOptions{ pwt, err := playwright.Run(&playwright.RunOptions{
DriverDirectory: dir + "/tools/driver/", DriverDirectory: dir + "/tools/driver/",
SkipInstallBrowsers: false, SkipInstallBrowsers: false,
Browsers: []string{"firefox"}, Browsers: []string{"msedge", "chromium"},
}) })
if err != nil { if err != nil {
log.Errorln("[core]", "初始化playwright失败") log.Errorln("[core]", "初始化playwright失败")
@ -314,20 +318,20 @@ func (c *Core) initNotWindows() {
return return
} }
c.pw = pwt c.pw = pwt
browser, err := pwt.Firefox.Launch(playwright.BrowserTypeLaunchOptions{ browser, err := pwt.Chromium.Launch(playwright.BrowserTypeLaunchOptions{
Args: []string{ Args: []string{
"--disable-extensions", "--disable-extensions",
"--disable-gpu", "--disable-gpu",
"--start-maximized", "--start-maximized",
"--no-sandbox", "--no-sandbox",
"--window-size=500,450", "--window-size=500,450",
// "--mute-audio", "--mute-audio",
"--window-position=0,0", "--window-position=0,0",
"--ignore-certificate-errors", "--ignore-certificate-errors",
// "--ignore-ssl-errors", "--ignore-ssl-errors",
// "--disable-features=RendererCodeIntegrity", "--disable-features=RendererCodeIntegrity",
// "--disable-blink-features", "--disable-blink-features",
// "--disable-blink-features=AutomationControlled", "--disable-blink-features=AutomationControlled",
}, },
Channel: nil, Channel: nil,
ChromiumSandbox: nil, ChromiumSandbox: nil,