An event that fires when the background script environment receives a message, usually from a content script.
- Source:
Methods
(static) addListener(listener, options)
Add a listener for the onMessage
event.
Parameters:
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
listener |
onMessageListener | The listener to add. |
||||||||||||
options |
Object | Options for the listener. Properties
|
- Source:
(static) hasAnyListeners() → {boolean}
Whether the onMessage
event has any listeners.
- Source:
Returns:
Whether the event has any listeners.
- Type
- boolean
(static) hasListener(listener) → {boolean}
Whether a specified listener has been added for the onMessage
event.
Parameters:
Name | Type | Description |
---|---|---|
listener |
onMessageListener | The listener to check. |
- Source:
Returns:
Whether the listener has been added for the event.
- Type
- boolean
(static) removeListener(listener)
Remove a listener for the onMessage
event.
Parameters:
Name | Type | Description |
---|---|---|
listener |
onMessageListener | The listener to remove. |
- Source:
Type Definitions
onMessageListener(message, sender, sendResponse) → {Promise|undefined}
A listener for the onMessage
event. See the documentation for
browser.runtime.onMessage
for additional detail on the parameters and
using a Promise
return value to send an asynchronous response.
Parameters:
Name | Type | Description |
---|---|---|
message |
Object | The received message with a matching type string. |
sender |
browser.runtime.MessageSender | The sender of the message. |
sendResponse |
function | A function that, when called, sends a response to the message. |
- Source:
Returns:
- Type
- Promise | undefined