diff --git a/common/js_handle.go b/common/js_handle.go index 26697ea70..3d579397f 100644 --- a/common/js_handle.go +++ b/common/js_handle.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "strings" "github.com/grafana/xk6-browser/k6ext" "github.com/grafana/xk6-browser/log" @@ -87,6 +88,13 @@ func (h *BaseJSHandle) Dispose() { if errors.Is(err, context.Canceled) { h.logger.Debugf("BaseJSHandle:Dispose", "%v", err) } + // The following error indicates that the object we're trying to release + // cannot be found, which would mean that the object has already been + // removed/deleted. This can occur when a navigation occurs, usually when + // a page contains an iframe. + if strings.Contains(err.Error(), "Cannot find context with specified id") { + h.logger.Debugf("BaseJSHandle:Dispose", "%v", err) + } k6ext.Panic(h.ctx, "dispose: %w", err) }