-
Notifications
You must be signed in to change notification settings - Fork 0
/
sraketa.go
70 lines (55 loc) · 1.45 KB
/
sraketa.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"log"
"github.com/playwright-community/playwright-go"
)
var loadedPage playwright.Page
var playwrightError error
var playwrightInstance *playwright.Playwright
var playwrightBrowser playwright.Browser
func sraketa_init() bool {
playwrightError = playwright.Install()
if playwrightError != nil {
log.Printf("Could not install playwright")
return false
}
playwrightInstance, playwrightError = playwright.Run()
if playwrightError != nil {
return false
}
playwrightBrowser, playwrightError = playwrightInstance.Firefox.Launch()
if playwrightError != nil {
return false
}
loadedPage, playwrightError = playwrightBrowser.NewPage()
if playwrightError != nil {
return false
}
if _, playwrightError = loadedPage.Goto("https://alerts.in.ua", playwright.PageGotoOptions{
WaitUntil: playwright.WaitUntilStateNetworkidle,
}); playwrightError != nil {
return false
}
return true
}
func sraketa() bool {
if playwrightError == nil {
if _, err := loadedPage.Screenshot(playwright.PageScreenshotOptions{
Path: playwright.String("sraketa_current.png"),
}); err != nil {
log.Printf("could not create screenshot: %v", err)
return false
}
return true
} else {
return false
}
}
func sraketa_shutdown() {
if err := playwrightBrowser.Close(); err != nil {
log.Printf("could not close browser: %v", err)
}
if err := playwrightInstance.Stop(); err != nil {
log.Fatalf("could not stop Playwright: %v", err)
}
}