{"record":{"id":"fd8166c9e2af4771","repo":"grafana/k6","slug":"waiting-for-function-polling-w","errorCode":null,"errorMessage":"waiting for function, polling: %w","messagePattern":"waiting for function, polling: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/frame.go","lineNumber":2026,"sourceCode":"\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\n\t}\n\n\treturn result, nil\n}\n\n// WaitForLoadState waits for the given load state to be reached.\n// This will unblock if that lifecycle event has already been received.\nfunc (f *Frame) WaitForLoadState(state string, popts *FrameWaitForLoadStateOptions) error {\n\tf.log.Debugf(\"Frame:WaitForLoadState\", \"fid:%s furl:%q state:%s\", f.ID(), f.URL(), state)\n\tdefer f.log.Debugf(\"Frame:WaitForLoadState:return\", \"fid:%s furl:%q state:%s\", f.ID(), f.URL(), state)\n\n\ttimeoutCtx, timeoutCancel := context.WithTimeout(f.ctx, popts.Timeout)\n\tdefer timeoutCancel()\n","sourceCodeStart":2008,"sourceCodeEnd":2044,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/frame.go#L2008-L2044","documentation":"Returned by Frame.waitForFunction when invoking the injected waitForPredicateFunction (with the predicate handle, polling config and timeout) fails. The wrapped error covers the whole polling evaluation: predicate runtime exceptions surface here, as do context destruction and CDP errors.","triggerScenarios":"Thrown at internal/js/modules/k6/browser/common/frame.go:2018 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Fix runtime exceptions inside the predicate function","Use a valid polling option ('raf', 'mutation', or a number in ms)","Increase the timeout","Retry after navigation settles"],"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"}