1
0
mirror of https://github.com/MontFerret/ferret.git synced 2025-09-16 09:06:36 +02:00

WIP: Feature/#38 fix browser launcher (#246)

* switch DebuggingAddress from 0.0.0.0 -> http://0.0.0.0:9222

* rename res -> path

* change exec.Command call and args

* set default cdp value to empty string
This commit is contained in:
3timeslazy
2019-03-03 05:34:29 +03:00
committed by Tim Voronov
parent 2303eee152
commit 5188f9e71b
4 changed files with 20 additions and 15 deletions

View File

@@ -1,10 +1,11 @@
package browser
import (
"github.com/pkg/errors"
"os"
"os/exec"
"runtime"
"github.com/pkg/errors"
)
type Browser struct {
@@ -18,7 +19,7 @@ func (b *Browser) Flags() Flags {
func (b *Browser) DebuggingAddress() string {
if !b.Flags().Has("remote-debugging-address") {
b.Flags().Set("remote-debugging-address", "0.0.0.0")
b.Flags().Set("remote-debugging-address", "http://0.0.0.0:9222")
}
value, _ := b.Flags().Get("remote-debugging-address")

View File

@@ -1,14 +1,12 @@
package browser
import (
"fmt"
"os"
"os/exec"
"runtime"
)
func resolveExecutablePath() string {
var res string
func resolveExecutablePath() (path string) {
switch runtime.GOOS {
case "darwin":
@@ -17,8 +15,9 @@ func resolveExecutablePath() string {
"/Applications/Google Chrome.app",
} {
// MacOS apps are actually folders
if info, err := os.Stat(c); err == nil && info.IsDir() {
res = fmt.Sprintf("open %s -n", c)
info, err := os.Stat(c)
if err == nil && info.IsDir() {
path = c
break
}
}
@@ -31,7 +30,7 @@ func resolveExecutablePath() string {
"google-chrome-unstable",
"google-chrome-stable"} {
if _, err := exec.LookPath(c); err == nil {
res = c
path = c
break
}
}
@@ -39,5 +38,5 @@ func resolveExecutablePath() string {
case "windows":
}
return res
return
}

View File

@@ -1,12 +1,13 @@
package browser
import (
"github.com/pkg/errors"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"runtime"
"github.com/pkg/errors"
)
func Launch(setters ...Option) (*Browser, error) {
@@ -78,7 +79,10 @@ func Launch(setters ...Option) (*Browser, error) {
}
}
cmd := exec.Command(chromeExecutable, flags.List()...)
execArgs := []string{chromeExecutable, "--args"}
execArgs = append(execArgs, flags.List()...)
cmd := exec.Command("open", execArgs...)
cmd.Dir = workDir
err = cmd.Start()

View File

@@ -5,12 +5,13 @@ import (
"encoding/json"
"flag"
"fmt"
"github.com/MontFerret/ferret/cli"
"github.com/MontFerret/ferret/cli/browser"
"github.com/MontFerret/ferret/pkg/runtime/core"
"io/ioutil"
"os"
"strings"
"github.com/MontFerret/ferret/cli"
"github.com/MontFerret/ferret/cli/browser"
"github.com/MontFerret/ferret/pkg/runtime/core"
)
type Params []string
@@ -55,7 +56,7 @@ var (
conn = flag.String(
"cdp",
"http://127.0.0.1:9222",
"",
"set CDP address",
)