{"record":{"id":"48db9741627a6c49","repo":"grafana/k6","slug":"unmarshaling-dom-element-state-w","errorCode":null,"errorMessage":"unmarshaling DOM element state: %w","messagePattern":"unmarshaling DOM element state: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/js/modules/k6/browser/common/frame.go","lineNumber":72,"sourceCode":"\t\"detached\": DOMElementStateDetached,\n\t\"visible\":  DOMElementStateVisible,\n\t\"hidden\":   DOMElementStateHidden,\n}\n\n// MarshalJSON marshals the enum as a quoted JSON string.\nfunc (s DOMElementState) MarshalJSON() ([]byte, error) {\n\tbuffer := bytes.NewBufferString(`\"`)\n\tbuffer.WriteString(domElementStateToString[s])\n\tbuffer.WriteString(`\"`)\n\treturn buffer.Bytes(), nil\n}\n\n// UnmarshalJSON unmarshals a quoted JSON string to the enum value.\nfunc (s *DOMElementState) UnmarshalJSON(b []byte) error {\n\tvar j string\n\terr := json.Unmarshal(b, &j)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"unmarshaling DOM element state: %w\", err)\n\t}\n\t// Note that if the string cannot be found then it will be set to the zero value.\n\t*s = domElementStateToID[j]\n\treturn nil\n}\n\n// Frame represents a frame in an HTML document.\ntype Frame struct {\n\tBaseEventEmitter\n\n\tctx         context.Context\n\tpage        *Page\n\tmanager     *FrameManager\n\tparentFrame *Frame\n\n\tchildFramesMu sync.RWMutex\n\tchildFrames   map[*Frame]bool\n","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/frame.go#L54-L90","documentation":"DOMElementState is an internal enum (attached/detached/visible/hidden) that k6 marshals to and from quoted JSON strings. UnmarshalJSON fails when the bytes are not a quoted string at all — json.Unmarshal into a string errors on objects, arrays, or numbers. The payload comes from k6's own injected-script machinery, so a user hitting this is almost certainly seeing an internal inconsistency or a corrupted CDP payload, not a script mistake.","triggerScenarios":"Internal element-state JSON arriving malformed (version skew between the injected script and the Go module); corrupted CDP responses under extreme load; user scripts do not feed this unmarshaller directly.","commonSituations":"Mixed k6 versions or stale binaries where injected script state shapes changed; exotic pages producing unexpected shapes to injected scripts.","solutions":["Upgrade k6 so the injected script and Go module versions match","Reproduce with a minimal script and report it to the k6 browser module maintainers","Retry the operation once — transient payload corruption is possible under heavy load"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await page.click('#x'); // actions that consult element state\n} catch (e) {\n  if (/unmarshaling DOM element state/.test(e.message)) {\n    // transient/internal: retry once, then report upstream\n  } else throw e;\n}","preventionTips":["Keep k6 and the browser module versions aligned","Pin the k6 version in CI to avoid mid-run skew","Report reproducible occurrences upstream with a minimal script"],"tags":["browser","internal","serialization","dom-state"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}