Skip to content

Commit f1ab3c4

Browse files
committed
Fix the JS error caused by some non-standard browsers
1 parent e56005f commit f1ab3c4

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

web_src/js/features/eventsource.sharedworker.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ class Source {
7070
self.addEventListener('connect', (e) => {
7171
for (const port of e.ports) {
7272
port.addEventListener('message', (event) => {
73+
if (!self.EventSource) {
74+
// some browsers (like PaleMoon, Firefox<53) don't support EventSource in SharedWorkerGlobalScope.
75+
// this event handler needs EventSource when doing "new Source(url)", so just post a message back to the caller,
76+
// in case the caller would like to use a fallback method to do its work.
77+
port.postMessage({type: 'no-event-source'});
78+
return;
79+
}
7380
if (event.data.type === 'start') {
7481
const url = event.data.url;
7582
if (sourcesByUrl[url]) {

0 commit comments

Comments
 (0)