{"record":{"id":"d6aa88e086833d9e","repo":"grafana/k6","slug":"waiting-for-function-getting-handle-w","errorCode":null,"errorMessage":"waiting for function, getting handle: %w","messagePattern":"waiting for function, getting handle: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/frame.go","lineNumber":2012,"sourceCode":"\tif execCtx == nil {\n\t\treturn nil, fmt.Errorf(\"waiting for function: execution context %q not found\", world)\n\t}\n\tinjected, err := execCtx.getInjectedScript(apiCtx)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"getting injected script: %w\", err)\n\t}\n\n\tpageFn := `\n\t\t(injected, predicate, polling, timeout, ...args) => {\n\t\t\treturn injected.waitForPredicateFunction(predicate, polling, timeout, ...args);\n\t\t}\n\t`\n\n\t// First evaluate the predicate function itself to get its handle.\n\topts := evalOptions{forceCallable: false, returnByValue: false}\n\thandle, err := execCtx.eval(apiCtx, opts, js)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"waiting for function, getting handle: %w\", err)\n\t}\n\n\t// Then evaluate the injected function call, passing it the predicate\n\t// function handle and the rest of the arguments.\n\topts = evalOptions{forceCallable: true, returnByValue: false}\n\tresult, err := execCtx.eval(\n\t\tapiCtx, opts, pageFn, append([]any{\n\t\t\tinjected,\n\t\t\thandle,\n\t\t\tpolling,\n\t\t\ttimeout.Milliseconds(), // The JS value is in ms integers\n\t\t}, args...)...)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"waiting for function, polling: %w\", err)\n\t}\n\t// prevent passing a non-nil interface to the upper layers.\n\tif result == nil {\n\t\treturn nil, nil //nolint:nilnil","sourceCodeStart":1994,"sourceCodeEnd":2030,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/frame.go#L1994-L2030","documentation":"Returned by Frame.waitForFunction when evaluating the user's predicate function itself (to obtain its handle) fails in the chosen world. The wrapped error is the evaluation failure: JS syntax/runtime error in the predicate, or a destroyed context.","triggerScenarios":"Thrown at internal/js/modules/k6/browser/common/frame.go:2004 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Fix syntax errors in the predicate function string","Retry after the frame stabilizes","Ensure the predicate is a function expression, not a statement"],"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"}