Skip to content

The free and privacy-friendly screen recorder with no limits 🎥

Fixed pause / resume sync on separate tabs + timer

Alyssa X890a18c0e2e5
diff --git a/src/manifest.json b/src/manifest.json
index e6b6442..cc04d9a 100755
--- a/src/manifest.json
+++ b/src/manifest.json
@@ -3,7 +3,7 @@
"name": "__MSG_extName__",
"description": "__MSG_extDesc__",
"default_locale": "en",
- "version": "4.2.2",
+ "version": "4.2.3",
"background": {
"service_worker": "background.bundle.js"
},
@@ -101,7 +101,7 @@
"managed_schema": "schema.json"
},
"externally_connectable": {
- "matches": ["https://app.screenity.io/*", "http://localhost:3000/*"]
+ "matches": ["https://app.screenity.io/*"]
},
"optional_permissions": [
"offscreen",
diff --git a/src/pages/Background/listeners/onTabActivatedListener.js b/src/pages/Background/listeners/onTabActivatedListener.js
index 3ac7462..3559840 100644
--- a/src/pages/Background/listeners/onTabActivatedListener.js
+++ b/src/pages/Background/listeners/onTabActivatedListener.js
@@ -5,18 +5,21 @@ export const handleTabActivation = async (activeInfo) => {
const {
recordingStartTime,
recording,
+ paused,
+ pausedAt,
+ totalPausedMs,
restarting,
pendingRecording,
recorderSession,
} = await chrome.storage.local.get([
"recordingStartTime",
"recording",
- "restarting",
- "pendingRecording",
- "recorderSession",
"paused",
"pausedAt",
"totalPausedMs",
+ "restarting",
+ "pendingRecording",
+ "recorderSession",
]);
// Get the activated tab
diff --git a/src/pages/Background/listeners/onTabUpdatedListener.js b/src/pages/Background/listeners/onTabUpdatedListener.js
index 05912ac..66c8d0d 100644
--- a/src/pages/Background/listeners/onTabUpdatedListener.js
+++ b/src/pages/Background/listeners/onTabUpdatedListener.js
@@ -5,6 +5,9 @@ export const handleTabUpdate = async (tabId, changeInfo, tab) => {
if (changeInfo.status === "complete") {
const {
recording,
+ paused,
+ pausedAt,
+ totalPausedMs,
restarting,
tabRecordedID,
pendingRecording,
@@ -12,14 +15,14 @@ export const handleTabUpdate = async (tabId, changeInfo, tab) => {
recorderSession,
} = await chrome.storage.local.get([
"recording",
+ "paused",
+ "pausedAt",
+ "totalPausedMs",
"restarting",
"tabRecordedID",
"pendingRecording",
"recordingStartTime",
"recorderSession",
- "paused",
- "pausedAt",
- "totalPausedMs",
]);
// Check both recording flag AND recorderSession to avoid race conditions
@@ -60,9 +63,9 @@ export const handleTabUpdate = async (tabId, changeInfo, tab) => {
if (alarm) {
const { alarmTime } = await chrome.storage.local.get(["alarmTime"]);
const remaining = Math.max(0, Math.floor(alarmTime - elapsed));
- sendMessageTab(activeInfo.tabId, { type: "time", time: remaining });
+ sendMessageTab(tabId, { type: "time", time: remaining });
} else {
- sendMessageTab(activeInfo.tabId, { type: "time", time: elapsed });
+ sendMessageTab(tabId, { type: "time", time: elapsed });
}
}
diff --git a/src/pages/Background/messaging/handlers.js b/src/pages/Background/messaging/handlers.js
index ca57fda..f0230e9 100644
--- a/src/pages/Background/messaging/handlers.js
+++ b/src/pages/Background/messaging/handlers.js
@@ -959,17 +959,27 @@ export const setupHandlers = () => {
return await loginWithWebsite();
});
registerMessage("sync-recording-state", async (message, sendResponse) => {
- const { recording, paused, recordingStartTime, pendingRecording } =
- await chrome.storage.local.get([
- "recording",
- "paused",
- "recordingStartTime",
- "pendingRecording",
- ]);
+ const {
+ recording,
+ paused,
+ recordingStartTime,
+ pausedAt,
+ totalPausedMs,
+ pendingRecording,
+ } = await chrome.storage.local.get([
+ "recording",
+ "paused",
+ "recordingStartTime",
+ "pausedAt",
+ "totalPausedMs",
+ "pendingRecording",
+ ]);
sendResponse({
recording: Boolean(recording),
paused: Boolean(paused),
recordingStartTime: recordingStartTime || null,
+ pausedAt: pausedAt || null,
+ totalPausedMs: totalPausedMs || 0,
pendingRecording: Boolean(pendingRecording),
});
return true;
diff --git a/src/pages/Background/recording/startRecording.js b/src/pages/Background/recording/startRecording.js
index 9f86718..88b99f1 100644
--- a/src/pages/Background/recording/startRecording.js
+++ b/src/pages/Background/recording/startRecording.js
@@ -2,9 +2,7 @@ import { sendMessageRecord } from "./sendMessageRecord";
export const startRecording = async () => {
chrome.storage.local.set({
- recordingStartTime: Date.now(),
restarting: false,
- recording: true,
});
// Check if customRegion is set
@@ -57,7 +55,6 @@ export const startAfterCountdown = async () => {
// If there is an active recording tab or offscreen document, begin recording
if (recordingTab !== null || offscreen) {
- await chrome.storage.local.set({ recording: true });
startRecording();
}
} catch (error) {
diff --git a/src/pages/CloudRecorder/CloudRecorder.jsx b/src/pages/CloudRecorder/CloudRecorder.jsx
index 73806e7..8925f2a 100644
--- a/src/pages/CloudRecorder/CloudRecorder.jsx
+++ b/src/pages/CloudRecorder/CloudRecorder.jsx
@@ -92,6 +92,7 @@ const CloudRecorder = () => {
const recoveryAttempted = useRef(false);
const screenTrackLostRef = useRef(false);
const screenTrackMonitor = useRef(null);
+ const pausedStateRef = useRef(false);
// This checks if the recording was previously initialized
const isInit = useRef(false);
@@ -557,6 +558,14 @@ const CloudRecorder = () => {
}
};
+ const setRecordingTimingState = async (nextState) => {
+ try {
+ await chrome.storage.local.set(nextState);
+ } catch (err) {
+ console.warn("Failed to persist recording timing state:", err);
+ }
+ };
+
const flushPendingChunks = async () => {
if (screenUploader.current) {
try {
@@ -627,6 +636,14 @@ const CloudRecorder = () => {
// Stop the silent audio keep-alive
stopTabKeepAlive();
+ await setRecordingTimingState({
+ recording: false,
+ paused: false,
+ recordingStartTime: null,
+ pausedAt: null,
+ totalPausedMs: 0,
+ });
+ pausedStateRef.current = false;
const { projectId, multiMode, multiSceneCount, recordingToScene } =
await chrome.storage.local.get([
@@ -1184,7 +1201,15 @@ const CloudRecorder = () => {
screenTimer.current.notificationInterval = timerInterval;
screenTimer.current.warned = warned;
- chrome.storage.local.set({ recording: true });
+ const recordingStartTime = Date.now();
+ await setRecordingTimingState({
+ recording: true,
+ paused: false,
+ recordingStartTime,
+ pausedAt: null,
+ totalPausedMs: 0,
+ });
+ pausedStateRef.current = false;
persistSessionState({ status: "recording" });
setStarted(true);
} catch (err) {
@@ -1623,7 +1648,14 @@ const CloudRecorder = () => {
}
}
isFinishing.current = true;
- chrome.storage.local.set({ recording: false });
+ await setRecordingTimingState({
+ recording: false,
+ paused: false,
+ recordingStartTime: null,
+ pausedAt: null,
+ totalPausedMs: 0,
+ });
+ pausedStateRef.current = false;
stopAllIntervals();
await stopAllRecorders();
@@ -2357,6 +2389,7 @@ const CloudRecorder = () => {
return true;
} else if (request.type === "pause-recording-tab") {
if (!isInit.current) return;
+ if (pausedStateRef.current) return;
// Pause all active recorders
if (
@@ -2387,8 +2420,14 @@ const CloudRecorder = () => {
cameraTimer.current.total += now - cameraTimer.current.start;
cameraTimer.current.paused = true;
}
+ pausedStateRef.current = true;
+ void setRecordingTimingState({
+ paused: true,
+ pausedAt: now,
+ });
} else if (request.type === "resume-recording-tab") {
if (!isInit.current) return;
+ if (!pausedStateRef.current) return;
// Resume all paused recorders
if (screenRecorder.current && screenRecorder.current.state === "paused") {
@@ -2410,6 +2449,23 @@ const CloudRecorder = () => {
cameraTimer.current.start = now;
cameraTimer.current.paused = false;
}
+ pausedStateRef.current = false;
+ void (async () => {
+ try {
+ const { pausedAt, totalPausedMs } = await chrome.storage.local.get([
+ "pausedAt",
+ "totalPausedMs",
+ ]);
+ const additional = pausedAt ? Math.max(0, now - pausedAt) : 0;
+ await setRecordingTimingState({
+ paused: false,
+ pausedAt: null,
+ totalPausedMs: (totalPausedMs || 0) + additional,
+ });
+ } catch (err) {
+ console.warn("Failed to update resume timing state:", err);
+ }
+ })();
} else if (request.type === "dismiss-recording") {
if (!isInit.current) return;
dismissRecording();
diff --git a/src/pages/Content/context/ContentState.jsx b/src/pages/Content/context/ContentState.jsx
index 3599425..a618c03 100644
--- a/src/pages/Content/context/ContentState.jsx
+++ b/src/pages/Content/context/ContentState.jsx
@@ -99,17 +99,14 @@ const ContentState = (props) => {
pendingRecording: false,
preparingRecording: false,
}));
- chrome.storage.local.set({
- recording: true,
- restarting: false,
- });
+ chrome.storage.local.set({ restarting: false });
// This cannot be triggered from here because the user might not have the page focused
//chrome.runtime.sendMessage({ type: "start-recording" });
}, []);
const restartRecording = useCallback(() => {
- chrome.storage.local.set({ recording: false, restarting: true });
+ chrome.storage.local.set({ restarting: true });
setTimeout(() => {
chrome.runtime.sendMessage({ type: "discard-backup-restart" });
chrome.runtime.sendMessage({ type: "restart-recording-tab" });
@@ -161,12 +158,8 @@ const ContentState = (props) => {
const stopRecording = useCallback(() => {
chrome.runtime.sendMessage({ type: "clear-recording-alarm" });
chrome.storage.local.set({
- recording: false,
restarting: false,
tabRecordedID: null,
- pausedAt: null,
- paused: false,
- totalPausedMs: 0,
});
setContentState((prevContentState) => ({
...prevContentState,
@@ -203,14 +196,9 @@ const ContentState = (props) => {
});
const pauseRecording = useCallback((dismiss) => {
+ if (contentStateRef.current?.paused) return;
chrome.runtime.sendMessage({ type: "pause-recording-tab" });
- const now = Date.now();
- chrome.storage.local.set({
- paused: true,
- pausedAt: now,
- });
-
setTimeout(() => {
setContentState((prev) => ({
...prev,
@@ -226,21 +214,9 @@ const ContentState = (props) => {
});
const resumeRecording = useCallback(() => {
+ if (!contentStateRef.current?.paused) return;
chrome.runtime.sendMessage({ type: "resume-recording-tab" });
- const now = Date.now();
- chrome.storage.local.get(["pausedAt", "totalPausedMs"], (s) => {
- const pausedAt = s.pausedAt || now;
- const totalPausedMs = s.totalPausedMs || 0;
- const additional = Math.max(0, now - pausedAt);
-
- chrome.storage.local.set({
- paused: false,
- pausedAt: null,
- totalPausedMs: totalPausedMs + additional,
- });
- });
-
setContentState((prev) => ({
...prev,
paused: false,
@@ -265,11 +241,6 @@ const ContentState = (props) => {
blurMode: false,
drawingMode: false,
}));
- chrome.storage.local.set({
- paused: false,
- pausedAt: null,
- totalPausedMs: 0,
- });
// Remove blur from all elements
const elements = document.querySelectorAll(".screenity-blur");
elements.forEach((element) => {
@@ -593,7 +564,9 @@ const ContentState = (props) => {
const tryDismissRecording = useCallback(() => {
if (contentStateRef.current.askDismiss) {
- contentStateRef.current.pauseRecording(true);
+ if (!contentStateRef.current.paused) {
+ contentStateRef.current.pauseRecording(true);
+ }
contentStateRef.current.openModal(
chrome.i18n.getMessage("discardModalTitle"),
chrome.i18n.getMessage("discardModalDescription"),
@@ -702,22 +675,6 @@ const ContentState = (props) => {
chrome.storage.local.set({ askForPermissions: false });
});
- useEffect(() => {
- const onChanged = (changes, area) => {
- if (area !== "local") return;
-
- if (changes.paused) {
- setContentState((prev) => ({
- ...prev,
- paused: Boolean(changes.paused.newValue),
- }));
- }
- };
-
- chrome.storage.onChanged.addListener(onChanged);
- return () => chrome.storage.onChanged.removeListener(onChanged);
- }, []);
-
useEffect(() => {
const handleMessage = (event) => {
if (event.data.type === "screenity-permissions") {
@@ -1016,26 +973,82 @@ const ContentState = (props) => {
}
}, [contentState.openModal]);
- // Count up every second
- useEffect(() => {
- if (contentState.recording && !contentState.paused && !contentState.alarm) {
- setTimer((timer) => timer + 1);
- const interval = setInterval(() => {
- setTimer((timer) => timer + 1);
- }, 1000);
- return () => clearInterval(interval);
- } else if (
- contentState.alarm &&
- !contentState.paused &&
- contentState.recording &&
- contentState.timer > 0
- ) {
- const interval = setInterval(() => {
- setTimer((timer) => timer - 1);
- }, 1000);
- return () => clearInterval(interval);
+ const updateTimerFromStorage = useCallback(async () => {
+ const {
+ recording,
+ recordingStartTime,
+ paused,
+ pausedAt,
+ totalPausedMs,
+ } = await chrome.storage.local.get([
+ "recording",
+ "recordingStartTime",
+ "paused",
+ "pausedAt",
+ "totalPausedMs",
+ ]);
+
+ if (!recording || !recordingStartTime) {
+ setTimer(0);
+ return;
+ }
+
+ const now = Date.now();
+ const basePaused = totalPausedMs || 0;
+ const extraPaused =
+ paused && pausedAt ? Math.max(0, now - pausedAt) : 0;
+ const elapsedSeconds = Math.max(
+ 0,
+ Math.floor((now - recordingStartTime - basePaused - extraPaused) / 1000)
+ );
+
+ if (contentStateRef.current?.alarm) {
+ const alarmTime = contentStateRef.current?.alarmTime || 0;
+ setTimer(Math.max(0, alarmTime - elapsedSeconds));
+ return;
}
- }, [contentState.recording, contentState.paused]);
+
+ setTimer(elapsedSeconds);
+ }, []);
+
+ useEffect(() => {
+ updateTimerFromStorage();
+ const interval = setInterval(() => {
+ updateTimerFromStorage();
+ }, 1000);
+ return () => clearInterval(interval);
+ }, [updateTimerFromStorage]);
+
+ useEffect(() => {
+ const onChanged = (changes, area) => {
+ if (area !== "local") return;
+
+ if (changes.paused) {
+ setContentState((prev) => ({
+ ...prev,
+ paused: Boolean(changes.paused.newValue),
+ }));
+ }
+ if (changes.recording) {
+ setContentState((prev) => ({
+ ...prev,
+ recording: Boolean(changes.recording.newValue),
+ }));
+ }
+ if (
+ changes.paused ||
+ changes.recording ||
+ changes.recordingStartTime ||
+ changes.pausedAt ||
+ changes.totalPausedMs
+ ) {
+ updateTimerFromStorage();
+ }
+ };
+
+ chrome.storage.onChanged.addListener(onChanged);
+ return () => chrome.storage.onChanged.removeListener(onChanged);
+ }, [updateTimerFromStorage]);
useEffect(() => {
if (!contentState.customRegion) {
@@ -1076,22 +1089,6 @@ const ContentState = (props) => {
}
}, []);
- // Check recording start time
- useEffect(() => {
- chrome.storage.local.get(["recordingStartTime"], (result) => {
- if (result.recordingStartTime && contentStateRef.current.recording) {
- const recordingStartTime = result.recordingStartTime;
- const currentTime = new Date().getTime();
- const timeElapsed = currentTime - recordingStartTime;
- const timeElapsedSeconds = Math.floor(timeElapsed / 1000);
- if (contentState.alarm) {
- setTimer(contentState.alarmTime - timeElapsedSeconds);
- } else {
- setTimer(timeElapsedSeconds);
- }
- }
- });
- }, []);
useEffect(() => {
if (contentState.pushToTalk) {
diff --git a/src/pages/Content/context/utils/updateFromStorage.js b/src/pages/Content/context/utils/updateFromStorage.js
index ae61889..bb2a1f5 100644
--- a/src/pages/Content/context/utils/updateFromStorage.js
+++ b/src/pages/Content/context/utils/updateFromStorage.js
@@ -13,6 +13,7 @@ export const updateFromStorage = (check = true, id = null) => {
"cameraActive",
"micActive",
"recording",
+ "paused",
"backgroundEffect",
"backgroundEffectsActive",
"toolbarPosition",
@@ -122,6 +123,10 @@ export const updateFromStorage = (check = true, id = null) => {
result.recording !== undefined && result.recording !== null
? result.recording
: prevContentState.recording,
+ paused:
+ result.paused !== undefined && result.paused !== null
+ ? result.paused
+ : prevContentState.paused,
recordingType:
result.recordingType !== undefined && result.recordingType !== null
? result.recordingType
diff --git a/src/pages/Recorder/Recorder.jsx b/src/pages/Recorder/Recorder.jsx
index ede8416..08de1a9 100644
--- a/src/pages/Recorder/Recorder.jsx
+++ b/src/pages/Recorder/Recorder.jsx
@@ -90,17 +90,25 @@ const Recorder = () => {
const uiClosing = useRef(false);
const isRecording = useRef(false);
+ const pausedStateRef = useRef(false);
// Keep-alive mechanism to prevent Chrome from freezing this background tab
const keepAliveAudioCtx = useRef(null);
const keepAliveOscillator = useRef(null);
- // Session state for recovery and diagnostics
const recordingStartTime = useRef(null);
const sessionHeartbeat = useRef(null);
debug("Recorder component mounted");
+ const setRecordingTimingState = async (nextState) => {
+ try {
+ await chrome.storage.local.set(nextState);
+ } catch (err) {
+ debugWarn("Failed to persist recording timing state", err);
+ }
+ };
+
async function canFitChunk(byteLength) {
const now = performance.now();
if (now - lastEstimateAt.current < ESTIMATE_INTERVAL_MS) {
@@ -429,10 +437,15 @@ const Recorder = () => {
fps,
});
- chrome.storage.local.set({
+ await setRecordingTimingState({
recording: true,
- restarting: false,
+ paused: false,
+ recordingStartTime: recordingStartTime.current,
+ pausedAt: null,
+ totalPausedMs: 0,
});
+ pausedStateRef.current = false;
+ chrome.storage.local.set({ restarting: false });
isRecording.current = true;
isRestarting.current = false;
@@ -825,6 +838,14 @@ const Recorder = () => {
// Stop the session heartbeat and persist final state
stopSessionHeartbeat();
persistSessionState("stopping");
+ await setRecordingTimingState({
+ recording: false,
+ paused: false,
+ recordingStartTime: null,
+ pausedAt: null,
+ totalPausedMs: 0,
+ });
+ pausedStateRef.current = false;
try {
if (
@@ -867,7 +888,7 @@ const Recorder = () => {
}
}
- const dismissRecording = () => {
+ const dismissRecording = async () => {
debug("dismissRecording()");
uiClosing.current = true;
isRecording.current = false;
@@ -876,6 +897,14 @@ const Recorder = () => {
stopTabKeepAlive();
stopSessionHeartbeat();
persistSessionState("dismissed");
+ await setRecordingTimingState({
+ recording: false,
+ paused: false,
+ recordingStartTime: null,
+ pausedAt: null,
+ totalPausedMs: 0,
+ });
+ pausedStateRef.current = false;
window.close();
};
@@ -892,6 +921,7 @@ const Recorder = () => {
isRecording.current = false;
sentLast.current = false;
isFinishing.current = false;
+ pausedStateRef.current = false;
try {
if (
@@ -1339,6 +1369,7 @@ const Recorder = () => {
setAudioOutputVolume(request.volume);
} else if (request.type === "pause-recording-tab") {
if (!recorder.current) return;
+ if (pausedStateRef.current) return;
if (
useWebCodecs.current &&
recorder.current instanceof WebCodecsRecorder
@@ -1349,8 +1380,15 @@ const Recorder = () => {
debug("Pausing MediaRecorder");
recorder.current.pause();
}
+ const now = Date.now();
+ pausedStateRef.current = true;
+ void setRecordingTimingState({
+ paused: true,
+ pausedAt: now,
+ });
} else if (request.type === "resume-recording-tab") {
if (!recorder.current) return;
+ if (!pausedStateRef.current) return;
if (
useWebCodecs.current &&
recorder.current instanceof WebCodecsRecorder
@@ -1361,6 +1399,24 @@ const Recorder = () => {
debug("Resuming MediaRecorder");
recorder.current.resume();
}
+ const now = Date.now();
+ pausedStateRef.current = false;
+ void (async () => {
+ try {
+ const { pausedAt, totalPausedMs } = await chrome.storage.local.get([
+ "pausedAt",
+ "totalPausedMs",
+ ]);
+ const additional = pausedAt ? Math.max(0, now - pausedAt) : 0;
+ await setRecordingTimingState({
+ paused: false,
+ pausedAt: null,
+ totalPausedMs: (totalPausedMs || 0) + additional,
+ });
+ } catch (err) {
+ debugWarn("Failed to update resume timing state", err);
+ }
+ })();
} else if (request.type === "dismiss-recording") {
dismissRecording();
}
diff --git a/src/pages/RecorderOffscreen/RecorderOffscreen.jsx b/src/pages/RecorderOffscreen/RecorderOffscreen.jsx
index 486e822..2c2e9c9 100644
--- a/src/pages/RecorderOffscreen/RecorderOffscreen.jsx
+++ b/src/pages/RecorderOffscreen/RecorderOffscreen.jsx
@@ -20,6 +20,7 @@ const RecorderOffscreen = () => {
const index = useRef(0);
const lastTimecode = useRef(0);
const hasChunks = useRef(false);
+ const pausedStateRef = useRef(false);
const [started, setStarted] = useState(false);
@@ -57,6 +58,17 @@ const RecorderOffscreen = () => {
const MAX_PENDING_BYTES = 8 * 1024 * 1024;
const pendingBytes = useRef(0);
+ const setRecordingTimingState = async (nextState) => {
+ try {
+ await chrome.storage.local.set(nextState);
+ } catch (err) {
+ console.warn(
+ "[RecorderOffscreen] Failed to persist recording timing state",
+ err
+ );
+ }
+ };
+
async function canFitChunk(byteLength) {
const now = performance.now();
if (now - lastEstimateAt.current < ESTIMATE_INTERVAL_MS) {
@@ -260,11 +272,6 @@ const RecorderOffscreen = () => {
return;
}
- chrome.storage.local.set({
- recording: true,
- restarting: false,
- });
-
isRestarting.current = false;
index.current = 0;
@@ -279,6 +286,20 @@ const RecorderOffscreen = () => {
return;
}
+ const recordingStartTime = Date.now();
+ await setRecordingTimingState({
+ recording: true,
+ paused: false,
+ recordingStartTime,
+ pausedAt: null,
+ totalPausedMs: 0,
+ });
+ pausedStateRef.current = false;
+ chrome.storage.local.set({
+ recording: true,
+ restarting: false,
+ });
+
recorder.current.onerror = (ev) => {
chrome.runtime.sendMessage({
type: "recording-error",
@@ -390,6 +411,14 @@ const RecorderOffscreen = () => {
async function stopRecording() {
isFinishing.current = true;
+ await setRecordingTimingState({
+ recording: false,
+ paused: false,
+ recordingStartTime: null,
+ pausedAt: null,
+ totalPausedMs: 0,
+ });
+ pausedStateRef.current = false;
if (recorder.current) {
try {
recorder.current.requestData();
@@ -416,6 +445,14 @@ const RecorderOffscreen = () => {
}
const dismissRecording = async () => {
+ await setRecordingTimingState({
+ recording: false,
+ paused: false,
+ recordingStartTime: null,
+ pausedAt: null,
+ totalPausedMs: 0,
+ });
+ pausedStateRef.current = false;
isRestarting.current = true;
if (recorder.current !== null) {
recorder.current.stop();
@@ -426,6 +463,7 @@ const RecorderOffscreen = () => {
const restartRecording = async () => {
isRestarting.current = true;
+ pausedStateRef.current = false;
if (recorder.current !== null) {
recorder.current.stop();
}
@@ -719,10 +757,39 @@ const RecorderOffscreen = () => {
setAudioOutputVolume(request.volume);
} else if (request.type === "pause-recording-tab") {
if (!recorder.current) return;
+ if (pausedStateRef.current) return;
+ const now = Date.now();
recorder.current.pause();
+ pausedStateRef.current = true;
+ void setRecordingTimingState({
+ paused: true,
+ pausedAt: now,
+ });
} else if (request.type === "resume-recording-tab") {
if (!recorder.current) return;
+ if (!pausedStateRef.current) return;
recorder.current.resume();
+ const now = Date.now();
+ pausedStateRef.current = false;
+ void (async () => {
+ try {
+ const { pausedAt, totalPausedMs } = await chrome.storage.local.get([
+ "pausedAt",
+ "totalPausedMs",
+ ]);
+ const additional = pausedAt ? Math.max(0, now - pausedAt) : 0;
+ await setRecordingTimingState({
+ paused: false,
+ pausedAt: null,
+ totalPausedMs: (totalPausedMs || 0) + additional,
+ });
+ } catch (err) {
+ console.warn(
+ "[RecorderOffscreen] Failed to update resume timing state",
+ err
+ );
+ }
+ })();
} else if (request.type === "dismiss-recording") {
dismissRecording();
}
diff --git a/src/pages/Region/Recorder.jsx b/src/pages/Region/Recorder.jsx
index 6c944d9..314fbc6 100644
--- a/src/pages/Region/Recorder.jsx
+++ b/src/pages/Region/Recorder.jsx
@@ -23,6 +23,7 @@ const Recorder = () => {
const lastTimecode = useRef(0);
const hasChunks = useRef(false);
const lastSize = useRef(0);
+ const pausedStateRef = useRef(false);
// Main stream (recording)
const liveStream = useRef(null);
@@ -60,6 +61,17 @@ const Recorder = () => {
const MAX_PENDING_BYTES = 8 * 1024 * 1024;
const pendingBytes = useRef(0);
+ const setRecordingTimingState = async (nextState) => {
+ try {
+ await chrome.storage.local.set(nextState);
+ } catch (err) {
+ console.warn(
+ "[Region Recorder] Failed to persist recording timing state",
+ err
+ );
+ }
+ };
+
async function canFitChunk(byteLength) {
const now = performance.now();
if (now - lastEstimateAt.current < ESTIMATE_INTERVAL_MS) {
@@ -320,11 +332,6 @@ const Recorder = () => {
return;
}
- chrome.storage.local.set({
- recording: true,
- restarting: false,
- });
-
isRestarting.current = false;
index.current = 0;
recordingRef.current = true;
@@ -346,6 +353,20 @@ const Recorder = () => {
return;
}
+ const recordingStartTime = Date.now();
+ await setRecordingTimingState({
+ recording: true,
+ paused: false,
+ recordingStartTime,
+ pausedAt: null,
+ totalPausedMs: 0,
+ });
+ pausedStateRef.current = false;
+ chrome.storage.local.set({
+ recording: true,
+ restarting: false,
+ });
+
recorder.current.onerror = (ev) => {
chrome.runtime.sendMessage({
type: "recording-error",
@@ -489,6 +510,14 @@ const Recorder = () => {
async function stopRecording() {
isFinishing.current = true;
regionRef.current = false;
+ await setRecordingTimingState({
+ recording: false,
+ paused: false,
+ recordingStartTime: null,
+ pausedAt: null,
+ totalPausedMs: 0,
+ });
+ pausedStateRef.current = false;
if (recorder.current) {
try {
@@ -529,6 +558,14 @@ const Recorder = () => {
const dismissRecording = async () => {
regionRef.current = false;
+ await setRecordingTimingState({
+ recording: false,
+ paused: false,
+ recordingStartTime: null,
+ pausedAt: null,
+ totalPausedMs: 0,
+ });
+ pausedStateRef.current = false;
chrome.runtime.sendMessage({ type: "handle-dismiss" });
isRestarting.current = true;
isDismissing.current = true;
@@ -561,6 +598,7 @@ const Recorder = () => {
const restartRecording = async () => {
isRestarting.current = true;
isDismissing.current = false;
+ pausedStateRef.current = false;
if (recorder.current) {
recorder.current.stop();
}
@@ -827,10 +865,39 @@ const Recorder = () => {
setAudioOutputVolume(request.volume);
} else if (request.type === "pause-recording-tab") {
if (!recorder.current) return;
+ if (pausedStateRef.current) return;
recorder.current.pause();
+ const now = Date.now();
+ pausedStateRef.current = true;
+ void setRecordingTimingState({
+ paused: true,
+ pausedAt: now,
+ });
} else if (request.type === "resume-recording-tab") {
if (!recorder.current) return;
+ if (!pausedStateRef.current) return;
recorder.current.resume();
+ const now = Date.now();
+ pausedStateRef.current = false;
+ void (async () => {
+ try {
+ const { pausedAt, totalPausedMs } = await chrome.storage.local.get([
+ "pausedAt",
+ "totalPausedMs",
+ ]);
+ const additional = pausedAt ? Math.max(0, now - pausedAt) : 0;
+ await setRecordingTimingState({
+ paused: false,
+ pausedAt: null,
+ totalPausedMs: (totalPausedMs || 0) + additional,
+ });
+ } catch (err) {
+ console.warn(
+ "[Region Recorder] Failed to update resume timing state",
+ err
+ );
+ }
+ })();
} else if (request.type === "dismiss-recording") {
dismissRecording();
}