The postMessage() method of Client allows a service worker to send a message to a client (a WindowWorker, or SharedWorker). The message is received in the "message" event on navigator.serviceWorker


Client.postMessage(message[, transfer]);


The message to send to the service worker. This can be any structured-clonable type.
transfer Optional
A sequence of objects to transfer. These objects must also be present in the message.

Return value



Sending a message from a service worker to a client:

addEventListener('fetch', event => {
  event.waitUntil(async function() {
    // Exit early if we don't have access to the client.
    // Eg, if it's cross-origin.
    if (!event.clientId) return;

    // Get the client.
    const client = await clients.get(event.clientId);
    // Exit early if we don't get the client.
    // Eg, if it closed.
    if (!client) return;

    // Send a message to the client.
      msg: "Hey I just got a fetch from you!",
      url: event.request.url

Receiving that message:

navigator.serviceWorker.addEventListener('message', event => {


Specification Status Comment
Service Workers
The definition of 'postMessage()' in that specification.
Working Draft Initial definition.

Browser compatibility

Update compatibility data on GitHub
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
Chrome Full support 45Edge ? Firefox Full support 44
Full support 44
Notes Service workers (and Push) have been disabled in the Firefox 45 & 52 Extended Support Releases (ESR).
IE No support NoOpera Full support 32Safari No support NoWebView Android Full support 45Chrome Android Full support 45Firefox Android Full support 44Opera Android Full support 32Safari iOS No support NoSamsung Internet Android Full support 5.0


Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
See implementation notes.
See implementation notes.

Document Tags and Contributors

Last updated by: jpmedley,