How do I view existing opened BroadcastChannels using JavaScript?
Asked Answered
D

0

7

HTML5 BroadcastChannel API is a great solution to sending data between tabs/windows.

They are opened with new BroadcastChannel(name) and closed by calling the .close() function.

However, it provides no explanation on how to view existing opened BroadcastChannels. If I'm creating BroadcastChannels dynamically (not with a fixed channel name), viewing the BroadcastChannels currently opened is highly useful.

A search on Google ("view existing broadcast channels javascript") and viewing the top three results (1, 2, 3) all provide no pointers as to how to view all opened broadcast channels.

I've tried viewing the BroadcastChannel interface but it does not provide any .listOpenedChannels() function or anything of the sort.

How do I view existing opened BroadcastChannels?

Deprecate answered 19/5, 2021 at 21:44 Comment(3)
You could use localStorage so that you add the dynamic name on a well known named property there. But... why use a dynamic name to begin with? (Also, such a method on the official API would allow any third party script to hijack any such channels, which is not something we want).Cayes
Hey, I was wondering how you create the listening channels dynamically. Opening the channels with unique names on the sender is easy but how the listener channels will be created that will use that unique name to get their messages?Lawsuit
Use the Memory panel's Profile tab in Chrome DevTools to take a Heap snapshot. Then search for BroadcastChannel in the Class filter box.Subshrub

© 2022 - 2024 — McMap. All rights reserved.