1 Star 3 Fork 2

林伟奇思妙想 / lin

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
类_谷歌窗口.go 3.57 KB
一键复制 编辑 原始数据 按行查看 历史
package lin
import (
"errors"
"fmt"
"os"
"runtime"
)
type G谷歌窗口 struct {
谷歌程序 C程序
谷歌路径 string
}
func ( *G谷歌窗口) Z置谷歌路径(谷歌路径 string) {
.谷歌路径 = 谷歌路径
}
func ( *G谷歌窗口) C创建窗口(网站url string, , int, 是否等待结束 bool) (返回错误 error) {
dir, err := os.MkdirTemp("", "lorca")
if err != nil {
return err
}
var 基础谷歌配置 = []string{
fmt.Sprintf("--app=%s", 网站url),
fmt.Sprintf("--window-size=%d,%d", , ),
fmt.Sprintf("--user-data-dir=%s", dir),
"--remote-debugging-port=0",
"--disable-background-networking",
"--disable-background-timer-throttling",
"--disable-backgrounding-occluded-windows",
"--disable-breakpad",
"--disable-client-side-phishing-detection",
"--disable-default-apps",
"--disable-dev-shm-usage",
"--disable-infobars",
"--disable-extensions",
"--disable-features=site-per-process",
"--disable-hang-monitor",
"--disable-ipc-flooding-protection",
"--disable-popup-blocking",
"--disable-prompt-on-repost",
"--disable-renderer-backgrounding",
"--disable-sync",
"--disable-translate",
"--disable-windows10-custom-titlebar",
"--metrics-recording-only",
"--no-first-run",
"--no-default-browser-check",
"--safebrowsing-disable-auto-update",
//"--enable-automation",
"--password-store=basic",
"--use-mock-keychain",
}
.谷歌程序.F附加运行条件(基础谷歌配置...)
if .谷歌路径 == "" {
.谷歌路径 = .Q取谷歌浏览器地址()
}
if .谷歌路径 == "" {
返回错误 = errors.New("错误:谷歌路径不存在")
return
}
返回错误 = .谷歌程序.Y运行程序(.谷歌路径, 是否等待结束)
return
}
func ( *G谷歌窗口) G关闭谷歌窗口() error {
return .谷歌程序.G关闭程序()
}
func ( *G谷歌窗口) D等待谷歌窗口关闭() error {
return .谷歌程序.D等待程序关闭()
}
func ( *G谷歌窗口) Q运行谷歌程序路径() (谷歌路径 string, 返回错误 error) {
return .谷歌程序.Q取运行程序路径()
}
func (G谷歌窗口) Q取谷歌浏览器地址() string {
// If env variable "LORCACHROME" specified and it exists
if path, ok := os.LookupEnv("LORCACHROME"); ok {
if _, err := os.Stat(path); err == nil {
return path
}
}
var paths []string
switch runtime.GOOS {
case "darwin":
paths = []string{
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
"/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary",
"/Applications/Chromium.app/Contents/MacOS/Chromium",
"/usr/bin/google-chrome-stable",
"/usr/bin/google-chrome",
"/usr/bin/chromium",
"/usr/bin/chromium-browser",
}
case "windows":
paths = []string{
"./Chrome/chrome.exe",
os.Getenv("LocalAppData") + "/Google/Chrome/Application/chrome.exe",
os.Getenv("ProgramFiles") + "/Google/Chrome/Application/chrome.exe",
os.Getenv("ProgramFiles(x86)") + "/Google/Chrome/Application/chrome.exe",
os.Getenv("LocalAppData") + "/Chromium/Application/chrome.exe",
os.Getenv("ProgramFiles") + "/Chromium/Application/chrome.exe",
os.Getenv("ProgramFiles(x86)") + "/Chromium/Application/chrome.exe",
os.Getenv("ProgramFiles(x86)") + "/Microsoft/Edge/Application/msedge.exe",
}
default:
paths = []string{
"/usr/bin/google-chrome-stable",
"/usr/bin/google-chrome",
"/usr/bin/chromium",
"/usr/bin/chromium-browser",
"/snap/bin/chromium",
}
}
for _, path := range paths {
if _, err := os.Stat(path); os.IsNotExist(err) {
continue
}
return path
}
return ""
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/mad-wud/lin.git
git@gitee.com:mad-wud/lin.git
mad-wud
lin
lin
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891