Skip to content

API > wxt > MainWorldContentScriptDefinition

Interface: MainWorldContentScriptDefinition ​

Contents ​

Extends ​

Properties ​

allFrames ​

allFrames?: PerBrowserOption<undefined | boolean>

See https://developer.chrome.com/docs/extensions/mv3/content_scripts/

Default ​

ts
false

Inherited from ​

MainWorldContentScriptEntrypointOptions.allFrames

Source ​

packages/wxt/src/types.ts:682


cssInjectionMode ​

cssInjectionMode?: PerBrowserOption<"manifest" | "manual" | "ui">

Customize how imported/generated styles are injected with the content script. Regardless of the mode selected, CSS will always be built and included in the output directory.

  • "manifest" - Include the CSS in the manifest, under the content script's css array.
  • "manual" - Exclude the CSS from the manifest. You are responsible for manually loading it onto the page. Use browser.runtime.getURL("content-scripts/<name>.css") to get the file's URL
  • "ui" - Exclude the CSS from the manifest. CSS will be automatically added to your UI when calling createShadowRootUi

Default ​

ts
'manifest'

Inherited from ​

MainWorldContentScriptEntrypointOptions.cssInjectionMode

Source ​

packages/wxt/src/types.ts:705


exclude ​

exclude?: string[]

List of target browsers to exclude this entrypoint from. Cannot be used with include. You must choose one of the two options.

Default ​

ts
undefined

Inherited from ​

MainWorldContentScriptEntrypointOptions.exclude

Source ​

packages/wxt/src/types.ts:600


excludeGlobs ​

excludeGlobs?: PerBrowserOption<undefined | string[]>

See https://developer.chrome.com/docs/extensions/mv3/content_scripts/

Default ​

ts
[ ]

Inherited from ​

MainWorldContentScriptEntrypointOptions.excludeGlobs

Source ​

packages/wxt/src/types.ts:676


excludeMatches ​

excludeMatches?: PerBrowserOption<undefined | string[]>

See https://developer.chrome.com/docs/extensions/mv3/content_scripts/

Default ​

ts
[ ]

Inherited from ​

MainWorldContentScriptEntrypointOptions.excludeMatches

Source ​

packages/wxt/src/types.ts:664


globalName ​

globalName?: string | boolean | (entrypoint) => string

The variable name for the IIFE in the output bundle.

This option is relevant for scripts inserted into the page context where the default IIFE variable name may conflict with an existing variable on the target page. This applies to content scripts with world=MAIN, and others, such as unlisted scripts, that could be dynamically injected into the page with a <script> tag.

Available options:

  • true: automatically generate a name for the IIFE based on the entrypoint name
  • false: Output the IIFE without a variable name, making it anonymous. This is the safest option to avoid conflicts with existing variables on the page. This will become the default in a future version of WXT.
  • string: Use the provided string as the global variable name.
  • function: A function that receives the entrypoint and returns a string to use as the variable name.

Default ​

ts
true

Inherited from ​

MainWorldContentScriptEntrypointOptions.globalName

Source ​

packages/wxt/src/types.ts:640


include ​

include?: string[]

List of target browsers to include this entrypoint in. Defaults to being included in all builds. Cannot be used with exclude. You must choose one of the two options.

Default ​

ts
undefined

Inherited from ​

MainWorldContentScriptEntrypointOptions.include

Source ​

packages/wxt/src/types.ts:593


includeGlobs ​

includeGlobs?: PerBrowserOption<undefined | string[]>

See https://developer.chrome.com/docs/extensions/mv3/content_scripts/

Default ​

ts
[ ]

Inherited from ​

MainWorldContentScriptEntrypointOptions.includeGlobs

Source ​

packages/wxt/src/types.ts:670


matchAboutBlank ​

matchAboutBlank?: PerBrowserOption<undefined | boolean>

See https://developer.chrome.com/docs/extensions/mv3/content_scripts/

Default ​

ts
false

Inherited from ​

MainWorldContentScriptEntrypointOptions.matchAboutBlank

Source ​

packages/wxt/src/types.ts:656


matchOriginAsFallback ​

matchOriginAsFallback?: PerBrowserOption<boolean>

See https://developer.chrome.com/docs/extensions/mv3/content_scripts/

Default ​

ts
false

Inherited from ​

MainWorldContentScriptEntrypointOptions.matchOriginAsFallback

Source ​

packages/wxt/src/types.ts:688


matches ​

matches?: PerBrowserOption<string[]>

Inherited from ​

MainWorldContentScriptEntrypointOptions.matches

Source ​

packages/wxt/src/types.ts:644


noScriptStartedPostMessage ​

noScriptStartedPostMessage?: boolean

Do not send the wxt:content-script-started message via window.postMessage.

This has been replaced with custom events. The postMessage call is kept for backwards compatibility. For some websites the postMessage call is undesirable, such as those with poorly written message event listeners.

Setting this to true opts into the behavior that will become the default in a future version of WXT, where the postMessage call is removed entirely.

See https://github.com/wxt-dev/wxt/pull/1938 and https://github.com/wxt-dev/wxt/pull/2035 for a detailed discussion.

Inherited from ​

MainWorldContentScriptEntrypointOptions.noScriptStartedPostMessage

Source ​

packages/wxt/src/types.ts:734


registration ​

registration?: PerBrowserOption<"runtime" | "manifest">

Specify how the content script is registered.

  • "manifest": The content script will be added to the content_scripts entry in the manifest. This is the normal and most well known way of registering a content script.
  • "runtime": The content script's matches is added to host_permissions and you are responsible for using the scripting API to register/execute the content script dynamically at runtime.

Default ​

ts
'manifest'

Inherited from ​

MainWorldContentScriptEntrypointOptions.registration

Source ​

packages/wxt/src/types.ts:718


runAt ​

runAt?: PerBrowserOption<undefined | RunAt>

See https://developer.chrome.com/docs/extensions/mv3/content_scripts/

Default ​

ts
'documentIdle'

Inherited from ​

MainWorldContentScriptEntrypointOptions.runAt

Source ​

packages/wxt/src/types.ts:650


world ​

world: "MAIN"

See https://developer.chrome.com/docs/extensions/develop/concepts/content-scripts#isolated_world

Inherited from ​

MainWorldContentScriptEntrypointOptions.world

Source ​

packages/wxt/src/types.ts:742

Methods ​

main() ​

main(): any

Main function executed when the content script is loaded.

When running a content script with browser.scripting.executeScript, values returned from this function will be returned in the executeScript result as well. Otherwise returning a value does nothing.

Source ​

packages/wxt/src/types.ts:953


Generated using typedoc-plugin-markdown and TypeDoc