runtime.connect()

Attempts to connect listeners within an extension (such as the background page), or other extensions. This is useful for content scripts connecting to their extension processes and extension communication.

Note that this does not connect to any listeners in a content script. Extensions may connect to content scripts embedded in tabs via tabs.connect.

Syntax

browser.runtime.connect(
  extensionId, // optional string
  connectInfo  // optional object
)

Parameters

extensionIdOptional
string. The ID of the extension to connect to. If omitted, a connection will be attempted with your own extension.
connectInfoOptional
object.
nameOptional
string. Will be passed into runtime.onConnect for processes that are listening for the connection event.
includeTlsChannelIdOptional
boolean. Whether the TLS channel ID will be passed into runtime.onConnectExternal for processes that are listening for the connection event.

Return value

runtime.Port. Port through which messages can be sent and received. The port's  onDisconnect event is fired if the extension does not exist.

Browser compatibility

EdgeFirefoxChromeOpera
Basic support?45.0Yes33
Firefox
Basic support48.0

Examples

Acknowledgements

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

Document Tags and Contributors

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