Files
hetty/pkg/chrome/chrome.go

35 lines
981 B
Go
Raw Permalink Normal View History

2022-02-27 17:56:24 +01:00
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...), ";")
2022-02-28 16:21:01 +01:00
//nolint:gocritic
2022-02-27 17:56:24 +01:00
opts := append(defaultOpts,
chromedp.ProxyServer(cfg.ProxyServer),
chromedp.Flag("proxy-bypass-list", proxyBypass),
)
return chromedp.NewExecAllocator(ctx, opts...)
}