Create polished demo videos without editing skills. Mac/Windows/Linux
fix(recording): stop browser recorder before cleanup
wiiiii1237f5084387f37
diff --git a/src/hooks/useScreenRecorder.test.ts b/src/hooks/useScreenRecorder.test.tsindex e98554ad..34424903 100644--- a/src/hooks/useScreenRecorder.test.ts+++ b/src/hooks/useScreenRecorder.test.ts@@ -132,6 +132,11 @@ function stopRecording(if (webcamRecorder && webcamRecorder.state !== "inactive") {webcamRecorder.stop();}+ try {+ recorder.requestData();+ } catch {+ // Stopping should continue even if the browser refuses an explicit flush.+ }recorder.stop();return { stopped: true, wasNative: false };}@@ -328,6 +333,31 @@ describe("useScreenRecorder state machine", () => {expect(callOrder).toEqual(["resume", "stop"]);});+ it("flushes the current recorder data before stopping", () => {+ const callOrder: string[] = [];+ recorder.requestData.mockImplementation(() => {+ callOrder.push("requestData");+ });+ recorder.stop.mockImplementation(() => {+ callOrder.push("stop");+ });++ stopRecording(recorder, false);++ expect(callOrder).toEqual(["requestData", "stop"]);+ });++ it("still stops when the explicit data flush fails", () => {+ recorder.requestData.mockImplementation(() => {+ throw new Error("flush failed");+ });++ const result = stopRecording(recorder, false);++ expect(result.stopped).toBe(true);+ expect(recorder.stop).toHaveBeenCalled();+ });+it("still stops when resume throws from paused state", () => {recorder.pause();recorder.resume.mockImplementation(() => {diff --git a/src/hooks/useScreenRecorder.ts b/src/hooks/useScreenRecorder.tsindex 3d7933ee..69591478 100644--- a/src/hooks/useScreenRecorder.ts+++ b/src/hooks/useScreenRecorder.ts@@ -1092,7 +1092,11 @@ export function useScreenRecorder(): UseScreenRecorderReturn {}}pendingWebcamPathPromise.current = stopWebcamRecorder();- cleanupCapturedMedia();+ try {+ recorder.requestData();+ } catch (error) {+ console.warn("Failed to flush recorder before stopping:", error);+ }recorder.stop();setRecording(false);setFinalizing(true);