-
Notifications
You must be signed in to change notification settings - Fork 2
/
browser.go
39 lines (37 loc) · 994 Bytes
/
browser.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package chatgpt
import (
"github.com/playwright-community/playwright-go"
"github.com/sirupsen/logrus"
"os"
)
func (h *Helper) LaunchBrowser() error {
runOptions := &playwright.RunOptions{
Browsers: []string{"firefox"},
Verbose: false,
}
err := playwright.Install(runOptions)
if err != nil {
logrus.Errorf("Error while installing playwright: %v", err)
return err
}
logrus.Info("Playwright installed successfully")
pw, err := playwright.Run()
if err != nil {
logrus.Errorf("Error while running playwright: %v", err)
return err
}
logrus.Info("Playwright running successfully")
args := []string{}
os.RemoveAll("./cache")
browser, err := pw.Firefox.LaunchPersistentContext("./cache", playwright.BrowserTypeLaunchPersistentContextOptions{
Args: args,
Headless: playwright.Bool(false),
})
if err != nil {
logrus.Errorf("Error while launching browser: %v", err)
return err
}
logrus.Info("Browser launched successfully")
h.browser = browser
return nil
}