Donaldcwl / browser-image-compression

Image compression in web browser
MIT License
1.3k stars 160 forks source link

Web Worker Failing on Chrome #17

Closed brucem1976 closed 4 years ago

brucem1976 commented 5 years ago

Chrome 75.0.3770.100 Win 10 64-bit

I do the following:

var compressionOptions = {
          maxSizeMB: 0.8,
          maxWidthOrHeight: 1920,
          useWebWorker: true,
          exifOrientation: true
        };
const imageFile = await imageCompression(
          file,
          compressionOptions
        );

and get the following in browser console:

browser-image-compression.mjs:430 Run compression in web worker failed: x is not defined , fall back to main thread

Any ideas what could be wrong? The image is correctly compressed, but without a web worker.

JoelVenable commented 5 years ago

I notice the same issue on Firefox.

For now I'm setting useWebWorker to false, which won't fix the issue of course but the warning will be suppressed.

brucem1976 commented 5 years ago

A previous closed issue https://github.com/Donaldcwl/browser-image-compression/issues/15 confirmed that Web Workers don't work in Firefox, but this is specifically about Chrome

Donaldcwl commented 5 years ago

@brucem1976 The logging in the production script seems not enough to debug. Can you use this script and see the console again? debug script.zip

Thanks.

FaizanZahid commented 5 years ago

@Donaldcwl i m having an issue when my browser adblock on chrome is turned ON , i get this error in console.

Refused to create a worker from 'blob:https://site.com/3e9ce499-7750-4d8c-896b-7db16d4677c6' because it violates the following Content Security Policy directive: "script-src 'self' * 'unsafe-inline'". Note that 'worker-src' was not explicitly set, so 'script-src' is used as a fallback.

(anonymous) @ browser.img.compress.js:1 (anonymous) @ browser.img.compress.js:1 (anonymous) @ browser.img.compress.js:1 (anonymous) @ browser.img.compress.js:1 browser.img.compress.js:1 Uncaught DOMException: Failed to construct 'Worker': Access to the script at 'blob:https://site.com/3e9ce499-7750-4d8c-896b-7db16d4677c6' is denied by the document's Content Security Policy. at https://site.com/js/browser.img.compress.js:1:7705 at https://site.com/js/browser.img.compress.js:1:7770 at https://site.com/js/browser.img.compress.js:1:165 at https://site.com/js/browser.img.compress.js:1:169

Any way to fix this, i have even turned off use web worker option by false.

shriyajuneja commented 5 years ago

getting Warning Run compression in web worker failed: Error: ut is not defined ReferenceError: ut is not defined at blob::1 at new Promise () at blob::1 at Worker.t (app.234f3b40974f9acd4f5a.js:1) , fall back to main thread

alaksandarjesus commented 5 years ago

+1

Donaldcwl commented 4 years ago

There should be no problem in v1.0.7