Skip to content

feat(workers): add support for trusted types - #837

Open
sorin-davidoi wants to merge 1 commit into
krisk:mainfrom
sorin-davidoi:feat-trusted-types
Open

feat(workers): add support for trusted types#837
sorin-davidoi wants to merge 1 commit into
krisk:mainfrom
sorin-davidoi:feat-trusted-types

Conversation

@sorin-davidoi

@sorin-davidoi sorin-davidoi commented Jul 30, 2026

Copy link
Copy Markdown

Using fuse.js/worker currently fails for projects that use the require-trusted-types-for Content Security Policy directive:

This document requires 'TrustedScriptURL' assignment. The action has been blocked.
_spawnWorker @fuse-worker.mjs:73
_init        @fuse-worker.mjs:107
_ensureInit  @fuse-worker.mjs:69
search       @fuse-worker.mjs:130

This patch fixes this by creating a TrustedTypePolicy called fuse-trusted-worker-url and spawning the web workers with a TrustedTypeURL instance created from the policy.

It also changes the public API to allow workerUrl to be passed as a TrustedScriptURL, such that consumers can use their own policies.

This change should have no impact on consumers that don't make use of the require-trusted-types-for directive.

See https://developer.mozilla.org/en-US/docs/Web/API/Trusted_Types_API.

Inspired by sveltejs/svelte#16271.

Using `fuse.js/worker` currently fails for projects that use the
`require-trusted-types-for` Content Security Policy directive:

```
This document requires 'TrustedScriptURL' assignment. The action has been blocked.
_spawnWorker @fuse-worker.mjs:73
_init        @fuse-worker.mjs:107
_ensureInit  @fuse-worker.mjs:69
search       @fuse-worker.mjs:130
```

This patch fixes this by creating a `TrustedTypePolicy` called
`fuse-trusted-worker-url` and spawning the web workers with a
`TrustedTypeURL` instance created from the policy.

It also changes the public API to allow `workerUrl` to be passed as a
`TrustedScriptURL`, such that consumers can use their own policies.

This change has should have no impact on consumers that don't make use
of the `require-trusted-types-for` directive.

See https://developer.mozilla.org/en-US/docs/Web/API/Trusted_Types_API.

Inspired by sveltejs/svelte#16271.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant