Skip to content

🎥 Make videos programmatically with React

move cross origin isolation check to `canUseWhisperWasm`

Igor Samokhovetsef083342eadd
diff --git a/packages/whisper-wasm/src/can-use-whisper-wasm.ts b/packages/whisper-wasm/src/can-use-whisper-wasm.ts
index ab38dbbf45..588d510bf0 100644
--- a/packages/whisper-wasm/src/can-use-whisper-wasm.ts
+++ b/packages/whisper-wasm/src/can-use-whisper-wasm.ts
@@ -11,6 +11,7 @@ export enum WhisperWasmUnsupportedReason {
UsageUndefined = 'usage-undefined',
NotEnoughSpace = 'not-enough-space',
ErrorEstimatingStorage = 'error-estimating-storage',
+ NotCrossOriginIsolated = 'not-cross-origin-isolated',
}
export interface CanUseWhisperWasmResult {
@@ -31,6 +32,15 @@ export const canUseWhisperWasm = async (
};
}
+ if (!window.crossOriginIsolated) {
+ return {
+ supported: false,
+ reason: WhisperWasmUnsupportedReason.NotCrossOriginIsolated,
+ detailedReason:
+ 'The document is not cross-origin isolated (window.crossOriginIsolated = false). This prevents the usage of SharedArrayBuffer, which is required by `@remotion/whisper-wasm`. Make sure the document is served with the HTTP header `Cross-Origin-Opener-Policy: same-origin` and `Cross-Origin-Embedder-Policy: require-corp`: https://developer.mozilla.org/en-US/docs/Web/API/Window/crossOriginIsolated',
+ };
+ }
+
if (!window.indexedDB) {
return {
supported: false,
diff --git a/packages/whisper-wasm/src/check-for-headers.ts b/packages/whisper-wasm/src/check-for-headers.ts
deleted file mode 100644
index 4628527701..0000000000
--- a/packages/whisper-wasm/src/check-for-headers.ts
+++ /dev/null
@@ -1,9 +0,0 @@
-const headerWarningPrinted = false;
-
-export const checkForHeaders = () => {
- if (!headerWarningPrinted && !window.crossOriginIsolated) {
- throw new Error(
- 'The document is not cross-origin isolated (window.crossOriginIsolated = false). This prevents the usage of SharedArrayBuffer, which is required by `@remotion/whisper-wasm`. Make sure the document is served with the HTTP header `Cross-Origin-Opener-Policy: same-origin` and `Cross-Origin-Embedder-Policy: require-corp`: https://developer.mozilla.org/en-US/docs/Web/API/Window/crossOriginIsolated',
- );
- }
-};
diff --git a/packages/whisper-wasm/src/transcribe.ts b/packages/whisper-wasm/src/transcribe.ts
index 6d471efe77..ca3f31dba0 100644
--- a/packages/whisper-wasm/src/transcribe.ts
+++ b/packages/whisper-wasm/src/transcribe.ts
@@ -1,7 +1,5 @@
/* eslint-disable new-cap */
-
import type {MainModule} from '../main';
-import {checkForHeaders} from './check-for-headers';
import type {WhisperWasmLanguage, WhisperWasmModel} from './constants';
import {getObject} from './db/get-object-from-db';
import {getModelUrl} from './get-model-url';
@@ -80,7 +78,6 @@ export const transcribe = async ({
threads ?? DEFAULT_THREADS
}`,
);
- checkForHeaders();
if ((threads ?? DEFAULT_THREADS) > MAX_THREADS_ALLOWED) {
Log.warn(