BroadcastChannel testing in chrome developer tools console isn't working

I am testing the BroadcastChannel functionality and I’am having trouble. I open two Chrome windows and the dev tools for each. On the console I write:

const z = new BroadcastChannel('blarg')
z.onmessage = function (ev) {console.log(ev)}

I can examine z and it has the function saved to the onmessage prop so it all looks good. However, when I test:

z.postMessage('sweet')

in one of the consoles, nothing shows in the other. I would expect since both Chrome windows are subscribed to the broadcast channel blarg and have a function to console log the message that is posted, I would see the message sweet to be shown in the other console but nothing happens.

So two questions:

Can’t I test BroadcastChannel interface in the devtools console like this?

If so, what am I missing about how BroadcastChannel works?

39 thoughts on “BroadcastChannel testing in chrome developer tools console isn't working”

Leave a Comment