DedicatedWorkerGlobalScope: message event

The message event is fired on a DedicatedWorkerGlobalScope object when the worker receives a message from its parent (i.e. when the parent sends a message using Worker.postMessage()).

Bubbles No
Cancelable No
Interface MessageEvent
Event handler property onmessage


This code creates a new worker and sends it a message using Worker.postMessage():

const worker = new Worker("static/scripts/worker.js");

worker.addEventListener('message', (event) => {
    console.log(`Received message from worker: ${}`)

The worker can listen for this message using addEventListener():

// inside static/scripts/worker.js

self.addEventListener('message', (event) => {
    console.log(`Received message from parent: ${}`);  

Alternatively, it could listen using the onmessage event handler property:

// static/scripts/worker.js

self.onmessage = (event) => {
    console.log(`Received message from parent: ${}`);  


Specification Status
HTML Living Standard Living Standard

Browser compatibility

Update compatibility data on GitHub
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
message eventChrome Full support 4Edge Full support 12Firefox Full support 3.5IE Full support 10Opera Full support 10.6Safari Full support 4WebView Android Full support 37Chrome Android Full support YesFirefox Android Full support 4Opera Android Full support 11.5Safari iOS Full support 5.1Samsung Internet Android Full support Yes


Full support  
Full support

See also