Slide 21
Slide 21 text
2
10 func main() {
12 farm := chromefarm.NewFarm()
14 // This serves the postback.html for the browser to load
15 http.HandleFunc("/", func(res http.ResponseWriter, req *http.Request) {
17 http.ServeFile(res, req, "postback.html")
18 })
19 // this handles the callback from JS/AJAX
20 http.HandleFunc("/callback", func(res http.ResponseWriter, req *http.Request) {
21 message := req.FormValue("message")
22 log.Println("Received message from browser: %s", message)
25 })
26 farm.OnReady(func() {
29 for i := 0; i < 2; i++ {
30 browser := farm.CreateBrowser(url)
31 browser.ExecuteJavaScript(fmt.Sprintf("console.log('sup %d');", i), "eva
32 }
33 })
34 farm.Start(":3000")
36 }
7
8
9 $.post('/callback', {message: "I've loaded successfully"}, function(resp) {
10 console.log(resp);
11 });
12
13