BroadcastChannel losing .postMessage() in setInterval

The FoozleTimer class is wired with a BroadcastChannel instance, yet when the emit() method is called, the postMessage() method is not available. This throws an error:

Uncaught TypeError: this.channel.postMessage is not a function

The emit() method is called from the startTimer() method, which uses an arrow function so the this context should be respected from the FoozleTimer class. However, this does not appear to be the case.

It is possible that the context of the BroadcastChannel instance is not being retained correctly.

To resolve this issue, further debugging is needed to confirm the source of the issue. Some potential solutions might be:

  • Ensuring the context of the BroadcastChannel instance is set correctly in the constructor of FoozleTimer
  • Re-initializing the BroadcastChannel instance within the emit() method