BroadcastChannel Class

A channel of messages between the windows and the workers of the same origin (https://html.spec.whatwg.org/multipage/web-messaging.html#broadcasting-to-other-browsing-contexts). The messages are delivered to the channels with the same name of the browsing context group of the global object (the windows of the top-level browsing context and of its nested browsing contexts, and their workers), through their event loops.

public sealed class BroadcastChannel : EventTarget

Remarks

The relevant global object of a channel is the current global object when it is created (e.g. the window or the worker of the script that creates it); a channel created without current global object neither sends nor receives messages. The messages are serialized by the script engine of the global object (structured clone); without script engine, only the .NET primitive values and the serializable platform objects can be sent.

See also

Inheritance
EventTarget BroadcastChannel

Constructors

NameDescription
BroadcastChannel(string)https://html.spec.whatwg.org/multipage/web-messaging.html#dom-broadcastchannel

BroadcastChannel(string)

BroadcastChannel.cs

https://html.spec.whatwg.org/multipage/web-messaging.html#dom-broadcastchannel

public BroadcastChannel(string name)

Properties

NameDescription
NameGets the channel name.
OnMessageGets or sets the event handler of the message event.
OnMessageErrorGets or sets the event handler of the messageerror event.

Gets the channel name.

public string Name { get; }

Gets or sets the event handler of the message event.

public Action<Event>? OnMessage { get; set; }

OnMessageError

BroadcastChannel.cs

Gets or sets the event handler of the messageerror event.

public Action<Event>? OnMessageError { get; set; }

Methods

NameDescription
Close()Closes the channel: it no longer sends nor receives messages (https://html.spec.whatwg.org/multipage/web-messaging.html#dom-broadcastchannel-close).
PostMessage(object?)Sends a message to the other channels with the same name of the windows and the workers of the same origin (https://html.spec.whatwg.org/multipage/web-messaging.html#dom-broadcastchannel-postmessage).

Closes the channel: it no longer sends nor receives messages (https://html.spec.whatwg.org/multipage/web-messaging.html#dom-broadcastchannel-close).

public void Close()

PostMessage(object?)

BroadcastChannel.cs

Sends a message to the other channels with the same name of the windows and the workers of the same origin (https://html.spec.whatwg.org/multipage/web-messaging.html#dom-broadcastchannel-postmessage).

public void PostMessage(object? message)

Parameters

message object?
The message: a value of the script engine, a .NET primitive value or a serializable platform object, or null for undefined.

See also