Image compression loads its worker script from cdn.jsdelivr.net #11
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
prepareImage(client/src/media.ts) callsbrowser-image-compressionwithuseWebWorker: true. The library then starts ablob:worker that runsimportScripts(libURL), andlibURLdefaults tohttps://cdn.jsdelivr.net/npm/[email protected]/dist/browser-image-compression.js. So every install, including the family instance, runs third-party code from a CDN whenever someone picks a picture, and tells the CDN when that happens. If the CDN is unreachable or blocked, the library falls back to compressing on the main thread, which freezes the page for large photos.It also fails under the preview CSP from #9 (
script-src 'self'), which only allows same-origin scripts.Plan
dist/browser-image-compression.js, which defines the globalimageCompressionthat the worker expects) as a static asset with Vite's?urlimport, and pass it aslibURL.blob:URL, where relative URLs do not resolve, so pass the absolute URL (new URL(url, location.href))./assets/, the bundle no longer needs jsdelivr, and on the pull request's preview, posting a picture works with the worker (no CSP violation, no fallback).