Firefox 中的 WebWorkers 和 WebSocket
我正在尝试在 WebWorker 中实现有效的 WebSocket 连接。这应该很简单,如果我使用 Chrome 作为 b rower 的话,那就很简单了。然而,由于这个实验应该进一步成为产品的一部分,我需要它在所有伟大的浏览器上运行,即火狐。
我的问题是我无法在 Firefox 中使用它。起初 Firefox 无法创建 WebWorker。这是一个 Bug,并在版本 9 中修复。但现在看来它无法在 Worker 中创建 WebSocket。
我尝试了以下代码行:
var ws = new WebSocket(url);
失败并显示:
WebSocket is not defined
嗯,根据 this 它应该可以工作。但事实并非如此,无论是在 WebWorker 之内还是在此上下文之外。我尝试了旧的
var ws = new MozWebSocket(url);
,它似乎可以在 WebWorker 之外工作,但我在其中遇到了与上面相同的错误。
现在,问题是什么?我知道 WebSockets 在某些旧版本中默认被禁用,但版本 9 应该支持与 Chrome 类似的功能(至少他们是这么说的)。那么我做错了什么吗?
我使用的是 Ubuntu 11.10,尚未测试其他浏览器。
提前致谢!
I'm trying to implement a working WebSocket connection within a WebWorker. That should be simple and it is if I use Chrome as b rowser. However, since this experiment should further become part of a production I need it to work on all the great Browsers, namely also Firefox.
My problem is that I can't get it working with Firefox. At first Firefox wasn't able to create a WebWorker. That was a Bug and is fixed with version 9. But now it seems that it wouldn't be able to create a WebSocket within the Worker.
I tried the following line of code:
var ws = new WebSocket(url);
which fails with:
WebSocket is not defined
Well, according to this it should work. But it doesn't, neither within the WebWorker nor outside of this context. I tried the older
var ws = new MozWebSocket(url);
which seems to work outside of the WebWorker but I get the same error as above within it.
Now, what's the problem? I know WebSockets where disabled byy default in some older versions but version 9 should support a similar functionality as Chrome (at least that's what they say on their side). So am I doing something wrong?
Im using Ubuntu 11.10 and did not test other browsers yet.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Firefox 中的工作程序尚不支持 WebSocket。请参阅https://bugzilla.mozilla.org/show_bug.cgi?id=504553
更新:Firefox 35 添加了支持。
There's no support for WebSocket in workers in Firefox yet. See https://bugzilla.mozilla.org/show_bug.cgi?id=504553
Update: Firefox 35 added support.