feat(workers): add support for trusted types - #837
Open
sorin-davidoi wants to merge 1 commit into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Using
fuse.js/workercurrently fails for projects that use therequire-trusted-types-forContent Security Policy directive:This patch fixes this by creating a
TrustedTypePolicycalledfuse-trusted-worker-urland spawning the web workers with aTrustedTypeURLinstance created from the policy.It also changes the public API to allow
workerUrlto be passed as aTrustedScriptURL, 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-fordirective.See https://developer.mozilla.org/en-US/docs/Web/API/Trusted_Types_API.
Inspired by sveltejs/svelte#16271.