最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Firefox -- "FileReader is not defined" only when called from Web Worker - Stack Overflow

programmeradmin2浏览0评论

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?

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?

Share Improve this question asked Mar 30, 2014 at 7:35 Stu BlairStu Blair 1,3431 gold badge16 silver badges24 bronze badges 3
  • 1 Did you try using FileReaderSync instead of FileReader ? – adeneo Commented Mar 30, 2014 at 8: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 Commented Mar 30, 2014 at 9: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 Commented Mar 30, 2014 at 9:17
Add a ment  | 

1 Answer 1

Reset to default 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 acplish what I needed.

发布评论

评论列表(0)

  1. 暂无评论