runtime.onUserScriptConnect

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 userScripts.configureWorld() with messaging set to true.

Syntax

js
browser.runtime.onUserScriptConnect.addListener(listener)
browser.runtime.onUserScriptConnect.removeListener(listener)
browser.runtime.onUserScriptConnect.hasListener(listener)

Events have three functions:

addListener(listener)

Adds a listener to this event.

removeListener(listener)

Stop listening to this event. The listener argument is the listener to remove.

hasListener(listener)

Checks whether a listener is registered for this event. Returns true if it is listening, false otherwise.

addListener syntax

Parameters

function

The function called when this event occurs. The function is passed this argument:

port

runtime.Port. An object connecting the current script to the other context.

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Firefox for Android
Safari on iOS
onUserScriptConnect
Chrome – Full support
Chrome 120 (Release date: 2023-12-05)
footnote
footnote Available for use with Manifest V3 only.
footnote Always available, even if the extension has no way of firing the event.
Edge – Full support
Edge 120 (Release date: 2023-12-07)
footnote
footnote Available for use with Manifest V3 only.
footnote Always available, even if the extension has no way of firing the event.
Firefox – Full support
Firefox 136 (Release date: 2025-03-04)
footnote
footnote Available for use with Manifest V3 only.
footnote Requires the userScripts permission.
Opera – Full support
Opera 106 (Release date: 2023-12-19)
footnote
footnote Available for use with Manifest V3 only.
footnote Always available, even if the extension has no way of firing the event.
Safari – No support
Safari
footnote No support
Firefox for Android – No support
Firefox for Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
See implementation notes.