fix(chromium): hypen-data now work everytime

This commit is contained in:
Julien Neuhart
2025-08-12 20:48:00 +02:00
parent 8d795a4317
commit db8f0ad9ee
57 changed files with 36 additions and 1 deletions

View File

@@ -39,6 +39,7 @@ type browserArguments struct {
hostResolverRules string
proxyServer string
wsUrlReadTimeout time.Duration
hyphenDataDirPath string
// Tasks specific.
allowList *regexp2.Regexp
@@ -79,6 +80,16 @@ func (b *chromiumBrowser) Start(logger *zap.Logger) error {
debug := &debugLogger{logger: logger}
b.userProfileDirPath = b.fs.NewDirPath()
// See https://github.com/gotenberg/gotenberg/issues/1293.
err := os.MkdirAll(b.userProfileDirPath, 0o755)
if err != nil {
return fmt.Errorf("could not create user profile directory: %w", err)
}
err = os.Symlink(b.arguments.hyphenDataDirPath, fmt.Sprintf("%s/hyphen-data", b.userProfileDirPath))
if err != nil {
return fmt.Errorf("create symlink to hyphen-data directory: %w", err)
}
opts := append(chromedp.DefaultExecAllocatorOptions[:],
chromedp.CombinedOutput(debug),
chromedp.ExecPath(b.arguments.binPath),
@@ -93,6 +104,8 @@ func (b *chromiumBrowser) Start(logger *zap.Logger) error {
// See https://github.com/gotenberg/gotenberg/issues/1177.
chromedp.Flag("no-zygote", true),
chromedp.Flag("disable-dev-shm-usage", true),
// See https://github.com/gotenberg/gotenberg/issues/1293.
chromedp.Flag("disable-component-update", false),
)
if b.arguments.incognito {
@@ -133,7 +146,7 @@ func (b *chromiumBrowser) Start(logger *zap.Logger) error {
allocatorCtx, allocatorCancel := chromedp.NewExecAllocator(b.initialCtx, opts...)
ctx, cancel := chromedp.NewContext(allocatorCtx, chromedp.WithDebugf(debug.Printf))
err := chromedp.Run(ctx)
err = chromedp.Run(ctx)
if err != nil {
cancel()
allocatorCancel()

View File

@@ -395,6 +395,11 @@ func (mod *Chromium) Provision(ctx *gotenberg.Context) error {
return errors.New("CHROMIUM_BIN_PATH environment variable is not set")
}
hyphenDataDirPath, ok := os.LookupEnv("CHROMIUM_HYPHEN_DATA_DIR_PATH")
if !ok {
return errors.New("CHROMIUM_HYPHEN_DATA_DIR_PATH environment variable is not set")
}
mod.args = browserArguments{
binPath: binPath,
incognito: flags.MustBool("chromium-incognito"),
@@ -405,6 +410,7 @@ func (mod *Chromium) Provision(ctx *gotenberg.Context) error {
hostResolverRules: flags.MustString("chromium-host-resolver-rules"),
proxyServer: flags.MustString("chromium-proxy-server"),
wsUrlReadTimeout: flags.MustDuration("chromium-start-timeout"),
hyphenDataDirPath: hyphenDataDirPath,
allowList: flags.MustRegexp("chromium-allow-list"),
denyList: flags.MustRegexp("chromium-deny-list"),
@@ -449,6 +455,11 @@ func (mod *Chromium) Validate() error {
return fmt.Errorf("chromium binary path does not exist: %w", err)
}
_, err = os.Stat(mod.args.hyphenDataDirPath)
if os.IsNotExist(err) {
return fmt.Errorf("chromium hyphen-data directory path does not exist: %w", err)
}
return nil
}