package browser import ( "context" "github.com/go-rod/rod" "github.com/go-rod/rod/lib/launcher" "github.com/go-rod/rod/lib/launcher/flags" "github.com/go-rod/rod/lib/proto" "go.uber.org/zap" ) // OpenApp 用APP模式打开网页 func OpenApp(c context.Context, url string) { path, _ := launcher.LookPath() l := launcher.NewAppMode(url). Delete(flags.Env). Set("kiosk"). Delete("disable-site-isolation-trials"). Bin(path) p := l.MustLaunch() defer l.Cleanup() b := rod.New().ControlURL(p).MustConnect() defer b.MustClose() s := make(chan struct{}) wait := b.EachEvent(func(e *proto.TargetTargetDestroyed) { zap.S().Infoln("关闭待机网页") s <- struct{}{} }) go wait() select { case <-c.Done(): b.MustClose() <-s case <-s: } }