Skip to content

Commit

Permalink
add Launcher.StartURL option
Browse files Browse the repository at this point in the history
  • Loading branch information
ysmood committed Nov 23, 2020
1 parent ef105da commit 1792052
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
10 changes: 8 additions & 2 deletions lib/launcher/launcher.go
Expand Up @@ -42,6 +42,7 @@ type Launcher struct {
// Headless will be enabled by default.
// Leakless will be enabled by default.
// UserDataDir will use OS tmp dir by default.
// StartURL will be set to GetSelfClosePage().
func New() *Launcher {
dir := defaults.Dir
if dir == "" {
Expand All @@ -58,7 +59,7 @@ func New() *Launcher {
"headless": nil,

// to prevent welcome page
"": {getSelfClosePage()},
"": {GetSelfClosePage()},

"disable-background-networking": nil,
"disable-background-timer-throttling": nil,
Expand Down Expand Up @@ -120,7 +121,7 @@ func NewUserMode() *Launcher {
ctxCancel: cancel,
Flags: map[string][]string{
"remote-debugging-port": {"37712"},
"": {getSelfClosePage()},
"": {GetSelfClosePage()},
},
exit: make(chan struct{}),
browser: NewBrowser(),
Expand Down Expand Up @@ -259,6 +260,11 @@ func (l *Launcher) Env(env ...string) *Launcher {
return l.Set(flagEnv, env...)
}

// StartURL to launch
func (l *Launcher) StartURL(u string) *Launcher {
return l.Set("", u)
}

// FormatArgs returns the formated arg list for cli
func (l *Launcher) FormatArgs() []string {
execArgs := []string{}
Expand Down
3 changes: 3 additions & 0 deletions lib/launcher/launcher_test.go
Expand Up @@ -103,6 +103,8 @@ func (t T) Launch() {
}

func (t T) LaunchUserMode() {
_ = os.Remove(launcher.GetSelfClosePage())

l := launcher.NewUserMode()
defer l.Kill()

Expand All @@ -122,6 +124,7 @@ func (t T) LaunchUserMode() {
Leakless(false).Leakless(true).
Headless(false).Headless(true).RemoteDebuggingPort(port).
Devtools(true).Devtools(false).
StartURL("about:blank").
Proxy("test.com").
UserDataDir("test").UserDataDir(dir).
WorkingDir("").
Expand Down
3 changes: 2 additions & 1 deletion lib/launcher/utils.go
Expand Up @@ -113,7 +113,8 @@ func unzip(logger io.Writer, from, to string) (err error) {
return zr.Close()
}

func getSelfClosePage() string {
// GetSelfClosePage returns an absolute file path of page that will close it self after it's opened.
func GetSelfClosePage() string {
path := filepath.Join(os.TempDir(), "rod", "self-close.html")

if !utils.FileExists(path) {
Expand Down

0 comments on commit 1792052

Please sign in to comment.