CSS

This domain exposes CSS read/write operations. All CSS objects (stylesheets, rules, and styles) have an associated id used in subsequent operations on the related object. Each object type has a specific id structure, and those are not interchangeable between objects of different kinds. CSS objects can be loaded using the get*ForNode() calls (which accept a DOM node id). A client can also keep track of stylesheets via the styleSheetAdded/styleSheetRemoved events and subsequently load the required stylesheet contents using the getStyleSheet[Text]() methods.

Methods enable, disable, getInlineStylesForNode, getMatchedStylesForNode, getPlatformFontsForNode, getComputedStyleForNode
Events styleSheetAdded, styleSheetChanged, styleSheetRemoved
Types StyleSheetId, PseudoElementMatches, InheritedStyleEntry, RuleMatch, Value, SelectorList, CSSRule, SourceRange, ShorthandEntry, CSSStyle, CSSProperty, CSSMedia, MediaQuery, MediaQueryExpression, PlatformFontUsage, CSSKeyframesRule, CSSKeyframeRule, CSSComputedStyleProperty, CSSStyleSheetHeader
Dependencies DOM

Methods

enable

Enables the CSS agent for the given page. Clients should not assume that the CSS agent has been enabled until the result of this command is received.


disable

Disables the CSS agent for the given page.


getInlineStylesForNode

Returns the styles defined inline (explicitly in the "style" attribute and implicitly, using DOM attributes) for a DOM node identified by nodeId.

Parameters
nodeId DOM.NodeId
Returns
inlineStyle
optional
CSSStyle Inline style for the specified DOM node.
attributesStyle
optional
CSSStyle Attribute-defined element style (e.g. resulting from "width=20 height=100%").


getMatchedStylesForNode

Returns requested styles for a DOM node identified by nodeId.

Parameters
nodeId DOM.NodeId
Returns
inlineStyle
optional
CSSStyle Inline style for the specified DOM node.
attributesStyle
optional
CSSStyle Attribute-defined element style (e.g. resulting from "width=20 height=100%").
matchedCSSRules
optional
RuleMatch[] CSS rules matching this node, from all applicable stylesheets.
pseudoElements
optional
PseudoElementMatches[] Pseudo style matches for this node.
inherited
optional
InheritedStyleEntry[] A chain of inherited styles (from the immediate node parent up to the DOM tree root).
cssKeyframesRules
optional
CSSKeyframesRule[] A list of CSS keyframed animations matching this node.


getPlatformFontsForNode

Requests information about platform fonts which we used to render child TextNodes in the given node.

Parameters
nodeId DOM.NodeId
Returns
fonts PlatformFontUsage[] Usage statistics for every employed platform font.


getComputedStyleForNode

Returns the computed style for a DOM node identified by nodeId.

Parameters
nodeId DOM.NodeId
Returns
computedStyle CSSComputedStyleProperty[] Computed style for the specified DOM node.


Events

styleSheetAdded

Fired whenever an active document stylesheet is added.

Parameters
header CSSStyleSheetHeader Added stylesheet metainfo.


styleSheetChanged

Fired whenever a stylesheet is changed as a result of the client operation.

Parameters
styleSheetId StyleSheetId


styleSheetRemoved

Fired whenever an active document stylesheet is removed.

Parameters
styleSheetId StyleSheetId Identifier of the removed stylesheet.


Types

StyleSheetId string


PseudoElementMatches object

CSS rule collection for a single pseudo style.

Properties
pseudoType DOM.PseudoType Pseudo element type.
matches RuleMatch[] Matches of CSS rules applicable to the pseudo style.


InheritedStyleEntry object

Inherited CSS rule collection from ancestor node.

Properties
inlineStyle
optional
CSSStyle The ancestor node's inline style, if any, in the style inheritance chain.
matchedCSSRules RuleMatch[] Matches of CSS rules matching the ancestor node in the style inheritance chain.


RuleMatch object

Match data for a CSS rule.

Properties
rule CSSRule CSS rule in the match.


Value object

Data for a simple selector (these are delimited by commas in a selector list).

Properties
text string Value text.
range
optional
SourceRange Value range in the underlying resource (if available).


SelectorList object

Selector list data.

Properties
selectors Value[] Selectors in the list.
text string Rule selector text.


CSSRule object

CSS rule representation.

