Skip to content

Commit

Permalink
fix browser event leaking
Browse files Browse the repository at this point in the history
  • Loading branch information
ysmood committed Apr 29, 2022
1 parent 9159a0d commit e61bef5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,10 +432,12 @@ func (b *Browser) Event() <-chan *Message {
}

func (b *Browser) initEvents() {
b.event = goob.New(b.ctx)
ctx, cancel := context.WithCancel(b.ctx)
b.event = goob.New(ctx)
event := b.client.Event()

go func() {
defer cancel()
for e := range event {
b.event.Publish(&Message{
SessionID: proto.TargetSessionID(e.SessionID),
Expand Down
15 changes: 15 additions & 0 deletions browser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,3 +452,18 @@ func TestOldBrowser(t *testing.T) {
g.E(err)
g.Eq(res.Revision, "@19d4547535ab5aba70b4730443f84e8153052174")
}

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

l := launcher.New()
p := rod.New().ControlURL(l.MustLaunch()).MustConnect().MustPage(g.blank())

go func() {
utils.Sleep(1)
l.Kill()
}()

_, err := p.Eval(`() => new Promise(r => {})`)
g.Err(err)
}

0 comments on commit e61bef5

Please sign in to comment.