Use this event to listen for messages from another WebExtension.

To send a message which will be received by the onMessageExternal listener, use runtime.sendMessage(), passing the ID of the recipient in the extensionId parameter.

Along with the message itself, the listener is passed:

  • a sender object giving details about the message sender
  • a sendResponse function which it can use to send a response back to the sender.

This API can't be used in a content script.



Events have three functions:

Adds a listener to this event.
Stop listening to this event. The listener argument is the listener to remove.
Checks whether a listener is registered for this event. Returns true if it is listening, false otherwise.

addListener syntax



A callback function that will be called when this event occurs. The function will be passed the following arguments:

object. The message itself. This is a JSON-ifiable object.
A runtime.MessageSender object representing the sender of the message.

A function to call, at most once, to send a response to the message. The function takes a single argument, which may be any JSON-ifiable object. This argument is passed back to the message sender.

If you have more than one onMessage listener in the same document, then only one may send a response.

To send a response synchronously, call sendResponse before the listener function returns. To send a response asynchronously, keep a reference to the sendResponse argument and return true from the listener function. You will then be able to call sendResponse after the listener function has returned.

The listener function returns a boolean. It should return true if you wish to call sendResponse after the listener returns.

Browser compatibility

Chrome Edge Firefox Firefox for Android Opera
Basic support Yes No No No 33



This API is based on Chromium's chrome.runtime API. This documentation is derived from runtime.json in the Chromium code.

Microsoft Edge compatibility data is supplied by Microsoft Corporation and is included here under the Creative Commons Attribution 3.0 United States License.

Document Tags and Contributors

 Contributors to this page: wbamberg, Makyen, chrisdavidmills
 Last updated by: wbamberg,