Skip to content

Commit b54f6ce

Browse files
committed
Adds verbose flag, timeout context to geteventlisteners
1 parent a9e645c commit b54f6ce

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

geteventlisteners/main.go

+14
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"regexp"
1111
"strconv"
1212
"strings"
13+
"time"
1314

1415
"github.com/chromedp/chromedp"
1516
"github.com/ditashi/jsbeautifier-go/jsbeautifier"
@@ -42,6 +43,9 @@ func main() {
4243
flag.Var(&filters, "filter", "")
4344
flag.Var(&filters, "f", "")
4445

46+
var verbose bool
47+
flag.BoolVar(&verbose, "v", false, "verbose mode")
48+
4549
flag.Parse()
4650

4751
// default to stdin unless we have an arg to use
@@ -57,10 +61,16 @@ func main() {
5761

5862
for sc.Scan() {
5963
ctx, cancel := chromedp.NewContext(parent)
64+
ctx, cancel = context.WithTimeout(ctx, time.Second*20)
65+
6066
requestURL := sc.Text()
6167

6268
var res map[string][]string
6369

70+
if verbose {
71+
fmt.Printf("requesting %s\n", requestURL)
72+
}
73+
6474
err := chromedp.Run(ctx,
6575
chromedp.Navigate(requestURL),
6676
chromedp.EvaluateAsDevTools(`
@@ -78,6 +88,7 @@ func main() {
7888

7989
if err != nil {
8090
cancel()
91+
// TODO: handle websocket timeout issue
8192
fmt.Fprintf(os.Stderr, "%s\n", err)
8293
continue
8394
}
@@ -115,6 +126,9 @@ func main() {
115126

116127
if first {
117128
// we didn't find any matching event listeners
129+
if verbose {
130+
fmt.Printf("no matching listeners on %s\n", requestURL)
131+
}
118132
cancel()
119133
continue
120134
}

0 commit comments

Comments
 (0)