X
Tap here to go to the mobile version of the site.

Support Forum

BroadcastChannel.onmessage not working in firefox

Posted

I need to share some information between 2 tabs of the same browser pointing at the same site. I'm using the BroadcastChannel.onmessage event handler as detailed here: https://developer.mozilla.org/en-US/docs/Web/API/BroadcastChannel/onmessage

In the sender tab javascript code I defined:

var bc = new BroadcastChannel('my_bc_channel');

bc.postMessage(i); //where i is simply the line number i want to share

And in the receiving tab:

var bc = new BroadcastChannel('my_bc_channel');

//then use this to receive the incoming messages:

bc.onmessage = function (ev) {

   last_line = ev.data

}

My code works fine in Chrome, but it does not do anything in Firefox (latest version 70 freshly installed under windows). The compatibility chart in the link I gave above says it should be working from Firefox version 38.

The thing is, I'm not sure how to debug this. I don't have any error messages in the console. I don't know if it's the sender code that does not send anything. But clearly the receiving code is not triggered so I guess the .onmessage event is not detected. Where can I see in the javascript console if the message is sent ?

I need to share some information between 2 tabs of the same browser pointing at the same site. I'm using the BroadcastChannel.onmessage event handler as detailed here: https://developer.mozilla.org/en-US/docs/Web/API/BroadcastChannel/onmessage In the sender tab javascript code I defined: var bc = new BroadcastChannel('my_bc_channel'); bc.postMessage(i); //where i is simply the line number i want to share And in the receiving tab: var bc = new BroadcastChannel('my_bc_channel'); //then use this to receive the incoming messages: bc.onmessage = function (ev) { last_line = ev.data } My code works fine in Chrome, but it does not do anything in Firefox (latest version 70 freshly installed under windows). The compatibility chart in the link I gave above says it should be working from Firefox version 38. The thing is, I'm not sure how to debug this. I don't have any error messages in the console. I don't know if it's the sender code that does not send anything. But clearly the receiving code is not triggered so I guess the .onmessage event is not detected. Where can I see in the javascript console if the message is sent ?

Modified by Hugues

Chosen solution

I opened a bug report: https://bugzilla.mozilla.org/show_bug.cgi?id=1600512

Seems BroadcastChannel.onmessage does not work properly when you host your files locally on your hard drive.

Read this answer in context 0
Quote

Additional System Details

Application

  • User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:70.0) Gecko/20100101 Firefox/70.0

More Information

Dinushi Dhananjani
  • Top 25 Contributor
5 solutions 216 answers

Helpful Reply

If the bug 1356546 mentioned didn't

resolve the issue then file a new firefox bug.

Otherwise you can try to split your

data up as was mentioned in comments, 

that wouldn't reduce the overall time,

but it might reduce the affect on UX,
or just don't support Firefox until they
fix their webextensions bugs.
If the bug 1356546 mentioned didn't resolve the issue then file a new firefox bug. Otherwise you can try to split your data up as was mentioned in comments, that wouldn't reduce the overall time, but it might reduce the affect on UX, or just don't support Firefox until they fix their webextensions bugs.
Was this helpful to you? 1
Quote

Question owner

After reading bug report 1356546, I changed my code to send only 1 time the number 700 a few seconds after starting my code. No change. The code goes through without any error message but I receive nothing on the receiving tab.

Before I file a bug report, is there a way in the console of the sending tab to see the data that is being sent with bc.postMessage(i) ?

After reading bug report 1356546, I changed my code to send only 1 time the number 700 a few seconds after starting my code. No change. The code goes through without any error message but I receive nothing on the receiving tab. Before I file a bug report, is there a way in the console of the sending tab to see the data that is being sent with bc.postMessage(i) ?

Modified by Hugues

Was this helpful to you?
Quote

Chosen Solution

I opened a bug report: https://bugzilla.mozilla.org/show_bug.cgi?id=1600512

Seems BroadcastChannel.onmessage does not work properly when you host your files locally on your hard drive.

I opened a bug report: https://bugzilla.mozilla.org/show_bug.cgi?id=1600512 Seems BroadcastChannel.onmessage does not work properly when you host your files '''locally''' on your hard drive.
Was this helpful to you?
Quote
Ask a question

You must log in to your account to reply to posts. Please start a new question, if you do not have an account yet.