feat(chromium): deprecate --chromium-user-agent property, add userAgent form field

This commit is contained in:
Julien Neuhart
2021-11-21 14:11:39 +01:00
parent 704dfc25e6
commit 4525cb38e4
4 changed files with 25 additions and 3 deletions

View File

@@ -61,6 +61,10 @@ type Chromium struct {
// Options are the available options for converting HTML document to PDF.
type Options struct {
// UserAgent overrides the default User-Agent header.
// Optional.
UserAgent string
// WaitDelay is the duration to wait when loading an HTML document before
// converting it to PDF.
// Optional.
@@ -143,6 +147,7 @@ type Options struct {
// DefaultOptions returns the default values for Options.
func DefaultOptions() Options {
return Options{
UserAgent: "",
WaitDelay: 0,
WaitWindowStatus: "",
ExtraHTTPHeaders: nil,
@@ -194,6 +199,11 @@ func (mod Chromium) Descriptor() gotenberg.ModuleDescriptor {
fs.String("chromium-deny-list", "^file:///[^tmp].*", "Set the denied URLs for Chromium using a regular expression")
fs.Bool("chromium-disable-routes", false, "Disable the routes")
err := fs.MarkDeprecated("chromium-user-agent", "use the userAgent form field instead")
if err != nil {
panic(fmt.Errorf("create deprecated flags for chromium module: %v", err))
}
return fs
}(),
New: func() gotenberg.Module { return new(Chromium) },
@@ -302,7 +312,8 @@ func (mod Chromium) PDF(ctx context.Context, logger *zap.Logger, URL, outputPath
chromedp.UserDataDir(userProfileDirPath),
)
if mod.userAgent != "" {
if mod.userAgent != "" && options.UserAgent == "" {
// Deprecated.
args = append(args, chromedp.UserAgent(mod.userAgent))
}
@@ -328,6 +339,10 @@ func (mod Chromium) PDF(ctx context.Context, logger *zap.Logger, URL, outputPath
args = append(args, chromedp.ProxyServer(mod.proxyServer))
}
if options.UserAgent != "" {
args = append(args, chromedp.UserAgent(options.UserAgent))
}
allocatorCtx, cancel := chromedp.NewExecAllocator(ctx, args...)
defer cancel()