grafana/k6 · warning
disposing element with ID %s: %w
Error message
disposing element with ID %s: %w
What it means
BaseJSHandle.Dispose releases the handle's remote object via Runtime.releaseObject. Two benign failures are detected by message and swallowed: 'Execution context was destroyed' and 'Cannot find context with specified id' (the object is already gone, typically after navigation or with iframes). This error therefore means ReleaseObject failed for some other reason and the object could not be released.
Source
Thrown at internal/js/modules/k6/browser/common/js_handle.go:114
// We do not want to return an error when the error is a closed
// 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) {
h.logger.Debugf("BaseJSHandle:Dispose", "%v", err)
return nil
}
// 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 nil
}
return fmt.Errorf("disposing element with ID %s: %w", h.remoteObject.ObjectID, err)
}
// dispose sends a command to the browser to release the remote object.
func (h *BaseJSHandle) dispose() error {
if h.disposed {
return nil
}
h.disposed = true
if h.remoteObject.ObjectID == "" {
return nil
}
act := runtime.ReleaseObject(h.remoteObject.ObjectID)
if err := act.Do(cdp.WithExecutor(h.ctx, h.session)); err != nil {
return fmt.Errorf("disposing element with ID %s: %w",
h.remoteObject.ObjectID, err)
}
return nilView on GitHub (pinned to 93accf6570)
Solutions
- Dispose handles promptly, before navigation destroys their execution context
- During teardown after the browser is going away, treat this as non-fatal and log it rather than failing the test
- Check for concurrent CDP errors to identify a dropped connection and fix that root cause
- Upgrade k6: dispose error handling has been refined over releases
Defensive patterns
Strategy: fallback
Try / catch
try { await handle.dispose(); }
catch (e) {
if (/disposing element with ID/.test(String(e.message))) { /* log and continue; object leak is harmless short-term */ }
else throw e;
} Prevention
- Dispose handles before navigating away from their context
- Treat dispose failures during final teardown as non-fatal
- Investigate accompanying CDP errors to find connection drops
When it happens
Trigger: Calling handle.dispose() (directly or via disposal paths like Frame cleanup) when the CDP call fails with a non-benign error: the DevTools session dropped, the browser died, or the object belongs to a context that was replaced but the error text differs from the swallowed cases.
Common situations: Disposing element/JS handles late in the iteration; iframe-heavy pages where contexts churn during navigation; browser disconnect during teardown; parallel load causing transport failures.
Related errors
- selectHandle.dispose: %w
- attaching new page: %w
- optionHandle.dispose: %w
- attaching worker target ID %v to session ID %v: %w
- evaluating handle for element: %w
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/aa381477f6566271.
Report an issue: GitHub.