Merge pull request 'Fix ShowBrowser merge + consistent browser defaults (#15, #16)' (#38) from fix/merge-options-and-browser-defaults into main
All checks were successful
CI / build (push) Successful in 32s
CI / vet (push) Successful in 1m50s
CI / test (push) Successful in 1m51s

This commit was merged in pull request #38.
This commit is contained in:
2026-02-15 16:23:07 +00:00
5 changed files with 14 additions and 6 deletions

View File

@@ -118,7 +118,7 @@ extractor.BrowserOptions{
Browser: extractor.BrowserFirefox, // or BrowserChromium, BrowserWebKit
Timeout: &timeout, // default 30s, 0 for no timeout
CookieJar: jar, // load/save cookies automatically
ShowBrowser: true, // show browser window (non-headless)
ShowBrowser: extractor.Bool(true), // show browser window (non-headless)
Dimensions: extractor.Size{1280, 720},
DarkMode: true,
ServerAddress: "ws://...", // remote Playwright server

View File

@@ -70,8 +70,9 @@ func initBrowser(opt BrowserOptions) (*browserInitResult, error) {
}
if launch {
headless := opt.ShowBrowser == nil || !*opt.ShowBrowser
browser, err = bt.Launch(playwright.BrowserTypeLaunchOptions{
Headless: playwright.Bool(!opt.ShowBrowser),
Headless: playwright.Bool(headless),
})
if err != nil {
return nil, fmt.Errorf("failed to launch browser: %w", err)
@@ -154,7 +155,9 @@ func mergeOptions(base BrowserOptions, opts []BrowserOptions) BrowserOptions {
if o.UseLocalOnly {
base.UseLocalOnly = true
}
if o.ShowBrowser != nil {
base.ShowBrowser = o.ShowBrowser
}
}
return base
}

View File

@@ -70,7 +70,9 @@ func FromCommand(ctx context.Context, cmd *cli.Command) (extractor.Browser, erro
opts.CookieJar = cookies
}
opts.ShowBrowser = cmd.Bool("visible")
if cmd.IsSet("visible") {
opts.ShowBrowser = extractor.Bool(cmd.Bool("visible"))
}
return extractor.NewBrowser(ctx, opts)
}

View File

@@ -60,7 +60,7 @@ func NewInteractiveBrowser(ctx context.Context, opts ...BrowserOptions) (Interac
var thirtySeconds = 30 * time.Second
opt := mergeOptions(BrowserOptions{
UserAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:142.0) Gecko/20100101 Firefox/142.0",
Browser: BrowserChromium,
Browser: BrowserFirefox,
Timeout: &thirtySeconds,
Dimensions: Size{
Width: 1280,

View File

@@ -36,6 +36,9 @@ const (
BrowserWebKit BrowserSelection = "webkit"
)
// Bool returns a pointer to the given bool value.
func Bool(v bool) *bool { return &v }
type Size struct {
Width int
Height int
@@ -49,7 +52,7 @@ type BrowserOptions struct {
// browser into the cookie jar for each request.
CookieJar
ShowBrowser bool // If false, browser will be headless
ShowBrowser *bool // If nil, defaults to false (headless). Set to ptr to override.
Dimensions Size
DarkMode bool