-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
55 lines (45 loc) · 1.19 KB
/
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"os/exec"
"log"
"github.com/tidwall/gjson"
"golang.org/x/net/websocket"
"github.com/levigross/grequests"
"fmt"
)
func runchrome(){
cmd := exec.Command("/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", "--headless", "--user-data-dir=/Users/omaidfaizyar/Library/Application Support/Google/Chrome/Default","https://gmail.com","--remote-debugging-port=9222")
err := cmd.Run()
if err != nil {
log.Fatalf("cmd.Run() failed with %s\n", err)
}
}
func checkcookies(socketurl string){
cookie := `{"id": 1, "method": "Network.getAllCookies"}`
origin := "http://localhost/"
ws, err := websocket.Dial(socketurl, "", origin)
if err != nil {
log.Fatal(err)
}
if _, err := ws.Write([]byte(cookie)); err != nil {
log.Fatal(err)
}
var msg = make([]byte, 512)
var n int
if n, err = ws.Read(msg); err != nil {
log.Fatal(err)
}
fmt.Printf("Received: %s.\n", msg[:n])
}
func main(){
go runchrome()
resp, err := grequests.Get("http://localhost:9222/json",nil)
if err != nil {
panic(err)
}
value := gjson.Get(resp.String(), "#.webSocketDebuggerUrl")
value.ForEach(func(key, value gjson.Result) bool {
checkcookies(value.String())
return true
})
}