Skip to content

Commit

Permalink
fix: handle browser closing event and avoid crash
Browse files Browse the repository at this point in the history
  • Loading branch information
hbollon committed Nov 11, 2021
1 parent 8aeb86d commit 70da812
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,19 @@ func launchBot(ctx context.Context) {

// Start bot routine
go func() {
defer func() {
if r := recover(); r != nil {
log.Errorf("Unknown error: %v", r)
SendMessageToElectron(
MessageOut{
Status: ERROR,
Msg: "bot crash",
Payload: fmt.Errorf("Unknown error: %v", r),
},
)
BotStruct.running = false
}
}()
rand.Seed(time.Now().Unix())
if err = BotStruct.Scheduler.CheckTime(); err == nil {
if exit := checkBotChannels(); exit {
Expand Down Expand Up @@ -265,6 +278,11 @@ func launchBot(ctx context.Context) {
default:
break
}

if ws, err := BotStruct.SeleniumStruct.WebDriver.WindowHandles(); len(ws) == 0 || err != nil {
BotStruct.SeleniumStruct.CleanUp()
return
}
time.Sleep(10 * time.Millisecond)
}
}
Expand Down

0 comments on commit 70da812

Please sign in to comment.