tabs.insertCSS()

Injects CSS into a page. For details, see the programmatic injection section of the content scripts doc.

Syntax

browser.tabs.insertCSS(
  tabId,           // optional integer
  details,         // extensionTypes.InjectDetails
  function() {...} // optional function
)

Parameters

tabIdOptional
integer. The ID of the tab in which to insert the CSS; defaults to the active tab of the current window.
details
extensionTypes.InjectDetails. Details of the CSS text to insert.

Values of this type are objects. They contain the following properties:

codeOptional
string. JavaScript or CSS code to inject.

Warning:
Be careful using the code parameter. Incorrect use of it may open your extension to cross-site scripting attacks.
fileOptional
string. JavaScript or CSS file to inject.
allFramesOptional
boolean. If allFrames is true, implies that the JavaScript or CSS should be injected into all frames of the current page. By default, it's false and is only injected into the top frame.
matchAboutBlankOptional
boolean. If matchAboutBlank is true, then the code is also injected in about:blank and about:srcdoc frames if your extension has access to its parent document. The code cannot be inserted in top-level about:-frames. By default it is false.
runAtOptional
extensionTypes.RunAt. The soonest that the JavaScript or CSS will be injected into the tab. Defaults to "document_idle".
callbackOptional
function. Called when all the CSS has been inserted.

Browser compatibility

EdgeFirefoxChromeOpera
Basic support?47.0Yes33
Firefox
Basic supportNo

Examples

Acknowledgements

This API is based on Chromium's chrome.tabs API. This documentation is derived from tabs.json in the Chromium code.

Document Tags and Contributors

 Contributors to this page: wbamberg, kmaglione
 Last updated by: wbamberg,