Properties
styleSheetId
optional
StyleSheetId The css style sheet identifier (absent for user agent stylesheet and user-specified stylesheet rules) this rule came from.
selectorList
optional
SelectorList Rule selector data.
origin
optional
<StyleSheetOrigin Parent stylesheet's origin.
style CSSStyle Associated style declaration.
media
optional
CSSMedia[] Media list array (for rules involving media queries). The array enumerates media queries starting with the innermost one, going outwards.


SourceRange object

Text range within a resource. All numbers are zero-based.

Properties
startLine integer Start line of range.
startColumn integer Start column of range (inclusive).
endLine integer End line of range
endColumn integer End column of range (exclusive).


ShorthandEntry object

Properties
name string Shorthand name.
value string Shorthand value.
important
optional
boolean Whether the property has "!important" annotation (implies `false` if absent).


CSSStyle object

CSS style representation.

Properties
styleSheetId
optional
StyleSheetId The css style sheet identifier (absent for user agent stylesheet and user-specified stylesheet rules) this rule came from.
cssProperties CSSProperty[] CSS properties in the style.
shorthandEntries ShorthandEntry[] Computed values for all shorthands found in the style.
cssText
optional
string Style declaration text (if available).
range
optional
SourceRange Style declaration range in the enclosing stylesheet (if available).


CSSProperty object

CSS property declaration data.

Properties
name string The property name.
value string The property value.
important
optional
boolean Whether the property has "!important" annotation (implies `false` if absent).
implicit
optional
boolean Whether the property is implicit (implies `false` if absent).
text
optional
string The full property text as specified in the style.
parsedOk
optional
boolean Whether the property is understood by the browser (implies `true` if absent).
disabled
optional
boolean Whether the property is disabled by the user (present for source-based properties only).
range
optional
SourceRange The entire property range in the enclosing style declaration (if available).


CSSMedia object

CSS media rule descriptor.

Properties
text string Media query text.
source string
Allowed values: mediaRule, importRule, linkedSheet, inlineSheet
Source of the media query: "mediaRule" if specified by a @media rule, "importRule" if specified by an @import rule, "linkedSheet" if specified by a "media" attribute in a linked stylesheet's LINK tag, "inlineSheet" if specified by a "media" attribute in an inline stylesheet's STYLE tag.
sourceURL
optional
string URL of the document containing the media query description.
range
optional
SourceRange The associated rule (@media or @import) header range in the enclosing stylesheet (if available).
styleSheetId
optional
StyleSheetId Identifier of the stylesheet containing this object (if exists).
mediaList
optional
MediaQuery[] Array of media queries.


MediaQuery object

Media query descriptor.

Properties
expressions MediaQueryExpression[] Array of media query expressions.
active boolean Whether the media query condition is satisfied.


MediaQueryExpression object

Media query expression descriptor.

Properties
value number Media query expression value.
unit string Media query expression units.
feature string Media query expression feature.
valueRange
optional
SourceRange The associated range of the value text in the enclosing stylesheet (if available).
computedLength
optional
number Computed length of media query expression (if applicable).


PlatformFontUsage object

Information about amount of glyphs that were rendered with given font.

Properties
familyName string Font's family name reported by platform.
isCustomFont boolean Indicates if the font was downloaded or resolved locally.
glyphCount number Amount of glyphs that were rendered with this font.


CSSKeyframesRule object

CSS keyframes rule representation.

Properties
animationName Value Animation name.
keyframes CSSKeyframeRule[] List of keyframes.


CSSKeyframeRule object

CSS keyframe rule representation.

Properties
styleSheetId
optional
StyleSheetId The css style sheet identifier (absent for user agent stylesheet and user-specified stylesheet rules) this rule came from.
origin StyleSheetOrigin Parent stylesheet's origin.
keyText Value Associated key text.
style CSSStyle Associated style declaration.


CSSComputedStyleProperty object

Properties
name string Computed style property name.
value string Computed style property value.


CSSStyleSheetHeader object

CSS stylesheet metainformation.

Properties
styleSheetId StyleSheetId The stylesheet identifier.
sourceURL string Stylesheet resource URL.
disabled boolean Denotes whether the stylesheet is disabled.
isInline boolean Whether this stylesheet is created for STYLE tag by parser. This flag is not set for document.written STYLE tags.
startLine number Line offset of the stylesheet within the resource (zero based).
startColumn number Column offset of the stylesheet within the resource (zero based).
length number Size of the content (in characters).


Dependencies

DOM