Inserts JavaScript and CSS into websites. This API offers two approaches to inserting content:
-
scripting.executeScript(),scripting.insertCSS(), andscripting.removeCSS()that provide for one-off injections. -
scripting.registerContentScripts()that registers content scripts dynamically, which can then be retrieved withscripting.getRegisteredContentScripts()and unregistered withscripting.unregisterContentScripts()).
Note: Chrome restricts this API to Manifest V3. Firefox and Safari support this API in Manifest V2 and V3.
This API requires the "scripting" permission and host permission for the target in the tab into which JavaScript or CSS is injected.
Alternatively, you can get permission temporarily in the active tab and only in response to an explicit user action, by asking for the "activeTab" permission. However, the "scripting" permission is still required.