Skip to content

Commit

Permalink
Avoid closing browser when executed remotely
Browse files Browse the repository at this point in the history
Modifies the Browser.Close implementation in order to avoid sending the
Close CDP cmd when the browser is being executed remotely.
  • Loading branch information
ka3de committed Mar 2, 2023
1 parent 7e30eb5 commit 8a331f2
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions common/browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package common

import (
"context"
"errors"
"fmt"
"strings"
"sync"
Expand Down Expand Up @@ -410,11 +411,12 @@ func (b *Browser) Close() {
b.conn.IgnoreIOErrors()
b.browserProc.GracefulClose()

// Send the Browser.close CDP command, which triggers the browser process to
// exit.
action := cdpbrowser.Close()
if err := action.Do(cdp.WithExecutor(b.ctx, b.conn)); err != nil {
if _, ok := err.(*websocket.CloseError); !ok {
// If the browser is not being executed remotely, send the Browser.close CDP
// command, which triggers the browser process to exit.
if !b.launchOpts.isRemoteBrowser {
var closeErr *websocket.CloseError
err := cdpbrowser.Close().Do(cdp.WithExecutor(b.ctx, b.conn))
if err != nil && !errors.As(err, &closeErr) {
k6ext.Panic(b.ctx, "closing the browser: %v", err)
}
}
Expand Down

0 comments on commit 8a331f2

Please sign in to comment.