Skip to Content

postMessage()

A convenient function for posting a message to the Service Worker.

JavaScript February 7, 2021

Usage

JavaScript
nebula.postMessage(data)

Parameters

data
(Required) (Mixed) A string, object, or valid data to pass as a message to the service worker
Default: None

Request or provide clarification »

Examples

Send a simple string as a message

JavaScript
nebula.postMessage('This is a test!');

Send an object as a message

JavaScript
nebula.postMessage({
    demo: jQuery('#message').val()
});

Demo


Waiting for JavaScript to load...

Additional Notes

This function is essentially an alias for navigator.serviceWorker.controller.postMessage(data), but it also checks if Service Worker is supported and if there is currently a controller, so it is safe to use anywhere.

Remember: Using shift+reload bypasses the service worker so the window will not be controlled! This prevents messages from being posted!

Source File

This function was not found in /assets/js/modules/utilities.js. Please report this error.

No Hooks

This function does not have any filters or actions available. Request one?

Override

To override or disable this JavaScript function, simply redeclare it with the exact same function name.

JavaScript
function postMessage(data){
    //Write your own code here, leave it blank, or return false.
}