Tampermonkey® by Jan Biniok

Content Script API

Script execution is handled by wrapper code that runs or injects the actual userscripts. There are various methods and APIs available for this, and the Content Script API setting in Tampermonkey determines how and where the wrapper code is executed.

This setting is available in Firefox and Chrome (Manifest V3) versions of the extension.

The following options are available for the Content Script API setting:

  • Content Script: Runs the wrapper code as a content script or via the content script API. This is the default option if not explicitly selected. Userscripts are retrieved via messaging from the background script, no real document-start support.
  • UserScripts API: Uses the browser's UserScripts API (MV3|MV2) to inject the wrapper code.
    • Chrome: Userscripts are retrieved via messaging from the background script, no real document-start support.
    • Firefox: The userscript is executed instantly -> document-start is supported.
  • UserScripts API Dynamic: Uses the browser's UserScripts API (MV3|MV2) to inject both the wrapper code and the userscript code. The userscript is executed instantly -> document-start is supported.

Some known MV3 issues with the Content Script API setting include:

  • Dynamic Mode Limitations: In Dynamic Mode, @include patterns using regular expressions may cause scripts to be injected into every frame.
  • External Resource Updates: Tampermonkey does not automatically update external @resources.