chrome.pushMessaging

Description: Use chrome.pushMessaging to send message data to app or extension users.
Availability: Google Chrome 24
Permissions: "pushMessaging"
Learn more: Google Cloud Messaging for Chrome;
API Reference for GCM service

chrome.pushMessaging reference

Methods

getChannelId

chrome.pushMessaging.getChannelId(boolean interactive, function callback)

Retrieves the channel ID associated with this app or extension. Typically an app or extension will want to send this value to its application server so the server can use it to trigger push messages back to the app or extension. If the interactive flag is set, we will ask the user to log in when they are not already logged in.

Parameters

interactive ( optional boolean )
callback ( function )

Callback

The callback parameter should specify a function that looks like this:

function(object channelId) {...};
channelId ( object )
channelId ( string )
The channel ID for this app to use for push messaging.

Events

onMessage

chrome.pushMessaging.onMessage.addListener(function(object message) {...});

Fired when a push message has been received.

Listener Parameters

message ( object )
The details associated with the message.
subchannelId ( integer )
The subchannel the message was sent on; only values 0-3 are valid.
payload ( string )
The payload associated with the message, if any.

Sample Apps that use chrome.pushMessaging

  • Push Guestbook – Displays the last post to an anonymous guestbook using push messaging
  • Push Messaging Roundtrip Sample – Tests push messaging end to end.
  • Push Messaging Sample Client App – A sample to demonstrate how to use Chrome Push Messaging.