files/en-us/mozilla/add-ons/webextensions/api/runtime/onuserscriptconnect/index.md
Fired when a connection is made with a user script from one of the extension's USER_SCRIPT worlds.
In Firefox, this event requires the userScripts permission. In Chrome, the event is always present, including in extensions that don't declare the userScripts permission.
A user script can only connect and then sent messages from a USER_SCRIPT world that is configured by {{WebExtAPIRef('userScripts.configureWorld()')}} with messaging set to true.
browser.runtime.onUserScriptConnect.addListener(listener)
browser.runtime.onUserScriptConnect.removeListener(listener)
browser.runtime.onUserScriptConnect.hasListener(listener)
Events have three functions:
addListener(listener)
removeListener(listener)
listener argument is the listener to remove.hasListener(listener)
listener is registered for this event. Returns true if it is listening, false otherwise.function
port
{{WebExtExamples("h2")}}
{{Compat}}