{"record":{"id":"fb7d226c6391075c","repo":"grafana/k6","slug":"getting-new-document-handle-w","errorCode":null,"errorMessage":"getting new document handle: %w","messagePattern":"getting new document handle: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/frame.go","lineNumber":262,"sourceCode":"\treturn nil\n}\n\nfunc (f *Frame) defaultTimeout() time.Duration {\n\treturn f.manager.timeoutSettings.timeout()\n}\n\nfunc (f *Frame) document() (*ElementHandle, error) {\n\tf.log.Debugf(\"Frame:document\", \"fid:%s furl:%q\", f.ID(), f.URL())\n\n\tif cdh, ok := f.cachedDocumentHandle(); ok {\n\t\treturn cdh, nil\n\t}\n\n\tf.waitForExecutionContext(mainWorld)\n\n\tdh, err := f.newDocumentHandle()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"getting new document handle: %w\", err)\n\t}\n\n\t// each execution context switch modifies documentHandle.\n\t// see: nullContext().\n\tf.executionContextMu.Lock()\n\tdefer f.executionContextMu.Unlock()\n\tf.documentHandle = dh\n\n\treturn dh, nil\n}\n\nfunc (f *Frame) cachedDocumentHandle() (*ElementHandle, bool) {\n\t// each execution context switch modifies documentHandle.\n\t// see: nullContext().\n\tf.executionContextMu.RLock()\n\tdefer f.executionContextMu.RUnlock()\n\n\treturn f.documentHandle, f.documentHandle != nil","sourceCodeStart":244,"sourceCodeEnd":280,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/frame.go#L244-L280","documentation":"Returned by Frame.document when the frame has no cached document handle and creating a fresh one via newDocumentHandle fails. The wrapped error comes from evaluating 'document' in the main world: no execution context yet, navigation destroyed the context, or a CDP error. All selector-based frame APIs that need the document go through this.","triggerScenarios":"Thrown at internal/js/modules/k6/browser/common/frame.go:257 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Wait for the frame to load (waitForLoadState/waitForSelector) before querying","Retry after navigation completes","Check that the frame is not 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"}