Get to know MDN better
Injects a user script into a target context (e.g., tab or frame).
Note: By default, the injected script is executed at document_idle, or immediately if the page is loaded. If the injectImmediately property is set to true, the script injects without waiting, even if the page is loading.
An object specifying what user scripts to inject, where, and how.
injectImmediately Optionalboolean. If set to true, the injection is triggered as soon as possible in the target context. This doesn't guarantee that the injection occurs before the page finishes loading, as the page may load before the script has reached the target.
jsarray of userScripts.ScriptSource. The scripts to inject into matching pages.
targetAn object that defines the target context scripts are injected into.
allFrames Optionalboolean. If set to true, the script is injected into all available frames. Defaults to false, in which the script is only injected into the top frame.
documentIds Optionalarray of string. The IDs of the documents to inject into. Must not be specified if frameIds is set.
frameIds Optionalarray of integer. The IDs of the frames to inject into. Must not be specified if documentIds is set.
tabIdinteger. The ID of a tab to inject into.
world OptionaluserScripts.ExecutionWorld. The execution environment to use to run the scripts. Defaults to "USER_SCRIPT".
worldId Optionalstring. ID of a user script world the script executes in. Only valid if world is USER_SCRIPT or omitted. If worldId is omitted, the script is executed in the default USER_SCRIPT world (""). Values with leading underscores (_) are reserved. The maximum length is 256 characters. A world can be used by several scripts as their execution environment. To configure the behavior of a world, pass its worldId to userScripts.configureWorld before the first script executes in that world.
A Promise fulfilled with an array of objects describing the outcome of the injection with these properties:
documentIdstring. Document ID associated with the injection.
error Optionalstring. Error message if any. This is mutually exclusive with result
frameIdinteger. Frame ID associated with the injection.
result Optionalstring. Result of the script injection if any. This is mutually exclusive with error
Enable JavaScript to view this browser compatibility table.
This page was last modified on May 6, 2026 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.