onmessage
Onmessage is an event handler property used in JavaScript to handle messages delivered by the postMessage API. It is available on various objects that can receive messages, such as Window, Worker, DedicatedWorkerGlobalScope, SharedWorker, MessagePort, and WebSocket. Assigning a function to onmessage designates a single handler for incoming message events on that object.
When a message arrives, the assigned onmessage function is invoked with a MessageEvent object. The event typically
Common usage includes communication with web workers and cross-document messaging. For a worker, the pattern is:
Onmessage differs from addEventListener in that it supports only a single handler assignment per target. Replacing