Skip to Content
Menu

Deprecated

nebula_sw_message

This is a custom DOM event to conveniently listen for Service Worker messages.

JavaScript February 8, 2021

Deprecated

Usage

This is a variable or event handle.

Examples

Listen for all messages

JavaScript
jQuery(document).on('nebula_sw_message', function(e, message){
    console.log('Message received via Nebula event:', message);
});

Listen for a message with an object key of "demo"

JavaScript
jQuery(document).on('nebula_sw_message', function(e, message){
    if ( message.demo ){
        console.log('Message received via Nebula event:', message.demo);
    }
});

Additional Notes

This is useful for syncing data/information between tabs without needing localstorage. Like closing a notification in one tab closes it in all tabs, or incrementing a counter on all tabs (like an ecommerce cart).

Note: the message is not sent to the same tab/window (client) that triggered it.

This event will trigger anytime the service worker receives a message, so you may need to check to make sure you are acting on the correct one.

To post a message to the service worker, use navigator.serviceWorker.controller.postMessage(data), or the more convenient Nebula alias: nebulaPostMessage

Deprecated in favor of Workbox Window. Use workbox.messageSW()[code] after it has been activated (Listen for [code]nebula_workbox_active on the document).

Was this page helpful? Yes No


    A feedback message is required to submit this form.


    Please check that you have entered a valid email address.

    Enter your email address if you would like a response.

    Thank you for your feedback!