{"record":{"id":"0c388c2f1106eeec","repo":"grafana/k6","slug":"evaluating-js-w","errorCode":null,"errorMessage":"evaluating JS: %w","messagePattern":"evaluating JS: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/frame.go","lineNumber":876,"sourceCode":"\n\treturn nil\n}\n\n// EvaluateWithContext will evaluate provided page function within an execution context.\n// The passed in context will be used instead of the frame's context. The context must\n// be a derivative of one that contains the sobek runtime.\nfunc (f *Frame) EvaluateWithContext(ctx context.Context, pageFunc string, args ...any) (any, error) {\n\tf.log.Debugf(\"Frame:EvaluateWithContext\", \"fid:%s furl:%q\", f.ID(), f.URL())\n\n\tf.waitForExecutionContext(mainWorld)\n\n\topts := evalOptions{\n\t\tforceCallable: true,\n\t\treturnByValue: true,\n\t}\n\tresult, err := f.evaluate(ctx, mainWorld, opts, pageFunc, args...)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"evaluating JS: %w\", err)\n\t}\n\n\tapplySlowMo(ctx)\n\n\treturn result, nil\n}\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","sourceCodeStart":858,"sourceCodeEnd":894,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/frame.go#L858-L894","documentation":"Returned by Frame.EvaluateWithContext when evaluating the provided page function in the frame's main world fails. The wrapped error is the evaluation failure: JS exception in the page function, destroyed execution context, argument conversion failure, or a CDP error.","triggerScenarios":"Thrown at internal/js/modules/k6/browser/common/frame.go:868 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Fix JS exceptions in the evaluated page function (check error text)","Evaluate after the frame loads; retry post-navigation","Pass only serializable arguments"],"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"}