The free and privacy-friendly screen recorder with no limits π₯
JavaScript annotationannotation-toolaudiocamerachrome-extensiondesigneditorffmpegjavascriptproductivityrecorderscreen-capturescreen-recorderscreencasttensorflowvideo
Auto fallback to MediaRecorder when Webcodecs fails
Alyssa X23ebe4a4bb06
diff --git a/src/pages/Recorder/Recorder.jsx b/src/pages/Recorder/Recorder.jsxindex f136198..0f99adb 100644--- a/src/pages/Recorder/Recorder.jsx+++ b/src/pages/Recorder/Recorder.jsx@@ -1586,6 +1586,7 @@ const Recorder = () => {return;}+ let webcodecsFallbackTriggered = false;try {if (canUseWebCodecs) {useWebCodecs.current = true;@@ -1795,6 +1796,56 @@ const Recorder = () => {if (!transient) persisted.useWebCodecsRecorder = false;chrome.storage.local.set(persisted);updateFreeFinalizeStatus("failed", 100, errStr);++ // Same-session fallback: if WebCodecs blew up before any chunk+ // landed and the capture track is still live, swap to+ // MediaRecorder via a recursive startRecording() so the user+ // doesn't have to re-pick the screen / re-grant prompts.+ const liveVideoTrack =+ liveStream.current?.getVideoTracks?.()[0] || null;+ const trackLive = liveVideoTrack?.readyState === "live";+ const noChunksYet =+ savedCount.current === 0 && !hasChunks.current;+ if (+ !transient &&+ !webcodecsFallbackTriggered &&+ noChunksYet &&+ trackLive+ ) {+ webcodecsFallbackTriggered = true;+ debugWarn(+ "WebCodecs onError: attempting in-session MediaRecorder swap",+ );+ (async () => {+ const prev = recorder.current;+ recorder.current = null;+ useWebCodecs.current = false;+ try {+ await chrome.storage.local.set({+ fastRecorderInUse: false,+ });+ } catch {}+ try {+ prev?.cleanup?.();+ } catch {}+ // Re-enter startRecording (guard at top requires both+ // recorder.current null and isStarting.current false).+ isStarting.current = false;+ try {+ await startRecording();+ } catch (e) {+ debugError("In-session swap startRecording threw", e);+ chrome.runtime.sendMessage({+ type: "show-toast",+ message:+ chrome.i18n.getMessage("webcodecsFailedOffToast"),+ });+ sendRecordingError(errStr);+ }+ })();+ return;+ }+if (!transient) {chrome.runtime.sendMessage({type: "show-toast",@@ -1847,6 +1898,9 @@ const Recorder = () => {message: chrome.i18n.getMessage("webcodecsFailedOffToast"),});recorder.current = null;+ // Top-of-startRecording guard requires both recorder null AND+ // isStarting false; without this reset the recursive call bails.+ isStarting.current = false;return await startRecording();}await chrome.storage.local.set({ fastRecorderInUse: true });diff --git a/src/pages/Recorder/webcodecs/WebCodecsRecorder.js b/src/pages/Recorder/webcodecs/WebCodecsRecorder.jsindex 6b100c4..cff31fe 100644--- a/src/pages/Recorder/webcodecs/WebCodecsRecorder.js+++ b/src/pages/Recorder/webcodecs/WebCodecsRecorder.js@@ -323,6 +323,24 @@ export class WebCodecsRecorder {this._startAlignTimer = setTimeout(() => {this._startAlignTimer = null;if (!this.running) return;++ // E2E hook: simulate a runtime encoder failure before any chunk+ // lands so tests can exercise the in-session swap to+ // MediaRecorder. Resolves start() with success first so the+ // caller treats this as a normal post-start error.+ if (globalThis.__screenityForceWebCodecsError) {+ if (this._startResolve) {+ this._startResolve(true);+ this._startResolve = null;+ }+ setTimeout(() => {+ this.options.onError?.(+ new Error("e2e-forced-webcodecs-error"),+ );+ }, 0);+ return;+ }+// Launch loops together so t=0 aligns.this._videoLoopPromise = this.readVideoLoop();if (this.audioReader && this.options.enableAudio) {diff --git a/src/pages/Region/Recorder.jsx b/src/pages/Region/Recorder.jsxindex f76039c..6475a8b 100644--- a/src/pages/Region/Recorder.jsx+++ b/src/pages/Region/Recorder.jsx@@ -801,6 +801,7 @@ const Recorder = () => {probeResult?.details?.selectedVideoConfig || null;let recorderToken = 0;let codecFallbackTriggered = false;+ let webcodecsFallbackTriggered = false;let mediaRecorderStartAt = Date.now();let recdbgChunkCount = 0;let recdbgTotalBytes = 0;@@ -1125,6 +1126,82 @@ const Recorder = () => {if (!transient) persisted.useWebCodecsRecorder = false;chrome.storage.local.set(persisted);updateFreeFinalizeStatus("failed", 100, errStr);++ // Same-session fallback: encoder errored before any chunk landed+ // and the capture track is still live. Swap to MediaRecorder so+ // the user doesn't have to re-pick the region / re-grant prompts.+ // Skip on transient errors (WebCodecs may recover) and on repeat+ // calls (VideoEncoder.error can fire more than once).+ const liveVideoTrack =+ liveStream.current?.getVideoTracks?.()[0] || null;+ const trackLive = liveVideoTrack?.readyState === "live";+ const noChunksYet =+ savedCount.current === 0 && !hasChunks.current;+ if (+ !transient &&+ !webcodecsFallbackTriggered &&+ noChunksYet &&+ trackLive+ ) {+ webcodecsFallbackTriggered = true;+ persistRegionStartDebug({+ stage: "webcodecs-onerror-swap",+ why: errStr.slice(0, 200),+ });+ (async () => {+ const prev = recorder.current;+ recorder.current = null;+ useWebCodecs.current = false;+ try {+ await chrome.storage.local.set({+ fastRecorderInUse: false,+ });+ } catch {}+ try {+ prev?.cleanup?.();+ } catch {}+ let swapped = false;+ try {+ swapped = await startMediaRecorderWithCodec("vp9");+ } catch (e) {+ swapped = false;+ }+ if (+ swapped &&+ recorder.current instanceof MediaRecorder+ ) {+ try {+ recorder.current.start(5000);+ setTimeout(() => {+ try {+ recorder.current?.requestData?.();+ } catch {}+ }, 250);+ persistRegionStartDebug({+ stage: "webcodecs-onerror-swap-ok",+ });+ return;+ } catch (startErr) {+ persistRegionStartDebug({+ stage: "webcodecs-onerror-swap-start-throw",+ why: String(startErr),+ });+ }+ }+ // Fallback failed too β surface the original failure.+ chrome.runtime.sendMessage({+ type: "show-toast",+ message: chrome.i18n.getMessage("webcodecsFailedOffToast"),+ });+ chrome.runtime.sendMessage({+ type: "recording-error",+ error: "stream-error",+ why: "Fast recorder failed. Please try compatibility mode.",+ });+ })();+ return;+ }+if (!transient) {chrome.runtime.sendMessage({type: "show-toast",