Skip to content

Commit 8a68464

Browse files
authored
feat(go): add a load-wait config option (#796)
1 parent adca8c0 commit 8a68464

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

pkg/config/config.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,9 @@ type BrowserConfig struct {
315315
TimeBetweenScrolls time.Duration
316316
// ReadinessTimeout is the maximum time to wait for the web-page to become ready (i.e. no longer loading anything).
317317
ReadinessTimeout time.Duration
318+
// LoadWait is the time to wait before checking for how ready the page is.
319+
// This lets you force the webpage to take a beat and just do its thing before the service starts looking for whether it's time to render anything.
320+
LoadWait time.Duration
318321

319322
// MinWidth is the minimum width of the browser viewport.
320323
// If larger than MaxWidth, MaxWidth is used instead.
@@ -402,6 +405,12 @@ func BrowserFlags() []cli.Flag {
402405
Value: time.Second * 30,
403406
Sources: FromConfig("browser.readiness-timeout", "BROWSER_READINESS_TIMEOUT"),
404407
},
408+
&cli.DurationFlag{
409+
Name: "browser.load-wait",
410+
Usage: "The time to wait before checking for how ready the page is. This lets you force the webpage to take a beat and just do its thing before the service starts looking for whether it's time to render anything.",
411+
Value: time.Second,
412+
Sources: FromConfig("browser.load-wait", "BROWSER_LOAD_WAIT"),
413+
},
405414
&cli.IntFlag{
406415
Name: "browser.min-width",
407416
Usage: "The minimum width of the browser viewport. This is the default width in requests.",
@@ -504,6 +513,7 @@ func BrowserConfigFromCommand(c *cli.Command) (BrowserConfig, error) {
504513
Headers: headers,
505514
TimeBetweenScrolls: c.Duration("browser.time-between-scrolls"),
506515
ReadinessTimeout: c.Duration("browser.readiness-timeout"),
516+
LoadWait: c.Duration("browser.load-wait"),
507517
MinWidth: minWidth,
508518
MinHeight: minHeight,
509519
MaxWidth: maxWidth,

pkg/service/browser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ func (s *BrowserService) Render(ctx context.Context, url string, printer Printer
240240
tracingAction("Navigate", chromedp.Navigate(url)),
241241
tracingAction("WaitReady(body)", chromedp.WaitReady("body", chromedp.ByQuery)), // wait for a body to exist; this is when the page has started to actually render
242242
scrollForElements(cfg.TimeBetweenScrolls),
243-
waitForDuration(time.Second),
243+
waitForDuration(cfg.LoadWait),
244244
waitForReady(browserCtx, cfg.ReadinessTimeout),
245245
printer.prepare(cfg),
246246
printer.action(fileChan, cfg),

0 commit comments

Comments
 (0)