grafana/k6 · error
evaluating JS in global context
Error message
evaluating JS in global context: %w
What it means
Returned by Frame.EvaluateGlobal when the raw runtime.Evaluate CDP call (no execution-context wrapper, global object scope) fails at the transport/session level. Distinct from exceptionDetails handling below it: this indicates the CDP request itself errored (session closed, target gone).
Solutions
- Ensure the page/target is still open
- Retry after the browser session stabilizes
- Check for browser crash or manual page closure
Defensive patterns
Strategy: retry
When it happens
Trigger: Thrown at internal/js/modules/k6/browser/common/frame.go:892 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of grafana/k6@3fcf5388d7 (2026-08-18).
Data as JSON: /api/errors/c2ec6eef7d81da1a.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/browser/common/frame.go:900
}
// Evaluate will evaluate provided page function within an execution context.
func (f *Frame) Evaluate(pageFunc string, args ...any) (any, error) {
f.log.Debugf("Frame:Evaluate", "fid:%s furl:%q", f.ID(), f.URL())
return f.EvaluateWithContext(f.ctx, pageFunc, args...)
}
// EvaluateGlobal will evaluate the given JS code in the global object.
func (f *Frame) EvaluateGlobal(ctx context.Context, js string) error {
action := runtime.Evaluate(js).WithAwaitPromise(true)
var (
exceptionDetails *runtime.ExceptionDetails
err error
)
if _, exceptionDetails, err = action.Do(cdp.WithExecutor(ctx, f.manager.session)); err != nil {
return fmt.Errorf("evaluating JS in global context: %w", err)
}
if exceptionDetails != nil {
return fmt.Errorf("%s", parseExceptionDetails(exceptionDetails))
}
return nil
}
// EvaluateHandle will evaluate provided page function within an execution context.
func (f *Frame) EvaluateHandle(pageFunc string, args ...any) (handle JSHandleAPI, _ error) {
f.log.Debugf("Frame:EvaluateHandle", "fid:%s furl:%q", f.ID(), f.URL())
evalHandle := func() (JSHandleAPI, error) {
f.executionContextMu.RLock()
defer f.executionContextMu.RUnlock()
ec := f.executionContexts[mainWorld]
if ec == nil {View on GitHub (pinned to 3fcf5388d7)