Fix the JS error "EventSource is not defined" caused by some non-standard browsers (#20584)

* fall back to periodic poller

Co-authored-by: silverwind <me@silverwind.io>
This commit is contained in:
wxiaoguang 2022-08-04 03:58:27 +08:00 committed by GitHub
parent 99fc419855
commit 96440e6ada
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 71 additions and 64 deletions

View file

@ -70,6 +70,13 @@ class Source {
self.addEventListener('connect', (e) => {
for (const port of e.ports) {
port.addEventListener('message', (event) => {
if (!self.EventSource) {
// some browsers (like PaleMoon, Firefox<53) don't support EventSource in SharedWorkerGlobalScope.
// this event handler needs EventSource when doing "new Source(url)", so just post a message back to the caller,
// in case the caller would like to use a fallback method to do its work.
port.postMessage({type: 'no-event-source'});
return;
}
if (event.data.type === 'start') {
const url = event.data.url;
if (sourcesByUrl[url]) {