tryRestoreRecordingSession function exported ✗ 0.0%

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

Metrics

LOC: 57 Complexity: 7 Params: 0 Coverage: 0.0% (0/10 lines, 0x executed)

Signature

tryRestoreRecordingSession(): : RecordingSession | null

Summary

Checks sessionStorage for a recording session persisted across a page navigation (e.g. traditional form submit). If found, restores the session and resumes recording on the current page. Should be called once on content-script startup.

Source Code

export function tryRestoreRecordingSession(): RecordingSession | null {
  try {
    const raw = sessionStorage.getItem(RECORDING_SESSION_KEY);
    if (!raw) return null;

    // Remove immediately so subsequent reloads do not re-restore
    sessionStorage.removeItem(RECORDING_SESSION_KEY);

    const data = JSON.parse(raw) as PersistedRecording;
    if (!data?.session?.steps?.length) return null;

    // Stop any currently active recording before restoring
    if (session) stopRecording();

    // Restore state
    stoppedSession = null;
    stoppedResponses = [];
    capturedResponses = data.capturedResponses ?? [];
    lastNetworkActivityTimestamp = 0;

    // Resume the persisted session, adding a navigate step for the new page
    session = {
      ...data.session,
      status: "recording",
      steps: [
        ...data.session.steps,
        {
          type: "navigate" as RecordedStepType,
          timestamp: now(),
          url: window.location.href,
          label: document.title || "New page",
        },
      ],
    };

    lastActionTimestamp = now();

    // Re-attach event listeners on the new document
    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);

    startMutationObserver();
    startNetworkMonitoring();

    return session;
  } catch {
    return null;
  }
}

Dependencies (Outgoing)

graph LR tryRestoreRecordingSession["tryRestoreRecordingSession"] stopRecording["stopRecording"] now["now"] addListener["addListener"] startMutationObserver["startMutationObserver"] startNetworkMonitoring["startNetworkMonitoring"] tryRestoreRecordingSession -->|calls| stopRecording tryRestoreRecordingSession -->|calls| now tryRestoreRecordingSession -->|calls| addListener tryRestoreRecordingSession -->|calls| startMutationObserver tryRestoreRecordingSession -->|calls| startNetworkMonitoring style tryRestoreRecordingSession fill:#dbeafe,stroke:#2563eb,stroke-width:2px click tryRestoreRecordingSession "38d7b2802373484d.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 tryRestoreRecordingSession["tryRestoreRecordingSession"] FillableElement["FillableElement"] FillableElement -->|uses| tryRestoreRecordingSession style tryRestoreRecordingSession fill:#dbeafe,stroke:#2563eb,stroke-width:2px click tryRestoreRecordingSession "38d7b2802373484d.html" click FillableElement "2ecf5aaac3f668a8.html"
SourceType
FillableElement uses