{"record":{"id":"79057b393a6dfa7f","repo":"grafana/k6","slug":"unexpected-type-t-expecting-string","errorCode":null,"errorMessage":"unexpected type %T (expecting string)","messagePattern":"unexpected type %T \\(expecting string\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/element_handle.go","lineNumber":1004,"sourceCode":"// InnerHTML returns the inner HTML of the element.\nfunc (h *ElementHandle) InnerHTML() (string, error) {\n\tinnerHTML := func(apiCtx context.Context, handle *ElementHandle) (any, error) {\n\t\treturn handle.innerHTML(apiCtx)\n\t}\n\topts := NewElementHandleBaseOptions(h.DefaultTimeout())\n\tinnerHTMLAction := h.newAction(\n\t\t[]string{}, innerHTML, opts.Force, withRetry, opts.NoWaitAfter, opts.Timeout,\n\t)\n\tv, err := call(h.ctx, innerHTMLAction, opts.Timeout)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"getting element's inner HTML: %w\", err)\n\t}\n\n\tapplySlowMo(h.ctx)\n\n\ts, ok := v.(string)\n\tif !ok {\n\t\treturn \"\", fmt.Errorf(\"unexpected type %T (expecting string)\", v)\n\t}\n\n\treturn s, nil\n}\n\n// InnerText returns the inner text of the element.\nfunc (h *ElementHandle) InnerText() (string, error) {\n\tinnerText := func(apiCtx context.Context, handle *ElementHandle) (any, error) {\n\t\treturn handle.innerText(apiCtx)\n\t}\n\topts := NewElementHandleBaseOptions(h.DefaultTimeout())\n\tinnerTextAction := h.newAction(\n\t\t[]string{}, innerText, opts.Force, withRetry, opts.NoWaitAfter, opts.Timeout.Abs(),\n\t)\n\tv, err := call(h.ctx, innerTextAction, opts.Timeout)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"getting element's inner text: %w\", err)\n\t}","sourceCodeStart":986,"sourceCodeEnd":1022,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/element_handle.go#L986-L1022","documentation":"Internal invariant failure inside ElementHandle.innerHTML(): the evaluation succeeded but the returned remote value did not type-assert to a Go string. element.innerHTML is always a string in a live DOM, so a non-string payload points to a protocol/serialization anomaly or a k6 bug rather than script misuse.","triggerScenarios":"Requires the CDP evaluation to return a non-string RemoteObject - essentially only with a Chromium/CDP version mismatched to the k6 release or a k6 regression; not triggerable by normal scripts.","commonSituations":"Canary/nightly Chromium builds against a stable k6; custom browser executables; k6 versions with known evaluation bugs.","solutions":["Upgrade k6 to the latest release","Pin a Chromium version compatible with your k6 release","Work around with evaluate: const html = await el.evaluate((e) => e.innerHTML)","Report to k6 with script and browser versions if it persists"],"exampleFix":"// before\nconst html = await el.innerHTML();\n// after (workaround)\nconst html = await el.evaluate((e) => e.innerHTML);\nif (typeof html !== 'string') throw new Error('innerHTML not a string');","handlingStrategy":"validation","validationCode":"const html = await handle.evaluate((e) => e.innerHTML);\nif (typeof html !== 'string') {\n  throw new Error('innerHTML was not a string');\n}","typeGuard":"function isNonEmptyHtml(v) {\n  return typeof v === 'string';\n}","tryCatchPattern":"try {\n  return await handle.innerHTML();\n} catch (e) {\n  if (String(e).includes('expecting string')) {\n    return handle.evaluate((e) => e.innerHTML);\n  }\n  throw e;\n}","preventionTips":["Match k6 and Chromium versions","Use evaluate() as a fallback when protocol serialization misbehaves","Report reproduction details to k6 maintainers"],"tags":["browser","internal","type-assertion","compatibility"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}