diff --git a/src/broadcast-channel.ts b/src/broadcast-channel.ts index 2cded3a78..a9f37abae 100644 --- a/src/broadcast-channel.ts +++ b/src/broadcast-channel.ts @@ -9,6 +9,19 @@ export interface BroadcastChannelData { projectIds: string[]; settings?: boolean; } +class NoOpBroadcastChannel { + constructor() {} + postMessage(_data: unknown) {} + addEventListener(_type: string, _handler: (e: MessageEvent) => void) {} + removeEventListener(_type: string, _handler: (e: MessageEvent) => void) {} + close() {} +} // Used to keep project state synced between open tabs / windows. -export const broadcastChannel = new BroadcastChannel("ml"); +// Broadcast channel is not supported for older browsers/iOS versions, so a +// no-op version is used to avoid throwing an error. +// TODO: Revisit making project state syncing work for older web browsers. +export const broadcastChannel = + typeof BroadcastChannel === "undefined" + ? new NoOpBroadcastChannel() + : new BroadcastChannel("ml");