Description
Use chrome.gcm to enable apps and extensions to send and receive messages through Firebase Cloud Messaging (FCM).
Permissions
gcmProperties
MAX_MESSAGE_SIZE
The maximum size (in bytes) of all key/value pairs in a message.
Value
4096 
 
Methods
register()
chrome.gcm.register(
senderIds: string[],
callback?: function,
): Promise<string>
Registers the application with FCM. The registration ID will be returned by the callback. If register is called again with the same list of senderIds, the same registration ID will be returned.
Parameters
- 
    senderIdsstring[] A list of server IDs that are allowed to send messages to the application. It should contain at least one and no more than 100 sender IDs. 
- 
    callbackfunction optional The callbackparameter looks like:(registrationId: string) => void - 
    registrationIdstring A registration ID assigned to the application by the FCM. 
 
- 
    
Returns
- 
            Promise<string> Chrome 116+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
send()
chrome.gcm.send(
message: object,
callback?: function,
): Promise<string>
Sends a message according to its contents.
Parameters
- 
    messageobject A message to send to the other party via FCM. - 
    dataobject Message data to send to the server. Case-insensitive goog.andgoogle, as well as case-sensitivecollapse_keyare disallowed as key prefixes. Sum of all key/value pairs should not exceedgcm.MAX_MESSAGE_SIZE.
- 
    destinationIdstring The ID of the server to send the message to as assigned by Google API Console. 
- 
    messageIdstring The ID of the message. It must be unique for each message in scope of the applications. See the Cloud Messaging documentation for advice for picking and handling an ID. 
- 
    timeToLivenumber optional Time-to-live of the message in seconds. If it is not possible to send the message within that time, an onSendError event will be raised. A time-to-live of 0 indicates that the message should be sent immediately or fail if it's not possible. The default value of time-to-live is 86,400 seconds (1 day) and the maximum value is 2,419,200 seconds (28 days). 
 
- 
    
- 
    callbackfunction optional The callbackparameter looks like:(messageId: string) => void - 
    messageIdstring The ID of the message that the callback was issued for. 
 
- 
    
Returns
- 
            Promise<string> Chrome 116+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
unregister()
chrome.gcm.unregister(
callback?: function,
): Promise<void>
Unregisters the application from FCM.
Parameters
- 
    callbackfunction optional The callbackparameter looks like:() => void 
Returns
- 
            Promise<void> Chrome 116+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
Events
onMessage
chrome.gcm.onMessage.addListener(
callback: function,
)
Fired when a message is received through FCM.
Parameters
- 
    callbackfunction The callbackparameter looks like:(message: object) => void - 
    messageobject - 
    collapseKeystring optional The collapse key of a message. See the Non-collapsible and collapsible messages for details. 
- 
    dataobject The message data. 
- 
    fromstring optional The sender who issued the message. 
 
- 
    
 
- 
    
onMessagesDeleted
chrome.gcm.onMessagesDeleted.addListener(
callback: function,
)
Fired when a FCM server had to delete messages sent by an app server to the application. See Lifetime of a message for details on handling this event.
Parameters
- 
    callbackfunction The callbackparameter looks like:() => void 
onSendError
chrome.gcm.onSendError.addListener(
callback: function,
)
Fired when it was not possible to send a message to the FCM server.
Parameters
- 
    callbackfunction The callbackparameter looks like:(error: object) => void - 
    errorobject - 
    detailsobject Additional details related to the error, when available. 
- 
    errorMessagestring The error message describing the problem. 
- 
    messageIdstring optional The ID of the message with this error, if error is related to a specific message. 
 
- 
    
 
-