From 51a0ac51df247a300484c5bf32f0e25a8c11a036 Mon Sep 17 00:00:00 2001 From: johlanse Date: Sat, 4 Jun 2022 16:33:56 +0800 Subject: [PATCH] =?UTF-8?q?linux=E7=8E=AF=E5=A2=83=E7=BB=A7=E7=BB=AD?= =?UTF-8?q?=E4=BD=BF=E7=94=A8chrome=E6=B5=8F=E8=A7=88=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/core.go | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/core.go b/lib/core.go index fb95302..1b204d3 100644 --- a/lib/core.go +++ b/lib/core.go @@ -297,15 +297,19 @@ func (c *Core) initNotWindows() { if err != nil { return } - err = os.Setenv("PLAYWRIGHT_BROWSERS_PATH", dir+"/tools/browser/") - if err != nil { - log.Errorln("设置环境变量PLAYWRIGHT_BROWSERS_PATH失败" + err.Error()) - err = nil + _, b := os.LookupEnv("PLAYWRIGHT_BROWSERS_PATH") + if !b { + err = os.Setenv("PLAYWRIGHT_BROWSERS_PATH", dir+"/tools/browser/") + if err != nil { + log.Errorln("设置环境变量PLAYWRIGHT_BROWSERS_PATH失败" + err.Error()) + err = nil + } } + pwt, err := playwright.Run(&playwright.RunOptions{ DriverDirectory: dir + "/tools/driver/", SkipInstallBrowsers: false, - Browsers: []string{"firefox"}, + Browsers: []string{"msedge", "chromium"}, }) if err != nil { log.Errorln("[core]", "初始化playwright失败") @@ -314,20 +318,20 @@ func (c *Core) initNotWindows() { return } c.pw = pwt - browser, err := pwt.Firefox.Launch(playwright.BrowserTypeLaunchOptions{ + browser, err := pwt.Chromium.Launch(playwright.BrowserTypeLaunchOptions{ Args: []string{ "--disable-extensions", "--disable-gpu", "--start-maximized", "--no-sandbox", "--window-size=500,450", - // "--mute-audio", + "--mute-audio", "--window-position=0,0", "--ignore-certificate-errors", - // "--ignore-ssl-errors", - // "--disable-features=RendererCodeIntegrity", - // "--disable-blink-features", - // "--disable-blink-features=AutomationControlled", + "--ignore-ssl-errors", + "--disable-features=RendererCodeIntegrity", + "--disable-blink-features", + "--disable-blink-features=AutomationControlled", }, Channel: nil, ChromiumSandbox: nil,