Skip to content
This repository was archived by the owner on Aug 30, 2020. It is now read-only.

Commit 96bbdf0

Browse files
author
Hongze Xia
committed
update chrome timeout and ctx func
1 parent bd23b50 commit 96bbdf0

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

trackers/chrome_tracker.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
var (
15-
chromeTimeout = time.Second * 120
15+
chromeTimeout = time.Second * 60
1616
chromePath = ""
1717
chromeOpts = []chromedp.ExecAllocatorOption{
1818
chromedp.NoFirstRun,
@@ -55,9 +55,11 @@ func init() {
5555
// ChromeTracker uses headless chrome to fetch content from given url and xpath
5656
// and returns content/error message, ok
5757
func ChromeTracker(url, xpath *string) (string, bool) {
58-
allocCtx, cancel := chromedp.NewExecAllocator(context.Background(), chromeOpts...)
58+
ctx, cancel := context.WithTimeout(context.Background(), chromeTimeout)
5959
defer cancel()
60-
ctx, cancel := chromedp.NewContext(allocCtx)
60+
ctx, cancel = chromedp.NewExecAllocator(ctx, chromeOpts...)
61+
defer cancel()
62+
ctx, cancel = chromedp.NewContext(ctx)
6163
defer cancel()
6264

6365
var res string

0 commit comments

Comments
 (0)