-
-
Notifications
You must be signed in to change notification settings - Fork 342
/
chrome.go
34 lines (28 loc) · 981 Bytes
/
chrome.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
package chrome
import (
"context"
"strings"
"github.com/chromedp/chromedp"
)
var defaultOpts = []chromedp.ExecAllocatorOption{
chromedp.NoFirstRun,
chromedp.NoDefaultBrowserCheck,
chromedp.IgnoreCertErrors,
chromedp.Flag("test-type ", true), // This prevents the `ignore-certificate-errors` warning.
}
type Config struct {
ProxyServer string
ProxyBypassHosts []string
}
// NewExecAllocator returns a new context setup with a chromedp.ExecAllocator.
// Its `context.Context` return value can be used to create subsequent contexts for interacting
// with an allocated Chrome browser.
func NewExecAllocator(ctx context.Context, cfg Config) (context.Context, context.CancelFunc) {
proxyBypass := strings.Join(append([]string{"<-loopback"}, cfg.ProxyBypassHosts...), ";")
//nolint:gocritic
opts := append(defaultOpts,
chromedp.ProxyServer(cfg.ProxyServer),
chromedp.Flag("proxy-bypass-list", proxyBypass),
)
return chromedp.NewExecAllocator(ctx, opts...)
}