{"record":{"id":"063a39b9d71a5749","repo":"grafana/k6","slug":"execution-context-q-not-found","errorCode":null,"errorMessage":"execution context %q not found","messagePattern":"execution context %q not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/frame.go","lineNumber":2252,"sourceCode":"\tnavOpts := &FrameWaitForNavigationOptions{\n\t\tURL:       urlPattern,\n\t\tTimeout:   opts.Timeout,\n\t\tWaitUntil: opts.WaitUntil,\n\t}\n\t_, err = f.WaitForNavigation(navOpts, rm)\n\n\treturn err\n}\n\nfunc (f *Frame) adoptBackendNodeID(world executionWorld, id cdp.BackendNodeID) (*ElementHandle, error) {\n\tf.log.Debugf(\"Frame:adoptBackendNodeID\", \"fid:%s furl:%q world:%s id:%d\", f.ID(), f.URL(), world, id)\n\n\tf.executionContextMu.RLock()\n\tdefer f.executionContextMu.RUnlock()\n\n\tec := f.executionContexts[world]\n\tif ec == nil {\n\t\treturn nil, fmt.Errorf(\"execution context %q not found\", world)\n\t}\n\treturn ec.adoptBackendNodeID(id)\n}\n\nfunc (f *Frame) evaluate(\n\tapiCtx context.Context,\n\tworld executionWorld,\n\topts evalOptions, pageFunc string, args ...any,\n) (any, error) {\n\tf.log.Debugf(\"Frame:evaluate\", \"fid:%s furl:%q world:%s opts:%s\", f.ID(), f.URL(), world, opts)\n\n\tf.executionContextMu.RLock()\n\tdefer f.executionContextMu.RUnlock()\n\n\tec := f.executionContexts[world]\n\tif ec == nil {\n\t\treturn nil, fmt.Errorf(\"execution context %q not found\", world)\n\t}","sourceCodeStart":2234,"sourceCodeEnd":2270,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/frame.go#L2234-L2270","documentation":"Internal error from Frame.adoptBackendNodeID: the frame's execution-context map has no context for the requested world (main or utility) at lookup time. The map is populated when the browser sends Runtime.executionContextCreated and cleared on destruction, so the error means the world's context does not exist right now. Users normally hit it indirectly through element/handle operations that adopt a backend node.","triggerScenarios":"Adopting a node while the frame is mid-navigation (old contexts destroyed, new not yet created); operating on a frame that was just attached but whose utility world has not been initialized; pages where the utility world is not enabled; racing page.close().","commonSituations":"Element handles obtained before a navigation being used after it; k6 browser-module races around navigation in older versions (several were fixed over time); scripts that stash handles across page transitions.","solutions":["Re-acquire elements after every navigation instead of reusing handles from the previous document","await page.waitForLoadState('domcontentloaded') before touching elements after goto","Upgrade k6 — several execution-context race conditions in this area have been fixed in newer releases","If it reproduces reliably, capture debug logs (--log-output=logger=stderr -v environment=DEBUG) and report with a minimal script"],"exampleFix":"// before\nconst btn = page.waitForSelector('#go');\nawait page.goto('https://example.com/next');\nawait btn.click(); // handle from previous document, context gone\n\n// after\nawait page.goto('https://example.com/next');\nconst btn = page.waitForSelector('#go');\nawait btn.click();","handlingStrategy":"retry","validationCode":null,"typeGuard":"function isExecutionContextMissing(e) {\n  return e instanceof Error && /execution context .* not found/.test(e.message);\n}","tryCatchPattern":"async function withCtxRetry(fn, tries = 3) {\n  for (let i = 0; i < tries; i++) {\n    try { return await fn(); }\n    catch (e) { if (isExecutionContextMissing(e) && i < tries - 1) continue; throw e; }\n  }\n}","preventionTips":["Never reuse element handles across navigations","Await goto and waitForLoadState before element work","Keep k6 current — these races get fixed"],"tags":["browser","execution-context","internal","race","navigation"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}