diff --git a/common/js_handle.go b/common/js_handle.go index d021d7eb4..f52469e24 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" @@ -84,9 +85,20 @@ func (h *BaseJSHandle) Dispose() { // context. The reason the context would be closed is due to the // iteration ending and therefore the associated browser and its assets // will be automatically deleted. - if !errors.Is(err, context.Canceled) { - k6ext.Panic(h.ctx, "dispose: %w", err) + if errors.Is(err, context.Canceled) { + h.logger.Debugf("BaseJSHandle:Dispose", "%v", err) + return } + // 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) + return + } + + k6ext.Panic(h.ctx, "dispose: %w", err) } }