handleFill function

Last updated: 2026-03-05T20:45:07.036Z

Metrics

LOC: 41 Complexity: 8 Params: 4

Signature

handleFill( step: FlowStep, resolvedValue: string | undefined, config: ReplayConfig, ): : Promise<StepResult>

Source Code

async function handleFill(
  step: FlowStep,
  resolvedValue: string | undefined,
  config: ReplayConfig,
): Promise<StepResult> {
  const el = requireElement(step);
  ensureVisible(el);

  if (!(el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement)) {
    return { status: "failed", error: "Fill target is not an input/textarea" };
  }

  const value = resolvedValue ?? "";

  // Clear existing value first
  el.value = "";
  el.dispatchEvent(new Event("input", { bubbles: true }));

  // Simulate typing character by character
  if (config.typingDelay > 0 && value.length > 0) {
    for (const char of value) {
      el.value += char;
      el.dispatchEvent(new Event("input", { bubbles: true }));
      el.dispatchEvent(
        new KeyboardEvent("keydown", { key: char, bubbles: true }),
      );
      el.dispatchEvent(
        new KeyboardEvent("keyup", { key: char, bubbles: true }),
      );
      await sleep(config.typingDelay);
    }
  } else {
    el.value = value;
    el.dispatchEvent(new Event("input", { bubbles: true }));
  }

  el.dispatchEvent(new Event("change", { bubbles: true }));
  el.dispatchEvent(new Event("blur", { bubbles: true }));

  return { status: "success" };
}

Dependencies (Outgoing)

graph LR handleFill["handleFill"] requireElement["requireElement"] ensureVisible["ensureVisible"] sleep["sleep"] handleFill -->|calls| requireElement handleFill -->|calls| ensureVisible handleFill -->|calls| sleep style handleFill fill:#dbeafe,stroke:#2563eb,stroke-width:2px click handleFill "8f674e688d002684.html" click requireElement "54b35883ca14f405.html" click ensureVisible "12336ba1f5ec5dde.html" click sleep "25404f77365ed229.html"
TargetType
requireElement calls
ensureVisible calls
sleep calls

Impact (Incoming)

graph LR handleFill["handleFill"] executeStep["executeStep"] executeStep -->|calls| handleFill style handleFill fill:#dbeafe,stroke:#2563eb,stroke-width:2px click handleFill "8f674e688d002684.html" click executeStep "a26ccfb820921de2.html"
SourceType
executeStep calls