Skip to content

Commit

Permalink
fix: may hang on unexpect browser close
Browse files Browse the repository at this point in the history
  • Loading branch information
canstand committed Jun 3, 2023
1 parent a005a36 commit ef85afe
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions browser_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func (b *browserTypeImpl) Connect(url string, options ...BrowserTypeConnectOptio
context.(*browserContextImpl).onClose()
}
browser.onClose()
connection.cleanup()
}
jsonPipe.On("closed", pipeClosed)
connection.onmessage = func(message map[string]interface{}) error {
Expand Down
21 changes: 20 additions & 1 deletion connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,26 @@ func (c *connection) Start() *Playwright {
}

func (c *connection) Stop() error {
return c.onClose()
err := c.onClose()
if err != nil {
return err
}
c.cleanup()
return nil
}

func (c *connection) cleanup() {
c.callbacks.Range(func(key, value any) bool {
select {
case value.(chan callback) <- callback{
Error: &Error{
Name: "Error",
Message: "Connection closed",
}}:
default:
}
return true
})
}

func (c *connection) Dispatch(msg *message) {
Expand Down

0 comments on commit ef85afe

Please sign in to comment.