9

In Firefox, the following code works correctly when run in the main browser thread as normal--

var fr = new FileReader();

..but when run from a web worker, the following error is thrown:

FileReader is not defined

The same code works fine in Chrome and Safari.

Any suggestions for supporting FileReader in a web worker in Firefox?

Stu Blair
  • 1,323
  • 15
  • 24
  • 1
    Did you try using `FileReaderSync` instead of `FileReader` ? – adeneo Mar 30 '14 at 08:08
  • @adeneo, yes, that does appear to be supported. Does FF not support asynchronous file reading? Are chrome/safari actually operating synchronously when I use FileReader? – Stu Blair Mar 30 '14 at 09:14
  • 1
    Well, `FileReaderSync` is *only* supported in workers, as you generally don't need asynchronous file reading in a worker, but I'm not sure why Firefox doesn't support the regular async `FileReader` in worker, I thought they did, but at least they support the synchronous version, so you can just use that as you don't need async behaviour in a worker anyway. – adeneo Mar 30 '14 at 09:17

1 Answers1

7

As adeneo pointed out, it seems that FileReader is simply not supported by Firefox in Web Workers. I was able to use FileReaderSync instead to accomplish what I needed.

Stu Blair
  • 1,323
  • 15
  • 24
  • 1
    The bug request on bugzilla related to the Firefox shortcoming https://bugzilla.mozilla.org/show_bug.cgi?id=901097 – humanityANDpeace Jul 29 '15 at 06:56
  • Web workers are especially for blocking, intensive tasks which may block the main thread giving a poor user experience (UI blocking etc). That's probably why Firefox has focused on implementing FileReaderSync in Workers before FileReader, it just makes more sense in the Web Worker context. – user885983 Feb 28 '16 at 17:05