Enha (playwright): conditionaly install and use tools

This commit is contained in:
Grail Finder
2026-03-03 09:15:18 +03:00
parent d130254e88
commit 0c9c590d8f
6 changed files with 305 additions and 244 deletions

View File

@@ -74,23 +74,30 @@ Additional browser automation tools (Playwright):
`
var (
pw *playwright.Playwright
browser playwright.Browser
browserStarted bool
browserStartMu sync.Mutex
page playwright.Page
browserAvailable bool
pw *playwright.Playwright
browser playwright.Browser
browserStarted bool
browserStartMu sync.Mutex
page playwright.Page
)
func checkPlaywright() {
func installPW() error {
err := playwright.Install(&playwright.RunOptions{Verbose: false})
if err != nil {
logger.Warn("playwright not available", "error", err)
return err
}
return nil
}
func checkPlaywright() error {
var err error
pw, err = playwright.Run()
if err != nil {
logger.Warn("playwright not available", "error", err)
return
return err
}
browserAvailable = true
logger.Info("playwright tools available")
return nil
}
func pwStart(args map[string]string) []byte {
@@ -420,7 +427,3 @@ func pwDrag(args map[string]string) []byte {
}
return []byte(fmt.Sprintf(`{"success": true, "message": "Dragged from (%s,%s) to (%s,%s)"}`, x1, y1, x2, y2))
}
func init() {
go checkPlaywright()
}