From 7e42ae944429ed77604190e695b2212af470712e Mon Sep 17 00:00:00 2001 From: ankur22 Date: Mon, 29 Apr 2024 16:32:57 +0100 Subject: [PATCH] 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. --- common/js_handle.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/common/js_handle.go b/common/js_handle.go index 1eef5f1b0..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" @@ -88,6 +89,14 @@ func (h *BaseJSHandle) Dispose() { 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) }