-
Notifications
You must be signed in to change notification settings - Fork 0
/
browser.go
46 lines (40 loc) · 971 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
40
41
42
43
44
45
46
package vBrowser
import (
"net/http"
"net/http/cookiejar"
"golang.org/x/net/publicsuffix"
)
const defaultUserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36"
type Browser struct {
UserAgent string
CookieJar http.CookieJar
}
func NewBrowser() (browser *Browser) {
var err error
browser = new(Browser)
browser.CookieJar, err = cookiejar.New(&cookiejar.Options{PublicSuffixList: publicsuffix.List})
if err != nil {
panic(err)
}
browser.UserAgent = defaultUserAgent
return
}
func (b *Browser) NewTab() (tab *Tab) {
tab = new(Tab)
tab.browser = b
tab.httpClient = new(http.Client)
tab.httpClient.Jar = b.CookieJar
tab.httpClient.Transport = &transport{
browser: b,
tab: tab,
}
tab.ajaxHttpClient = new(http.Client)
tab.ajaxHttpClient.Jar = b.CookieJar
tab.ajaxHttpClient.Transport = &ajaxTransport{
transport{
browser: b,
tab: tab,
},
}
return
}