{"record":{"id":"4bd0551638e50144","repo":"grafana/k6","slug":"role-must-not-be-empty","errorCode":null,"errorMessage":"Role must not be empty","messagePattern":"Role must not be empty","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/js/injected_script.js","lineNumber":1284,"sourceCode":"      shadows.push(root.shadowRoot);\n    for (const element of root.querySelectorAll(\"*\")) {\n      match(element);\n      if (element.shadowRoot)\n        shadows.push(element.shadowRoot);\n    }\n    shadows.forEach(query);\n  };\n  query(scope);\n  return result;\n}\n\nfunction createRoleEngine(internal) {\n  return {\n    queryAll: (scope, selector) => {\n      const parsed = parseAttributeSelector(selector, true);\n      const role = parsed.name.toLowerCase();\n      if (!role)\n        throw new Error(`Role must not be empty`);\n      const options = validateAttributes(parsed.attributes, role);\n      beginAriaCaches();\n      try {\n        return queryRole(scope, options, internal);\n      } finally {\n        endAriaCaches();\n      }\n    }\n  };\n}\n\n// packages/injected/src/selectorEvaluator.ts\nvar SelectorEvaluatorImpl = class {\n  constructor() {\n    this._retainCacheCounter = 0;\n    this._cacheText = new k6BrowserNative.Map();\n    this._cacheQueryCSS = new k6BrowserNative.Map();\n  }","sourceCodeStart":1266,"sourceCodeEnd":1302,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/modules/k6/browser/common/js/injected_script.js#L1266-L1302","documentation":"After the inputValue evaluation succeeds (frame.go:1385), k6 asserts the CDP-returned value is a string; a non-string yields 'unexpected type %T'. The injected JS returns element.value, which for input/textarea/select is always a string per spec, so this defensive check fires only on abnormal pages: a patched value getter on the prototype, or a protocol conversion quirk. It indicates page tampering or a k6/browser bug rather than a wrong API call.","triggerScenarios":"Page defines a getter for HTMLInputElement.prototype.value returning non-strings; anti-bot frameworks or frameworks like older React versions interfering with native accessors; CDP value conversion edge cases; Chromium version mismatch.","commonSituations":"Testing protected login/checkout flows where bot detection patches input values; custom form libraries overriding value; k6 browser module paired with a non-standard Chromium.","solutions":["Inspect directly: const v = await page.evaluate(`document.querySelector(sel).value`); check typeof v.","Read the value via page.evaluate when the getter is patched.","Report a grafana/k6 issue with a minimal repro if the raw property is a string but the error persists.","Use a pinned, standard Chromium build."],"exampleFix":"// before\nconst v = await page.inputValue('#email'); // unexpected type ...\n\n// after\nconst v = await page.evaluate(`document.querySelector('#email').value`);\nif (typeof v !== 'string') throw new Error('value getter patched');","handlingStrategy":"fallback","validationCode":"const t = await page.evaluate(`\n  (() => { const el = document.querySelector('#email'); return el ? typeof el.value : 'no-el'; })()\n`);\nif (t !== 'string') throw new Error('value getter patched');","typeGuard":"function isValueString(v) { return typeof v === 'string'; }","tryCatchPattern":"try {\n  return await page.inputValue(sel);\n} catch (e) {\n  if (String(e).includes('unexpected type')) {\n    return await page.evaluate(`document.querySelector('${sel}').value`);\n  }\n  throw e;\n}","preventionTips":["On protected forms, read values via evaluate.","Avoid custom Chromium builds that deviate from protocol behavior.","Report reproducible type mismatches to grafana/k6."],"tags":["k6","browser","inputvalue","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"}