Cancelling renders
warning
Experimental feature - expect bugs and breaking changes at any time.
Track progress on GitHub and discuss in the #web-renderer channel on Discord.
Both renderMediaOnWeb() and renderStillOnWeb() support cancellation via the AbortSignal API.
Using AbortController
Create an AbortController and pass its signal to the render function:
Cancel after timeoutimport {renderMediaOnWeb } from '@remotion/web-renderer'; constabortController = newAbortController (); // Cancel after 10 secondssetTimeout (() =>abortController .abort (), 10000); const {getBlob } = awaitrenderMediaOnWeb ({signal :abortController .signal ,composition , });
Detecting if a render was cancelled
When a render is cancelled, an error is thrown. To distinguish between a user-initiated cancellation and an actual error, check if the signal was aborted:
Handle cancellation in catch blockimport {renderMediaOnWeb } from '@remotion/web-renderer'; constabortController = newAbortController (); try { const {getBlob } = awaitrenderMediaOnWeb ({signal :abortController .signal ,composition , }); } catch (error ) { if (abortController .signal .aborted ) { // Render was cancelled by the user, handle gracefullyconsole .log ('Render was cancelled'); } else { // Handle actual errors throwerror ; } }