Ste*_*art 5 firefox html5 web-worker server-sent-events
我试图EventSource在Firefox中的共享Web Worker中使用(服务器发送事件).当我尝试在共享工作器中的消息事件中尝试使用EventSource构造函数时,Worker会引发错误ReferenceError: EventSource is not defined.
我认为这意味着无法在Shared Web Workers上下文中访问此对象,但我可以从Google Chrome中的共享Web Worker中访问EventSource.我想明确表示,EventSource如果直接从脚本中使用,我可以毫无问题地使用,我只是在Firefox中的共享Web Worker中创建和使用它时遇到问题.
查看第4节中的EventSource规范,它指出:
当脚本的全局对象是Window对象或实现WorkerUtils接口的对象时,此构造函数必须可见.
但是看看第5节中的Web Workers规范,指定的接口有一个WorkerUtils接口.
interface WorkerGlobalScope : EventTarget {
readonly attribute WorkerGlobalScope self;
readonly attribute WorkerLocation location;
void close();
[TreatNonCallableAsNull] attribute Function? onerror;
[TreatNonCallableAsNull] attribute Function? onoffline;
[TreatNonCallableAsNull] attribute Function? ononline;
};
WorkerGlobalScope implements WorkerUtils;
Run Code Online (Sandbox Code Playgroud)
我原以为我可以使用self.EventSource或仅EventSource根据两个规范中提到的信息从Worker中访问EventSource .然而,在Firefox的实践中似乎并非如此.
有没有理由不能从Firefox的共享Web工作者访问EventSource?
我想使用Shared Web Worker for EventSource(推送事件),因为用户可以从相关网站打开多个选项卡,我想避免让浏览器打开与主机的多个EventSource连接.
我应该使用另一种方法吗?不幸的是,Web套接字不是我在ASP.net 2上开发的选项.
谢谢你的时间.
此错误已在 Firefox Nightly 中修复并在 Firefox 53 中发布:
\n\n\n\n\n我已将 EventSource 暴露给专用工作人员和共享工作人员。
\n\n其他浏览器引擎是否实现了这个?据我所知,Chrome 在专用工作线程、共享工作线程和服务工作线程中支持它。Safari 在专用工作人员中支持它。Edge 不支持。
\n\n将 EventSource 暴露给 ServiceWorker:\n 目前没有 Service Worker 计划,因为存在一个未解决的问题https://github.com/w3c/ServiceWorker/issues/947正在讨论中。
\n
参考
\n\n\n| 归档时间: |
|
| 查看次数: |
989 次 |
| 最近记录: |