{"record":{"id":"c2ec6eef7d81da1a","repo":"grafana/k6","slug":"evaluating-js-in-global-context-w","errorCode":null,"errorMessage":"evaluating JS in global context: %w","messagePattern":"evaluating JS in global context: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/frame.go","lineNumber":900,"sourceCode":"}\n\n// Evaluate will evaluate provided page function within an execution context.\nfunc (f *Frame) Evaluate(pageFunc string, args ...any) (any, error) {\n\tf.log.Debugf(\"Frame:Evaluate\", \"fid:%s furl:%q\", f.ID(), f.URL())\n\n\treturn f.EvaluateWithContext(f.ctx, pageFunc, args...)\n}\n\n// EvaluateGlobal will evaluate the given JS code in the global object.\nfunc (f *Frame) EvaluateGlobal(ctx context.Context, js string) error {\n\taction := runtime.Evaluate(js).WithAwaitPromise(true)\n\n\tvar (\n\t\texceptionDetails *runtime.ExceptionDetails\n\t\terr              error\n\t)\n\tif _, exceptionDetails, err = action.Do(cdp.WithExecutor(ctx, f.manager.session)); err != nil {\n\t\treturn fmt.Errorf(\"evaluating JS in global context: %w\", err)\n\t}\n\tif exceptionDetails != nil {\n\t\treturn fmt.Errorf(\"%s\", parseExceptionDetails(exceptionDetails))\n\t}\n\n\treturn nil\n}\n\n// EvaluateHandle will evaluate provided page function within an execution context.\nfunc (f *Frame) EvaluateHandle(pageFunc string, args ...any) (handle JSHandleAPI, _ error) {\n\tf.log.Debugf(\"Frame:EvaluateHandle\", \"fid:%s furl:%q\", f.ID(), f.URL())\n\n\tevalHandle := func() (JSHandleAPI, error) {\n\t\tf.executionContextMu.RLock()\n\t\tdefer f.executionContextMu.RUnlock()\n\n\t\tec := f.executionContexts[mainWorld]\n\t\tif ec == nil {","sourceCodeStart":882,"sourceCodeEnd":918,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/frame.go#L882-L918","documentation":"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).","triggerScenarios":"Thrown at internal/js/modules/k6/browser/common/frame.go:892 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the page/target is still open","Retry after the browser session stabilizes","Check for browser crash or manual page closure"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}