mirror of
https://github.com/dstotijn/hetty.git
synced 2025-07-01 18:47:29 -04:00
Add support to launch Chrome
This commit is contained in:
33
pkg/chrome/chrome.go
Normal file
33
pkg/chrome/chrome.go
Normal file
@ -0,0 +1,33 @@
|
||||
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...), ";")
|
||||
opts := append(defaultOpts,
|
||||
chromedp.ProxyServer(cfg.ProxyServer),
|
||||
chromedp.Flag("proxy-bypass-list", proxyBypass),
|
||||
)
|
||||
|
||||
return chromedp.NewExecAllocator(ctx, opts...)
|
||||
}
|
@ -60,7 +60,7 @@ func TestFindRequestByID(t *testing.T) {
|
||||
|
||||
URL: exampleURL,
|
||||
Method: http.MethodGet,
|
||||
Proto: sender.HTTPProto2,
|
||||
Proto: sender.HTTPProto20,
|
||||
Header: http.Header{
|
||||
"X-Foo": []string{"bar"},
|
||||
},
|
||||
|
@ -165,7 +165,7 @@ func TestCloneFromRequestLog(t *testing.T) {
|
||||
ProjectID: projectID,
|
||||
URL: exampleURL,
|
||||
Method: http.MethodPost,
|
||||
Proto: sender.HTTPProto2,
|
||||
Proto: sender.HTTPProto20,
|
||||
Header: http.Header{
|
||||
"X-Foo": []string{"bar"},
|
||||
},
|
||||
|
Reference in New Issue
Block a user