forked from browserutils/kooky
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chromium.go
47 lines (39 loc) · 1.21 KB
/
chromium.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
package chromium
import (
"net/http"
"github.com/favbox/kooky"
"github.com/favbox/kooky/internal/chrome"
"github.com/favbox/kooky/internal/cookies"
)
func ReadCookies(filename string, filters ...kooky.Filter) ([]*kooky.Cookie, error) {
s, err := cookieStore(filename, filters...)
if err != nil {
return nil, err
}
defer s.Close()
return s.ReadCookies(filters...)
}
// CookieJar returns an initiated http.CookieJar based on the cookies stored by
// the Chromium browser. Set cookies are memory stored and do not modify any
// browser files.
func CookieJar(filename string, filters ...kooky.Filter) (http.CookieJar, error) {
j, err := cookieStore(filename, filters...)
if err != nil {
return nil, err
}
defer j.Close()
if err := j.InitJar(); err != nil {
return nil, err
}
return j, nil
}
// CookieStore has to be closed with CookieStore.Close() after use.
func CookieStore(filename string, filters ...kooky.Filter) (kooky.CookieStore, error) {
return cookieStore(filename, filters...)
}
func cookieStore(filename string, filters ...kooky.Filter) (*cookies.CookieJar, error) {
s := &chrome.CookieStore{}
s.FileNameStr = filename
s.BrowserStr = `chromium`
return &cookies.CookieJar{CookieStore: s}, nil
}