diff --git a/.gitignore b/.gitignore index 9650c2e..17d8393 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ *.log /config/config.yml /chromium-857950/ +/web/ diff --git a/lib/config.go b/lib/config.go index 2080515..34f1531 100644 --- a/lib/config.go +++ b/lib/config.go @@ -36,9 +36,10 @@ type Config struct { Host string `json:"host" yaml:"host"` Port int `json:"port" yaml:"port"` } `json:"web"` - Cron string `json:"cron" yaml:"cron"` - EdgePath string `json:"edge_path" yaml:"edge_path"` - QrCOde bool `json:"qr_code" yaml:"qr_code"` + Cron string `json:"cron" yaml:"cron"` + EdgePath string `json:"edge_path" yaml:"edge_path"` + QrCOde bool `json:"qr_code" yaml:"qr_code"` + StartWait int `json:"start_wait" yaml:"start_wait"` } var ( diff --git a/lib/config_default.yml b/lib/config_default.yml index 0af8d26..a9203cd 100644 --- a/lib/config_default.yml +++ b/lib/config_default.yml @@ -43,3 +43,12 @@ tg: # "9 19 * * *" 每天19点9分执行一次 # "* 10 * * *” 每天早上十点执行一次 cron: "" + +#windows环境自定义浏览器路径,仅支持chromium系列 +edge_path: "" + +# 是否推送二维码 +qr_code: false + +# 启动时等待时间,为了防止代理启动比软件慢而报错,默认不等待,单位秒 +start_wait: 0 \ No newline at end of file diff --git a/lib/core.go b/lib/core.go index 1526c9e..76d7b37 100644 --- a/lib/core.go +++ b/lib/core.go @@ -231,7 +231,7 @@ func (c *Core) initWondows() { Channel: nil, ChromiumSandbox: nil, Devtools: nil, - DownloadsPath: nil, + DownloadsPath: playwright.String("./tools/temp/"), ExecutablePath: playwright.String(path), HandleSIGHUP: nil, HandleSIGINT: nil, @@ -250,7 +250,8 @@ func (c *Core) initWondows() { c.browser = browser context, err := c.browser.NewContext() - c.browser.NewContext() + _ = context.AddInitScript(playwright.BrowserContextAddInitScriptOptions{ + Script: playwright.String("Object.defineProperties(navigator, {webdriver:{get:()=>undefined}});")}) if err != nil { return } @@ -313,9 +314,9 @@ func (c *Core) initNotWindows() { return } c.browser = browser - context, err := c.browser.NewContext() - c.browser.NewContext() + _ = context.AddInitScript(playwright.BrowserContextAddInitScriptOptions{ + Script: playwright.String("Object.defineProperties(navigator, {webdriver:{get:()=>undefined}});")}) if err != nil { return } diff --git a/main.go b/main.go index 2358d64..39598b0 100644 --- a/main.go +++ b/main.go @@ -61,6 +61,10 @@ func init() { } func main() { + if config.StartWait > 0 { + log.Infoln(fmt.Sprintf("将等待%d秒后启动程序", config.StartWait)) + time.Sleep(time.Second * time.Duration(config.StartWait)) + } switch { case config.Cron != "": log.Infoln("已采用定时执行模式")