Skip to content

Commit

Permalink
feat: add Launcher.Client (#874)
Browse files Browse the repository at this point in the history
* feat: add Launcher.Client

* add Launcher.Client test

* fix CI test
  • Loading branch information
Fly-Playgroud committed May 14, 2023
1 parent 763929b commit f76a7b2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/launcher/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,18 @@ func (l *Launcher) JSON() []byte {
return utils.MustToJSONBytes(l)
}

// MustClient for launching browser remotely via the launcher.Manager.
// MustClient similar to Launcher.Client
func (l *Launcher) MustClient() *cdp.Client {
u, h := l.ClientHeader()
return cdp.MustStartWithURL(l.ctx, u, h)
}

// Client for launching browser remotely via the launcher.Manager.
func (l *Launcher) Client() (*cdp.Client, error) {
u, h := l.ClientHeader()
return cdp.StartWithURL(l.ctx, u, h)
}

// ClientHeader for launching browser remotely via the launcher.Manager.
func (l *Launcher) ClientHeader() (string, http.Header) {
l.mustManaged()
Expand Down
17 changes: 17 additions & 0 deletions lib/launcher/private_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,20 @@ func TestTestOpen(_ *testing.T) {

Open("about:blank")
}

func TestLaunchClient(t *testing.T) {
g := setup(t)

ctx := g.Timeout(5 * time.Second)

s := got.New(g).Serve()
rl := NewManager()
s.Mux.Handle("/", rl)

l := MustNewManaged(s.URL()).KeepUserDataDir().Delete(flags.KeepUserDataDir)
c, err := l.Client()
if err != nil {
g.Err(err)
}
g.E(c.Call(ctx, "", "Browser.getVersion", nil))
}

0 comments on commit f76a7b2

Please sign in to comment.