forked from go-rod/rod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
40 lines (30 loc) · 869 Bytes
/
main.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
// Package main ...
package main
import (
"fmt"
"net/http"
"github.com/apedem/rod"
"github.com/apedem/rod/lib/utils"
)
func main() {
go serve()
browser := rod.New().MustConnect()
defer browser.MustClose()
// Creating a Page Object
page := browser.MustPage()
// Evaluates given script in every frame upon creation
// Disable all alerts by making window.alert no-op.
page.MustEvalOnNewDocument(`window.alert = () => {}`)
// Navigate to the website you want to visit
page.MustNavigate("http://localhost:8080")
fmt.Println(page.MustElement("script").MustText())
}
const testPage = `<html><script>alert("message")</script></html>`
// mock a server
func serve() {
mux := http.NewServeMux()
mux.HandleFunc("/", func(res http.ResponseWriter, req *http.Request) {
utils.E(fmt.Fprint(res, testPage))
})
utils.E(http.ListenAndServe(":8080", mux))
}