From 369fc38c4396c391c80b7600deee7e600b8a69a9 Mon Sep 17 00:00:00 2001 From: Ivan Krutov Date: Thu, 20 Jun 2019 17:19:53 +0300 Subject: [PATCH] Supporting latest Chrome versions in devtools --- selenium/chrome/devtools/devtools.go | 53 +++++++++++++++------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/selenium/chrome/devtools/devtools.go b/selenium/chrome/devtools/devtools.go index 1ed2b101d..68da3f097 100644 --- a/selenium/chrome/devtools/devtools.go +++ b/selenium/chrome/devtools/devtools.go @@ -118,31 +118,36 @@ func getPageWebSocketUrl(targetId string) (*url.URL, error) { } func detectDevtoolsHost(baseDir string) string { - candidates, err := filepath.Glob(filepath.Join(baseDir, ".org.chromium.Chromium*")) - if err == nil { - for _, c := range candidates { - f, err := os.Stat(c) - if err != nil { - continue - } - if !f.IsDir() { - continue - } - portFile := filepath.Join(c, "DevToolsActivePort") - data, err := ioutil.ReadFile(portFile) - if err != nil { - continue - } - lines := strings.Split(string(data), "\n") - if len(lines) == 0 { - continue - } - port, err := strconv.Atoi(lines[0]) - if err != nil { - continue - } - return fmt.Sprintf("127.0.0.1:%d", port) + var candidates []string + for _, glob := range []string{".com.google.Chrome*", ".org.chromium.Chromium*"} { + cds, err := filepath.Glob(filepath.Join(baseDir, glob)) + if err == nil { + candidates = append(candidates, cds...) + } + + } + for _, c := range candidates { + f, err := os.Stat(c) + if err != nil { + continue + } + if !f.IsDir() { + continue + } + portFile := filepath.Join(c, "DevToolsActivePort") + data, err := ioutil.ReadFile(portFile) + if err != nil { + continue + } + lines := strings.Split(string(data), "\n") + if len(lines) == 0 { + continue + } + port, err := strconv.Atoi(lines[0]) + if err != nil { + continue } + return fmt.Sprintf("127.0.0.1:%d", port) } return devtoolsHost }