{"record":{"id":"67ef7adc55e0fad4","repo":"grafana/k6","slug":"unexpected-dom-error-type-t","errorCode":null,"errorMessage":"unexpected DOM error type %T","messagePattern":"unexpected DOM error type %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/element_handle.go","lineNumber":1869,"sourceCode":"\t\treturn true, nil // Continue retrying after delay\n\t}\n}\n\nfunc errorFromDOMError(v any) error {\n\tvar (\n\t\terr  error\n\t\tserr string\n\t)\n\tswitch e := v.(type) {\n\tcase string:\n\t\tserr = e\n\tcase error:\n\t\tif e == nil {\n\t\t\treturn errors.New(\"DOM error is nil\")\n\t\t}\n\t\terr, serr = e, e.Error()\n\tdefault:\n\t\treturn fmt.Errorf(\"unexpected DOM error type %T\", v)\n\t}\n\tvar uerr *k6ext.UserFriendlyError\n\tif errors.As(err, &uerr) {\n\t\treturn err\n\t}\n\tif strings.Contains(serr, \"timed out\") {\n\t\treturn &k6ext.UserFriendlyError{\n\t\t\tErr: ErrTimedOut,\n\t\t}\n\t}\n\tif s := \"error:expectednode:\"; strings.HasPrefix(serr, s) {\n\t\treturn fmt.Errorf(\"expected node but got %s\", strings.TrimPrefix(serr, s))\n\t}\n\n\tif serr == \"error:notconnected\" {\n\t\treturn ErrElementNotAttachedToDOM\n\t}\n","sourceCodeStart":1851,"sourceCodeEnd":1887,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/element_handle.go#L1851-L1887","documentation":"errorFromDOMError is the translator for injected-script errors: it accepts only strings ('error:...' codes) or Go errors. This error means it received something else (nil, map, number — the %T shows which), an internal contract violation. One known path: the hit-target gate at element_handle.go:1762 wraps a possibly-nil error, and a nil value with %w surfaces as this shape; otherwise the injected script returned an unexpected payload.","triggerScenarios":"checkHitTargetAt returning (false, nil) hit at the pointer-action gate (renders 'checking hit target: %!w(<nil>)'); injected-script evaluation returning an object/number where an error string was contracted; page-side prototype pollution corrupting injected script returns.","commonSituations":"Intermittent clicks on pages with overlays occasionally producing the nil-wrap path; testing pages that aggressively patch JS built-ins; essentially absent on well-behaved pages.","solutions":["Re-run the script — most occurrences are transient races","Upgrade to the latest k6 patch release; nil-wrapping in error paths has been an area of fixes","If reproducible, run with K6_BROWSER_LOG=debug, note the %T type and the preceding action, and file a k6 issue","As a workaround for click paths, force: true skips the hit-target gate where the nil-wrap originates"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  el.click();\n} catch (e) {\n  const msg = String(e);\n  if (msg.includes('unexpected DOM error type') || msg.includes('%!w(<nil>)')) {\n    el.click(); // transient race in the injected-script error path\n  } else {\n    throw e;\n  }\n}","preventionTips":["Retry once — occurrences are typically transient races","Keep k6 current; injected-script error paths get fixes","Avoid app-side prototype patches that alter injected script returns"],"tags":["browser","internal","invariant","error-handling","interception"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}