BroadcastChannel.onmessage not working
Categories
(Core :: DOM: Security, defect, P3)
Tracking
()
People
(Reporter: laliberte1965, Unassigned)
References
Details
(Whiteboard: [domsecurity-backlog])
Attachments
(2 files)
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36
Steps to reproduce:
I need to share some information between 2 tabs of the same browser pointing at the .html files on my local disk. 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 a consecutive 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.
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.
I have asked for support here:
https://support.mozilla.org/en-US/questions/1273938
It was proposed that it might relate to bug 1356546. But i have modified my code to send only one number once to be sure it is not the same bug, but the modification failed to solve my problem.
Actual results:
No message received in receiving tab. Not sure if message sent from sending tab.
Expected results:
Message is sent from sending tab and received in receiving tab.
Updated•5 years ago
|
Comment 1•5 years ago
•
|
||
A minimal testcase here would be really nice, attached to this bug.
Updated•5 years ago
|
(In reply to Olli Pettay [:smaug] from comment #1)
A minimal testcase here would be really nice, attached to this bug.
I have now attached 2 .html files to my bug report:
- send.html with a javascript that is simply sending "test" using .postmessage
- receive.html with a javascript to receive the message and alert user with a popup on screen
Procedure to replicate:
- open receive.html in one tab
- open send.html in another tab
- at this point the Alert with "Test" should show up in the receive tab
- at least that's how it behaves in Chrome, but in Firefox nothing happens, no error message.
Comment 5•5 years ago
|
||
When I open receive.html in one tab and send.html in another tab, alert is opened in the tab which has receive.html loaded, when loaded from this bug.
I tested both Firefox 70.0.1 and recent Nightly.
But ok, I see, this is about local files. Same origin handling on local files isn't consistent across browsers.
Updated•5 years ago
|
I confirm that BroadcastChannel.onmessage works if I'm pulling my code from a remote server, the problem appears to be only when i load the files from my local drive.
Comment 7•5 years ago
|
||
So Chrome treats file:/// urls as unique origins for direct access, but same origin for purposes of BroadcastChannel? That's not very consistent and I'm not sure it's supportable. But file:/// is a weird specless wasteland of guessing what the right thing to do is.
For your own development purposes, does setting the pref privacy.file_unique_origin
to false
fix the bug for you? Does this have to be deployable as a file:/// url solution or is that a good enough work around for your own personal development?
(In reply to Daniel Veditz [:dveditz] from comment #7)
So Chrome treats file:/// urls as unique origins for direct access, but same origin for purposes of BroadcastChannel? That's not very consistent and I'm not sure it's supportable. But file:/// is a weird specless wasteland of guessing what the right thing to do is.
For your own development purposes, does setting the pref
privacy.file_unique_origin
tofalse
fix the bug for you? Does this have to be deployable as a file:/// url solution or is that a good enough work around for your own personal development?
- started firefox
- opened about:config url
- looked for privacy.file_unique_origin
- changed to false
- restarted Firefox, to be sure
- checked that above flag is still false
- loaded my 2 .html files from local drive
- unfortunately problem is still there, receiving code .onmessage event is not detected.
Updated•5 years ago
|
Updated•4 years ago
|
Comment 9•2 years ago
|
||
Unfortunately this seems to make local development of sites using BroadcastChannel impossible.
Description
•