@@ -8,17 +8,19 @@ import (
88 "strings"
99 "time"
1010
11+ "github.com/chromedp/cdproto/page"
1112 "github.com/chromedp/chromedp"
1213)
1314
1415var (
15- chromeTimeout = time .Second * 60
16+ chromeTimeout = time .Second * 10
1617 chromeOpts = []chromedp.ExecAllocatorOption {
1718 chromedp .NoFirstRun ,
1819 chromedp .NoDefaultBrowserCheck ,
1920 chromedp .Headless ,
2021 chromedp .DisableGPU ,
2122 chromedp .Flag ("enable-automation" , false ),
23+ chromedp .UserAgent (`Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36` ),
2224 chromedp .Flag ("disable-background-networking" , true ),
2325 chromedp .Flag ("disable-background-timer-throttling" , true ),
2426 chromedp .Flag ("disable-backgrounding-occluded-windows" , true ),
3537 chromedp .Flag ("disable-renderer-backgrounding" , true ),
3638 chromedp .Flag ("disable-sync" , true ),
3739 }
40+ /**
41+ * Hard research to find out how to hide the automation mode
42+ * https://github.com/chromedp/chromedp/issues/396
43+ * https://intoli.com/blog/not-possible-to-block-chrome-headless/
44+ **/
45+ hiddenScript = `
46+ Object.defineProperty(navigator, 'webdriver', {
47+ get: () => false,
48+ });`
49+ hide = chromedp .ActionFunc (func (ctx context.Context ) error {
50+ _ , err := page .AddScriptToEvaluateOnNewDocument (hiddenScript ).Do (ctx )
51+ if err != nil {
52+ return err
53+ }
54+ // log.Println("identifier: ", identifier.String())
55+ return nil
56+ })
3857)
3958
4059func init () {
@@ -59,10 +78,15 @@ func ChromeTracker(url, xpath *string) (string, bool) {
5978 defer cancel ()
6079
6180 var res string
62- err := chromedp .Run (ctx , chromedp .Navigate (* url ), chromedp .Text (* xpath , & res , chromedp .NodeVisible , chromedp .BySearch ))
81+
82+ err := chromedp .Run (ctx ,
83+ hide ,
84+ chromedp .Navigate (* url ),
85+ chromedp .Text (* xpath , & res , chromedp .NodeVisible , chromedp .BySearch ),
86+ )
6387
6488 if err != nil {
65- log .Fatal ( err )
89+ log .Printf ( "WARN: failed to fetch with chromedp with %v" , err )
6690 }
6791
6892 return strings .TrimSpace (res ), true
0 commit comments