tabs.sendMessage()

Sends a single message to the content script(s) in the specified tab, with an optional callback to run when a response is sent back. The runtime.onMessage event is fired in each content script running in the specified tab for the current extension.

Syntax

browser.tabs.sendMessage(
  tabId,                   // integer
  message,                 // any
  options,                 // optional object
  function(response) {...} // optional function
)

Parameters

tabId
integer.
message
any.
optionsOptional
object.
frameIdOptional
integer. Send a message to a specific frame identified by frameId instead of all frames in the tab.
responseCallbackOptional
function. The function is passed the following arguments:
response
any. The JSON response object sent by the handler of the message. If an error occurs while connecting to the specified tab, the callback will be called with no arguments and runtime.lastError will be set to the error message.

Browser compatibility

EdgeFirefoxChromeOpera
Basic support?45.0Yes33
Firefox
Basic supportNo

Examples

Example add-ons

Acknowledgements

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

Document Tags and Contributors

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