startRecording function exported ✓ 100.0%

Last updated: 2026-03-05T11:49:57.418Z

Metrics

LOC: 48 Complexity: 3 Params: 0 Coverage: 100.0% (15/15 lines, 0x executed)

Signature

startRecording(): : RecordingSession

Summary

Starts a new recording session. Attaches event listeners and mutation observer to capture user interactions.

Source Code

export function startRecording(): RecordingSession {
  // Stop any existing session
  if (session) stopRecording();

  // Clear any previously stopped session so the new recording starts clean.
  // Reset capturedResponses here (not in stopRecording) so that XHR loadend events
  // that arrive after stopRecording can still append to the previous session's stoppedResponses.
  stoppedSession = null;
  stoppedResponses = [];
  capturedResponses = [];
  lastNetworkActivityTimestamp = 0;

  session = {
    steps: [
      {
        type: "navigate",
        timestamp: now(),
        url: window.location.href,
        label: document.title || "Page",
      },
    ],
    startUrl: window.location.href,
    startTime: now(),
    status: "recording",
  };

  lastActionTimestamp = now();

  // Attach event listeners
  addListener(document, "input", onInput, { capture: true });
  addListener(document, "change", onChange, { capture: true });
  addListener(document, "click", onClick, { capture: true });
  addListener(document, "submit", onSubmit, { capture: true });
  addListener(document, "keydown", onKeyDown as EventListener, {
    capture: true,
  });
  addListener(window, "beforeunload", onBeforeUnload);
  addListener(window, "hashchange", onHashChange);
  addListener(window, "popstate", onPopState);

  // Start mutation observer for auto-wait detection
  startMutationObserver();

  // Start network monitoring for smart waits
  startNetworkMonitoring();

  return session;
}

Dependencies (Outgoing)

graph LR startRecording["startRecording"] stopRecording["stopRecording"] now["now"] addListener["addListener"] startMutationObserver["startMutationObserver"] startNetworkMonitoring["startNetworkMonitoring"] startRecording -->|calls| stopRecording startRecording -->|calls| now startRecording -->|calls| addListener startRecording -->|calls| startMutationObserver startRecording -->|calls| startNetworkMonitoring style startRecording fill:#dbeafe,stroke:#2563eb,stroke-width:2px click startRecording "5a5a69de77cdf6a4.html" click stopRecording "26762b7cb59107d8.html" click now "b0f01bcc017e0081.html" click addListener "3710ea748b566f32.html" click startMutationObserver "b9d35cd1c4fa11fe.html" click startNetworkMonitoring "89e83cdb6693637a.html"
TargetType
stopRecording calls
now calls
addListener calls
startMutationObserver calls
startNetworkMonitoring calls
document dynamic_call
window dynamic_call

Impact (Incoming)

graph LR startRecording["startRecording"] FillableElement["FillableElement"] renderRecordTab["renderRecordTab"] FillableElement -->|uses| startRecording renderRecordTab -->|calls| startRecording style startRecording fill:#dbeafe,stroke:#2563eb,stroke-width:2px click startRecording "5a5a69de77cdf6a4.html" click FillableElement "2ecf5aaac3f668a8.html" click renderRecordTab "55c03c4dd1c7d324.html"
SourceType
FillableElement uses
renderRecordTab calls