Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 13f2e56

Browse files
committedMar 11, 2025·
Added support for trusted types
1 parent 63ea4cc commit 13f2e56

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed
 

‎packages/ffmpeg/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"webpack-cli": "^5.1.4"
6464
},
6565
"dependencies": {
66+
"@types/trusted-types": "^2.0.7",
6667
"@ffmpeg/types": "^0.12.4"
6768
}
6869
}

‎packages/ffmpeg/src/classes.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -185,17 +185,18 @@ export class FFmpeg {
185185
* @returns `true` if ffmpeg core is loaded for the first time.
186186
*/
187187
public load = (
188-
{ classWorkerURL, ...config }: FFMessageLoadConfig = {},
188+
{ classWorkerURL, trustedTypePolicy, ...config }: FFMessageLoadConfig = { },
189189
{ signal }: FFMessageOptions = {}
190190
): Promise<IsFirst> => {
191+
const createScriptURL = ((url: string) => (trustedTypePolicy ?? window.trustedTypes?.defaultPolicy)?.createScriptURL?.(url) ?? url)
191192
if (!this.#worker) {
192193
this.#worker = classWorkerURL ?
193-
new Worker(new URL(classWorkerURL, import.meta.url), {
194+
new Worker(createScriptURL(new URL(classWorkerURL, import.meta.url).toString()), {
194195
type: "module",
195196
}) :
196197
// We need to duplicated the code here to enable webpack
197198
// to bundle worekr.js here.
198-
new Worker(new URL("./worker.js", import.meta.url), {
199+
new Worker(createScriptURL(new URL("./worker.js", import.meta.url).toString()), {
199200
type: "module",
200201
});
201202
this.#registerHandlers();
@@ -340,7 +341,7 @@ export class FFmpeg {
340341
) as Promise<OK>;
341342
};
342343

343-
public mount = (fsType: FFFSType, options: FFFSMountOptions, mountPoint: FFFSPath, ): Promise<OK> => {
344+
public mount = (fsType: FFFSType, options: FFFSMountOptions, mountPoint: FFFSPath): Promise<OK> => {
344345
const trans: Transferable[] = [];
345346
return this.#send(
346347
{

‎packages/ffmpeg/src/types.ts

+5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ export interface FFMessageLoadConfig {
3030
* @defaultValue `./worker.js`
3131
*/
3232
classWorkerURL?: string;
33+
34+
/**
35+
* Trusted type policy to use on workers
36+
*/
37+
trustedTypePolicy?: TrustedTypePolicy
3338
}
3439

3540
export interface FFMessageExecData {

0 commit comments

Comments
 (0)
Please sign in to comment.