Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit 8fc2666

Browse files
committed
Add error handling for Dispose
Dispose can panic when a navigation occurs on a page with an iframe. The specific error that is returned is "Cannot find context with specified id". The reason for this error is due to the fact that Chrome has already cleaned up the associated resource before it receives the CDP command to release it. Therefore it is safe to handle this error, log a debug log and carry on with the test.
1 parent 51a2f1e commit 8fc2666

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

common/js_handle.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"strings"
78

89
"github.com/grafana/xk6-browser/k6ext"
910
"github.com/grafana/xk6-browser/log"
@@ -88,6 +89,14 @@ func (h *BaseJSHandle) Dispose() {
8889
h.logger.Debugf("BaseJSHandle:Dispose", "%v", err)
8990
return
9091
}
92+
// The following error indicates that the object we're trying to release
93+
// cannot be found, which would mean that the object has already been
94+
// removed/deleted. This can occur when a navigation occurs, usually when
95+
// a page contains an iframe.
96+
if strings.Contains(err.Error(), "Cannot find context with specified id") {
97+
h.logger.Debugf("BaseJSHandle:Dispose", "%v", err)
98+
return
99+
}
91100

92101
k6ext.Panic(h.ctx, "dispose: %w", err)
93102
}

0 commit comments

Comments
 (0)