{"record":{"id":"99169d65f566eda4","repo":"grafana/k6","slug":"waiting-for-function-execution-context-q-not-fou","errorCode":null,"errorMessage":"waiting for function: execution context %q not found","messagePattern":"waiting for function: execution context %q not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/frame.go","lineNumber":1995,"sourceCode":"}\n\nfunc (f *Frame) waitForFunction(\n\tapiCtx context.Context, world executionWorld, js string,\n\tpolling any, timeout time.Duration, args ...any,\n) (any, error) {\n\tf.log.Debugf(\n\t\t\"Frame:waitForFunction\",\n\t\t\"fid:%s furl:%q world:%s poll:%s timeout:%s\",\n\t\tf.ID(), f.URL(), world, polling, timeout)\n\n\tf.waitForExecutionContext(world)\n\n\tf.executionContextMu.RLock()\n\tdefer f.executionContextMu.RUnlock()\n\n\texecCtx := f.executionContexts[world]\n\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}","sourceCodeStart":1977,"sourceCodeEnd":2013,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/frame.go#L1977-L2013","documentation":"Returned by Frame.waitForFunction when, after waiting for the execution context to appear, the requested world's context is still absent from the frame's context map. A navigation/teardown race: nowhere to evaluate the predicate function.","triggerScenarios":"Thrown at internal/js/modules/k6/browser/common/frame.go:1987 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Retry waitForFunction after the frame finishes loading","Wait for a lifecycle event before polling","Avoid concurrent navigation while waiting"],"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"}