onChange function ✓ 100.0%
Last updated: 2026-03-05T11:49:57.418Z
Metrics
LOC: 46
Complexity: 17
Params: 1
Coverage: 100.0% (14/14 lines, 0x executed)
Signature
onChange(e: Event): : void
Architecture violations
- [warning] max-cyclomatic-complexity: 'onChange' has cyclomatic complexity 17 (max 10)
Source Code
function onChange(e: Event): void {
const el = e.target;
if (!session || session.status !== "recording") return;
if (isExtensionUI(el as Element)) return;
// Checkbox and radio: `change` is the reliable event across all browsers.
// Deduplicate with onInput in case the browser also fires `input` (Chrome 74+).
if (el instanceof HTMLInputElement) {
const lastStep = session.steps[session.steps.length - 1];
if (el.type === "checkbox") {
const action = el.checked ? "check" : "uncheck";
if (
lastStep?.type === action &&
lastStep.selector === buildQuickSelector(el) &&
now() - lastStep.timestamp < 500
)
return;
addStep(buildStep(action, el));
return;
}
if (el.type === "radio") {
if (
lastStep?.type === "check" &&
lastStep.selector === buildQuickSelector(el) &&
now() - lastStep.timestamp < 500
)
return;
addStep(buildStep("check", el, { value: el.value }));
return;
}
}
if (!(el instanceof HTMLSelectElement)) return;
// Select changes are captured here if not caught by input
const lastStep = session.steps[session.steps.length - 1];
if (
lastStep?.type === "select" &&
lastStep.selector === buildQuickSelector(el)
) {
lastStep.value = el.value;
return;
}
addStep(buildStep("select", el, { value: el.value }));
}
Dependencies (Outgoing)
| Target | Type |
|---|---|
| isExtensionUI | calls |
| buildQuickSelector | calls |
| now | calls |
| addStep | calls |
| buildStep | calls |
No incoming dependencies.