chrome.runtime.getURL()
and use the result the same as other URLs.'content_scripts'
field. They can include JavaScript files, CSS files or both. All auto-run content scripts must specify match patterns.Name | Type | Description |
---|---|---|
matches | array of strings | Required. Specifies which pages this content script will be injected into. See Match Patterns for more details on the syntax of these strings and Match patterns and globs for information on how to exclude URLs. |
css | array of strings | Optional. The list of CSS files to be injected into matching pages. These are injected in the order they appear in this array, before any DOM is constructed or displayed for the page. |
js | Optional. The list of JavaScript files to be injected into matching pages. These are injected in the order they appear in this array. | |
match_about_blank | boolean | Optional. Whether the script should inject into an about:blank frame where the parent or opener frame matches one of the patterns declared in matches . Defaults to false. |
Name | Type | Description |
---|---|---|
exclude_matches | array of strings | Optional. Excludes pages that this content script would otherwise be injected into. See Match Patterns for more details on the syntax of these strings. |
include_globs | array of strings | Optional. Applied after matches to include only those URLs that also match this glob. Intended to emulate the @include Greasemonkey keyword. |
exclude_globs | array of string | Optional. Applied after matches to exclude URLs that match this glob. Intended to emulate the @exclude Greasemonkey keyword. |
matches
pattern and any include_globs
pattern, as long as the URL doesn't also match an exclude_matches
or exclude_globs
pattern.matches
property is required, exclude_matches
, include_globs
, and exclude_globs
can only be used to limit which pages will be affected.run_at
field. The preffered and default field is 'document_idle'
, but can also be specified as 'document_start'
or 'document_end'
if needed.Name | Type | Description |
---|---|---|
document_idle | string | Prefered. Use 'document_idle' whenever possible. The browser chooses a time to inject scripts between 'document_end' and immediately after the window.onload event fires. The exact moment of injection depends on how complex the document is and how long it is taking to load, and is optimized for page load speed. Content scripts running at 'document_idle' do not need to listen for the window.onload event, they are guaranteed to run after the DOM is complete. If a script definitely needs to run after window.onload , the extension can check if onload has already fired by using the document.readyState property. |
document_start | string | Scripts are injected after any files from css , but before any other DOM is constructed or any other script is run. |
document_end | string | Scripts are injected immediately after the DOM is complete, but before subresources like images and frames have loaded. |
'all_frames'
field allows the extension to specify if JavaScript and CSS files should be injected into all frames matching the specified URL requirements or only into the topmost frame in a tab.Name | Type | Description |
---|---|---|
all_frames | boolean | Optional. Defaults to false , meaning that only the top frame is matched. If specified true , it will inject into all frames, even if the frame is not the topmost frame in the tab. Each frame is checked independently for URL requirements, it will not inject into child frames if the URL requirements are not met. |
window.postMessage
: