> For AI agents: the complete documentation index is available at /next/zh/llms.txt, the full documentation bundle is available at /next/zh/llms-full.txt.

# CSS

本页面介绍 Lynx DevTool 支持的 `CSS` CDP domain。



:::warning 实验性参考
此生成的参考文档仍在完善中。

- CDP events 尚未包含。
- 部分 Lynx 扩展已列出，但尚未提供详细文档。
- 方法说明尚未根据实现自动校验，可能不完整或不准确。

在依赖本参考前，请根据实现及所链接的 upstream CDP reference 验证实际行为。
:::

## 概览

- 作用域：`instance`
- CDP domain：[CSS](https://chromedevtools.github.io/devtools-protocol/tot/CSS/)

## 标准方法

- [CSS.addRule](https://chromedevtools.github.io/devtools-protocol/tot/CSS/#method-addRule)
- [CSS.createStyleSheet](https://chromedevtools.github.io/devtools-protocol/tot/CSS/#method-createStyleSheet)
- [CSS.disable](https://chromedevtools.github.io/devtools-protocol/tot/CSS/#method-disable)
- [CSS.enable](https://chromedevtools.github.io/devtools-protocol/tot/CSS/#method-enable)
- [CSS.getBackgroundColors](https://chromedevtools.github.io/devtools-protocol/tot/CSS/#method-getBackgroundColors)
- [CSS.getComputedStyleForNode](https://chromedevtools.github.io/devtools-protocol/tot/CSS/#method-getComputedStyleForNode)
- [CSS.getInlineStylesForNode](https://chromedevtools.github.io/devtools-protocol/tot/CSS/#method-getInlineStylesForNode)
- [CSS.getLayersForNode](https://chromedevtools.github.io/devtools-protocol/tot/CSS/#method-getLayersForNode)
- [CSS.getMatchedStylesForNode](https://chromedevtools.github.io/devtools-protocol/tot/CSS/#method-getMatchedStylesForNode)
- [CSS.getMediaQueries](https://chromedevtools.github.io/devtools-protocol/tot/CSS/#method-getMediaQueries)
- [CSS.getStyleSheetText](https://chromedevtools.github.io/devtools-protocol/tot/CSS/#method-getStyleSheetText)
- [CSS.setMediaText](https://chromedevtools.github.io/devtools-protocol/tot/CSS/#method-setMediaText)
- [CSS.setStyleSheetText](https://chromedevtools.github.io/devtools-protocol/tot/CSS/#method-setStyleSheetText)
- [CSS.setStyleTexts](https://chromedevtools.github.io/devtools-protocol/tot/CSS/#method-setStyleTexts)
- [CSS.setSupportsText](https://chromedevtools.github.io/devtools-protocol/tot/CSS/#method-setSupportsText)
- [CSS.startRuleUsageTracking](https://chromedevtools.github.io/devtools-protocol/tot/CSS/#method-startRuleUsageTracking)
- [CSS.stopRuleUsageTracking](https://chromedevtools.github.io/devtools-protocol/tot/CSS/#method-stopRuleUsageTracking)

## Lynx 扩展

### `CSS.updateRuleUsageTracking`

Records selectors that should be marked as used by the Lynx CSS rule usage tracker.

- Origin: `lynx-extension`
- Source: `devtool/lynx_devtool/agent/domain_agent/inspector_css_agent_ng.cc`

###### 参数

| Name         | Type     | Required | Description                                                                                                           |
| ------------ | -------- | -------- | --------------------------------------------------------------------------------------------------------------------- |
| `selector`   | `array`  | No       | Selector strings to add to the current CSS rule usage set while CSS rule usage tracking is active.                    |
| `selector[]` | `string` | Yes      | Selector text. The native handler stores the string as-is and later searches for it in the generated stylesheet text. |

###### 返回字段

无返回字段。

###### 备注

- Dispatches through LynxDevToolMediator to InspectorTasmExecutor on the TASM thread.
- This method is only effective after CSS.startRuleUsageTracking has enabled rule usage tracking.
- The handler inserts each params.selector item into an in-memory selector set and does not send a CDP response.
- CSS.stopRuleUsageTracking later emits the collected selectors as ruleUsage entries. Each entry contains styleSheetId, startOffset, endOffset, and used.
- When CSS.stopRuleUsageTracking runs with no selectors collected by this method, Lynx falls back to collecting id and class selector usage from the DOM tree.

###### 示例

**Mark selectors as used during tracking**

Request:

```json
{
  "id": 1,
  "method": "CSS.updateRuleUsageTracking",
  "params": {
    "selector": ["#app", ".title"]
  }
}
```

