{"record":{"id":"f9e0a6de76e69394","repo":"grafana/k6","slug":"name-attribute-must-be-a-string-or-a-regular-exp","errorCode":null,"errorMessage":"\"name\" attribute must be a string or a regular expression","messagePattern":"\"name\" attribute must be a string or a regular expression","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/js/injected_script.js","lineNumber":1211,"sourceCode":"        validateSupportedRole(attr.name, kAriaLevelRoles, role);\n        if (typeof attr.value === \"string\")\n          attr.value = +attr.value;\n        if (attr.op !== \"=\" || typeof attr.value !== \"number\" || Number.isNaN(attr.value))\n          throw new Error(`\"level\" attribute must be compared to a number`);\n        options.level = attr.value;\n        break;\n      }\n      case \"disabled\": {\n        validateSupportedValues(attr, [true, false]);\n        validateSupportedOp(attr, [\"<truthy>\", \"=\"]);\n        options.disabled = attr.op === \"<truthy>\" ? true : attr.value;\n        break;\n      }\n      case \"name\": {\n        if (attr.op === \"<truthy>\")\n          throw new Error(`\"name\" attribute must have a value`);\n        if (typeof attr.value !== \"string\" && !(attr.value instanceof RegExp))\n          throw new Error(`\"name\" attribute must be a string or a regular expression`);\n        options.name = attr.value;\n        options.nameOp = attr.op;\n        options.exact = attr.caseSensitive;\n        break;\n      }\n      case \"include-hidden\": {\n        validateSupportedValues(attr, [true, false]);\n        validateSupportedOp(attr, [\"<truthy>\", \"=\"]);\n        options.includeHidden = attr.op === \"<truthy>\" ? true : attr.value;\n        break;\n      }\n      default: {\n        throw new Error(`Unknown attribute \"${attr.name}\", must be one of ${kSupportedAttributes.map((a) => `\"${a}\"`).join(\", \")}.`);\n      }\n    }\n  }\n  return options;\n}","sourceCodeStart":1193,"sourceCodeEnd":1229,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/modules/k6/browser/common/js/injected_script.js#L1193-L1229","documentation":"After a successful innerText evaluation (frame.go:1353), k6 type-asserts the returned CDP value to string and errors with 'unexpected type %T' when it is not. innerText is spec-defined to return a string, so this fires only when the page returns something abnormal: an overridden innerText getter on the prototype chain, or a DevTools protocol conversion edge case. Treat it as a signal of page tampering or a browser-module bug, not a selector problem.","triggerScenarios":"Page code overrides HTMLElement.prototype.innerText to return objects/numbers/undefined; bot-mitigation scripts poison DOM accessors; CDP RemoteObject conversion returns a non-string for the getter; Chromium/k6 browser module version drift.","commonSituations":"Testing heavily protected sites; custom elements frameworks replacing text accessors; embedded/legacy Chromium builds.","solutions":["Check the real value type via evaluation: const v = await page.evaluate(`document.querySelector(sel).innerText`); inspect typeof v.","Fall back to textContent through page.evaluate when innerText is patched.","Report to grafana/k6 with a repro if the raw getter returns a string but the error persists.","Pin a standard Chromium executable for consistent protocol behavior."],"exampleFix":"// before\nconst txt = await page.innerText('#msg'); // unexpected type ...\n\n// after\nconst txt = await page.evaluate(`document.querySelector('#msg').innerText`);\nif (typeof txt !== 'string') throw new Error('innerText getter patched');","handlingStrategy":"fallback","validationCode":"const t = await page.evaluate(`\n  (() => { const el = document.querySelector('#msg'); return el ? typeof el.innerText : 'no-el'; })()\n`);\nif (t !== 'string') throw new Error('innerText getter patched');","typeGuard":"function isTextString(v) { return typeof v === 'string'; }","tryCatchPattern":"try {\n  return await page.innerText(sel);\n} catch (e) {\n  if (String(e).includes('unexpected type')) {\n    return await page.evaluate(`document.querySelector('${sel}').innerText`);\n  }\n  throw e;\n}","preventionTips":["Use evaluate for text reads on sites with patched DOM getters.","Keep browser/k6 versions consistent.","Report stable repros upstream."],"tags":["k6","browser","innertext","type-assertion","cdp"],"backgroundTag":"unexpected-eval-return-type","analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}