{"record":{"id":"22d1a98dc6b9fb9c","repo":"grafana/k6","slug":"document-element-handle-is-nil","errorCode":null,"errorMessage":"document element handle is nil","messagePattern":"document element handle is nil","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/frame.go","lineNumber":297,"sourceCode":"\n\treturn f.documentHandle, f.documentHandle != nil\n}\n\nfunc (f *Frame) newDocumentHandle() (*ElementHandle, error) {\n\tresult, err := f.evaluate(\n\t\tf.ctx,\n\t\tmainWorld,\n\t\tevalOptions{\n\t\t\tforceCallable: false,\n\t\t\treturnByValue: false,\n\t\t},\n\t\t\"document\",\n\t)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"getting document element handle: %w\", err)\n\t}\n\tif result == nil {\n\t\treturn nil, fmt.Errorf(\"document element handle is nil\")\n\t}\n\tdh, ok := result.(*ElementHandle)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"unexpected document handle type: %T\", result)\n\t}\n\n\treturn dh, nil\n}\n\nfunc (f *Frame) hasContext(world executionWorld) bool {\n\tf.executionContextMu.RLock()\n\tdefer f.executionContextMu.RUnlock()\n\n\treturn f.executionContexts[world] != nil\n}\n\nfunc (f *Frame) hasLifecycleEventFired(event LifecycleEvent) bool {\n\tf.lifecycleEventsMu.RLock()","sourceCodeStart":279,"sourceCodeEnd":315,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/frame.go#L279-L315","documentation":"Returned by Frame.newDocumentHandle when evaluating 'document' succeeded but returned a nil result — the frame's main-world context produced no document object. Usually a race right after context creation or during detachment, where the evaluation legitimately resolves to nothing.","triggerScenarios":"Thrown at internal/js/modules/k6/browser/common/frame.go:292 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Retry the document-dependent operation after a brief wait","Wait for the frame's load lifecycle event before acting","Verify the frame is a real document frame (not about:blank mid-swap or detached)"],"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"}