Html 服务器在Firefox共享Web Workers中发送事件
我正试图在Firefox中的共享Web Worker中使用Html 服务器在Firefox共享Web Workers中发送事件,html,firefox,web-worker,server-sent-events,Html,Firefox,Web Worker,Server Sent Events,我正试图在Firefox中的共享Web Worker中使用EventSource(服务器发送的事件)。当我尝试在共享工作进程的消息事件中使用EventSource构造函数时,工作进程抛出一个错误ReferenceError:EventSource未定义。 我假设这意味着无法在共享Web Workers上下文中访问此对象,但我可以从Google Chrome中的共享Web Worker中访问EventSource我想明确指出,如果直接从脚本中使用,我可以毫无问题地使用EventSource,我只是
EventSource
(服务器发送的事件)。当我尝试在共享工作进程的消息事件中使用EventSource构造函数时,工作进程抛出一个错误ReferenceError:EventSource未定义。
我假设这意味着无法在共享Web Workers上下文中访问此对象,但我可以从Google Chrome中的共享Web Worker中访问EventSource我想明确指出,如果直接从脚本中使用,我可以毫无问题地使用EventSource
,我只是在Firefox内的共享Web Worker中创建和使用它有问题。
查看it声明:
当脚本的全局对象是窗口对象或实现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;
但是,查看指定的接口有一个
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;
我假设我可以使用self.EventSource
或仅使用EventSource
从工作人员内部根据两个规范中提到的信息访问EventSource。然而,Firefox的实际情况似乎并非如此
我无法从Firefox的共享Web Worker访问EventSource有什么原因吗?
我希望对EventSource(推送事件)使用共享Web Worker,因为用户可以从相关网站打开多个选项卡,并且我希望避免浏览器打开到主机的多个EventSource连接
我应该使用另一种方法吗?不幸的是,在ASP.net 2上开发时,Web套接字不是一个选项
感谢您抽出时间。Firefox每晚都会修复此漏洞,并在Firefox 53中发布: 我已将EventSource公开给专用工作人员和共享工作人员 其他浏览器引擎是否实现了这一点? 据我所知,Chrome在专用工作者、共享工作者和服务工作者中支持它。Safari在专用的worker中支持它。Edge不支持它 向ServiceWorker公开EventSource: 目前没有服务人员的计划,因为有一个悬而未决的问题正在讨论中 参考资料