Permalink
Browse files

Work around an EventSource browser crash on Firefox for Android

Firefox for Android v63 crashes when the page is unloaded. The culprit
is believed to be EventSource, but not otherwise fixable. Instead,
drop the real-time updates and let the application degrade to a static
message list.
  • Loading branch information...
lovett committed Nov 27, 2018
1 parent d842e75 commit 771266d447239873cab09b343ee9632fed147041
Showing with 20 additions and 3 deletions.
  1. +4 −1 app/services.ts
  2. +15 −1 worker/receiver.ts
  3. +1 −1 worker/worker.ts
@@ -114,7 +114,10 @@ appServices.factory('PushClient', ['$rootScope', '$log', '$filter', 'MessageList

return {
connect() {
pushWorker.postMessage({action: WorkerCommand.connect});
pushWorker.postMessage({
action: WorkerCommand.connect,
agent: window.navigator.userAgent
});
},

disconnect() {
@@ -6,7 +6,21 @@ export class Receiver {

private reconnectTimer: number = 0;

public connect() {
public connect(userAgent?: string) {
// There is a problem with EventSource on Firefox for Android.
// The browser will crash if the page is reloaded or unloaded
// after the EventSource connection has been made. The exact
// nature of the problem is unknown; this is a
// workaround. Pretending the connection was successful allows
// the initial message fetch to continue working. Real-time
// updates are lost, but on a mobile screen this is not
// entirely terrible because usage is probably short-lived
// anyway. A long-running connection isn't happening on mobile
// the way it is on desktop.
if (userAgent!.indexOf('Android') > -1 && userAgent!.indexOf('Firefox') > -1) {
const reply = new WorkerMessage(WorkerEvent.connected);
return reply.send();
}

this.eventSource = new EventSource('push');

@@ -12,7 +12,7 @@ self.addEventListener('message', (e: Event) => {
}

if (command.action === WorkerCommand.connect) {
receiver.connect();
receiver.connect(command.agent);
}

if (command.action === WorkerCommand.disconnect) {

0 comments on commit 771266d

Please sign in to comment.