CSS🧪
该域公开了CSS的读写操作。所有CSS对象(样式表、规则和样式)都有一个关联的id,用于后续对相关对象的操作。每种对象类型都有特定的id结构,这些结构在不同类型的对象之间不可互换。CSS对象可以通过get*ForNode()调用(接受DOM节点id)加载。客户端还可以通过styleSheetAdded/styleSheetRemoved事件跟踪样式表,随后使用getStyleSheet[Text]()方法加载所需的样式表内容。
EN
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
🔨CSS.addRule
在指定的 styleSheetId 样式表中,根据 location 指定的位置,插入一条包含给定 ruleText 的新规则。
EN
Inserts a new rule with the given
ruleText in a stylesheet with given styleSheetId, at the position specified by location.| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| styleSheetId | ✔️ | DOM.StyleSheetId | css样式表标识符,用于指定新规则应插入的位置。 | ENThe css style sheet identifier where a new rule should be inserted. | |
| ruleText | ✔️ | string | 新规则的文本。 | ENThe text of a new rule. | |
| location | ✔️ | SourceRange | 目标样式表中新规则的文本位置。 | ENText position of a new rule in the target style sheet. | |
| nodeForPropertySyntaxValidation | 🧪 | DOM.NodeId | 注册属性自定义属性声明的验证应在哪个DOM节点的上下文中进行,其NodeId。如果省略,新规则文本中的声明只能进行静态验证,例如,如果声明包含var(),则可能产生不正确的结果。 | ENNodeId for the DOM node in whose context custom property declarations for registered properties should be validated. If omitted, declarations in the new rule text can only be validated statically, which may produce incorrect results if the declaration contains a var() for example. |
| 返回对象 | 类型 | 描述 | 原文 |
|---|---|---|---|
| rule | CSSRule | 新创建的规则。 | ENThe newly created rule. |
🔨CSS.collectClassNames
从指定样式表中返回所有类名。
EN
Returns all class names from specified stylesheet.
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| styleSheetId | ✔️ | DOM.StyleSheetId |
| 返回对象 | 类型 | 描述 | 原文 |
|---|---|---|---|
| classNames | array[string] | 类名列表。 | ENClass name list. |
🔨CSS.createStyleSheet
在给定的 frameId 框架中创建一个新的特殊 "via-inspector" 样式表。
EN
Creates a new special "via-inspector" stylesheet in the frame with given
frameId.| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| frameId | ✔️ | Page.FrameId | 应在其中创建“via-inspector”样式表的框架标识符。 | ENIdentifier of the frame where "via-inspector" stylesheet should be created. | |
| force | boolean | 如果为真,每次调用都会创建一个新的样式表。如果为假,则返回先前通过调用(force=false)为该框架文档创建的样式表(如果存在),否则创建一个新的样式表(默认值:false)。 | ENIf true, creates a new stylesheet for every call. If false, returns a stylesheet previously created by a call with force=false for the frame's document if it exists or creates a new stylesheet (default: false). |
| 返回对象 | 类型 | 描述 | 原文 |
|---|---|---|---|
| styleSheetId | DOM.StyleSheetId | 创建的“via-inspector”样式表的标识符。 | ENIdentifier of the created "via-inspector" stylesheet. |
🔨CSS.disable
禁用给定页面的CSS代理。
EN
Disables the CSS agent for the given page.
🔨CSS.enable
为给定页面启用CSS代理。在收到此命令的结果之前,客户端不应假定CSS代理已启用。
EN
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.
🔨CSS.forcePseudoState
确保在浏览器计算其样式时,给定节点将具有指定的伪类。
EN
Ensures that the given node will have specified pseudo-classes whenever its style is computed by the browser.
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| nodeId | ✔️ | DOM.NodeId | 要强制应用伪状态的目标元素ID。 | ENThe element id for which to force the pseudo state. | |
| forcedPseudoClasses | ✔️ | array[string] | 在计算元素的样式时强制应用的伪类。 | ENElement pseudo classes to force when computing the element's style. |
🔨CSS.forceStartingStyle
确保给定节点处于其起始样式状态。
EN
Ensures that the given node is in its starting-style state.
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| nodeId | ✔️ | DOM.NodeId | 要强制应用起始样式状态的元素ID。 | ENThe element id for which to force the starting-style state. | |
| forced | ✔️ | boolean | 表示此功能是开启还是关闭的布尔值。 | ENBoolean indicating if this is on or off. |
🔨CSS.getBackgroundColors
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| nodeId | ✔️ | DOM.NodeId | 获取背景颜色的节点ID。 | ENId of the node to get background colors for. |
| 返回对象 | 类型 | 描述 | 原文 |
|---|---|---|---|
| backgroundColors | array[string] | 该元素背景色的范围,如果它包含任何可见文本。如果没有可见文本,此项将为undefined。对于纯色背景,此项将仅包含该颜色。对于渐变背景,此项将包含每个颜色断点。对于更复杂的情况,此项将为空数组。图像将被忽略(如同图像加载失败)。 | ENThe range of background colors behind this element, if it contains any visible text. If no visible text is present, this will be undefined. In the case of a flat background color, this will consist of simply that color. In the case of a gradient, this will consist of each of the color stops. For anything more complicated, this will be an empty array. Images will be ignored (as if the image had failed to load). |
| computedFontSize | string | 此节点的计算字体大小,以CSS计算值字符串形式表示(例如'12px')。 | ENThe computed font size for this node, as a CSS computed value string (e.g. '12px'). |
| computedFontWeight | string |