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)
| Target | Type |
|---|---|
| stopRecording | calls |
| now | calls |
| addListener | calls |
| startMutationObserver | calls |
| startNetworkMonitoring | calls |
| document | dynamic_call |
| window | dynamic_call |
Impact (Incoming)
| Source | Type |
|---|---|
| FillableElement | uses |