From 4efda70970d0aa16415ccb1791b856e9dac71c16 Mon Sep 17 00:00:00 2001 From: Yad Smood Date: Wed, 17 Apr 2024 11:34:11 +0800 Subject: [PATCH] fix: shouldn't reset the user preferences by default Resolve #1041 --- lib/launcher/launcher.go | 8 ++++++-- lib/launcher/launcher_test.go | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/launcher/launcher.go b/lib/launcher/launcher.go index 11df4518..b8545821 100644 --- a/lib/launcher/launcher.go +++ b/lib/launcher/launcher.go @@ -68,8 +68,6 @@ func New() *Launcher { // enable headless by default flags.Headless: nil, - flags.Preferences: {`{"plugins":{"always_open_pdf_externally": true}}`}, - // to disable the init blank window "no-first-run": nil, "no-startup-window": nil, @@ -255,6 +253,12 @@ func (l *Launcher) Preferences(pref string) *Launcher { return l.Set(flags.Preferences, pref) } +// AlwaysOpenPDFExternally switch. +// It will set chromium user preferences to enable the always_open_pdf_externally option. +func (l *Launcher) AlwaysOpenPDFExternally() *Launcher { + return l.Set(flags.Preferences, `{"plugins":{"always_open_pdf_externally": true}}`) +} + // Leakless switch. If enabled, the browser will be force killed after the Go process exits. // The doc of leakless: https://github.com/ysmood/leakless. func (l *Launcher) Leakless(enable bool) *Launcher { diff --git a/lib/launcher/launcher_test.go b/lib/launcher/launcher_test.go index 60a2b817..eeb67ba9 100644 --- a/lib/launcher/launcher_test.go +++ b/lib/launcher/launcher_test.go @@ -65,7 +65,7 @@ func TestLaunch(t *testing.T) { defaults.Proxy = "test.com" defer func() { defaults.ResetWith("") }() - l := launcher.New().Preferences("") + l := launcher.New().Preferences("").AlwaysOpenPDFExternally() defer l.Kill() u := l.MustLaunch()