{"record":{"id":"2bc44ffa37df4bec","repo":"grafana/k6","slug":"getting-document-element-handle-w","errorCode":null,"errorMessage":"getting document element handle: %w","messagePattern":"getting document element handle: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/frame.go","lineNumber":294,"sourceCode":"\t// see: nullContext().\n\tf.executionContextMu.RLock()\n\tdefer f.executionContextMu.RUnlock()\n\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}","sourceCodeStart":276,"sourceCodeEnd":312,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/frame.go#L276-L312","documentation":"Returned by Frame.newDocumentHandle when evaluating the expression 'document' in the frame's main world fails. The wrap adds call-site context to the evaluation error; typical causes are a missing or destroyed execution context (frame navigating) or a session error.","triggerScenarios":"Thrown at internal/js/modules/k6/browser/common/frame.go:289 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Retry once the frame's execution context exists (waitForExecutionContext runs first, but races remain)","Ensure the frame is attached and not mid-navigation","Inspect the wrapped error for the CDP cause"],"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"}