Agent SkillsChromeDevTools/devtools-frontend › devtools-unicode-escaping

devtools-unicode-escaping

GitHub

提供DevTools中Unicode转义及用户可控数据处理的指南,防止布局错乱与XSS漏洞。涵盖文本表示、UI渲染及Lit模板自动转义机制的使用规范。

.agents/skills/devtools-unicode-escaping/SKILL.md ChromeDevTools/devtools-frontend

Trigger Scenarios

处理DevTools界面中的用户输入或不可信数据 在控制台或DOM树中显示字符串值 使用Lit模板渲染包含动态内容的UI组件

Install

npx skills add ChromeDevTools/devtools-frontend --skill devtools-unicode-escaping -g -y
More Options

Non-standard path

npx skills add https://github.com/ChromeDevTools/devtools-frontend/tree/main/.agents/skills/devtools-unicode-escaping -g -y

Use without installing

npx skills use ChromeDevTools/devtools-frontend@devtools-unicode-escaping

指定 Agent (Claude Code)

npx skills add ChromeDevTools/devtools-frontend --skill devtools-unicode-escaping -a claude-code -g -y

安装 repo 全部 skill

npx skills add ChromeDevTools/devtools-frontend --all -g -y

预览 repo 内 skill

npx skills add ChromeDevTools/devtools-frontend --list

SKILL.md

Frontmatter
{
    "name": "devtools-unicode-escaping",
    "description": "Guidelines for escaping strings and handling user-controlled data in DevTools to prevent layout bleed-through, XSS, and security issues."
}

Unicode Escaping and User-Controlled Data Guidelines

When displaying inspected data, user-controlled strings, or untrusted input in the DevTools UI (e.g., console messages, object properties, DOM tree nodes, or UI titles/descriptions), you must ensure they are properly escaped to prevent layout bleed-through (such as Right-to-Left leaks) or security vulnerabilities.

DevTools provides two primary Unicode escaping functions in Platform.StringUtilities:

1. Escaping for Text Representation (escapeUnicodeAsText)

Use Platform.StringUtilities.escapeUnicodeAsText(content) when rendering values that developers need to inspect (e.g. string values inside the Console or the Object properties view) where hidden, invisible, or formatting characters should be made explicitly visible.

  • Behavior: Escapes all formatting and surrogate characters into literal Unicode escape sequences (e.g., \u202E, \u200B).
  • Example Usage:
    const text = Platform.StringUtilities.escapeUnicodeAsText(JSON.stringify(description));
    

2. Escaping for UI Rendering (safeEscapeUnicode)

Use Platform.StringUtilities.safeEscapeUnicode(content) when rendering content inside templates or HTML markup where you want safe layout-critical zero-width formatting characters to function normally for word wrapping or rendering layout, but want to escape dangerous layout-disrupting characters (like bidi overrides).

  • Behavior: Escapes dangerous formatting and surrogate characters (like \u202E), but leaves safe formatting characters untouched:
    • Zero Width Space (\u200B)
    • Zero Width Non-Joiner (\u200C)
    • Zero Width Joiner (\u200D)
  • Example Usage: Used automatically by the global Lit template wrapper.

3. Global Lit Template Wrapper

DevTools wraps Lit's default html function inside front_end/ui/lit/strip-whitespace.ts (re-exported via ui/lit/lit.js). This wrapper automatically intercepts and escapes standard string values using Platform.StringUtilities.safeEscapeUnicode(val) at runtime.

  • What is escaped automatically: Any standard string interpolated directly in a template (e.g., html${myString}``).
  • Array items: Array values are traversed recursively, and string elements inside arrays are escaped automatically.
  • Lit directives: Directives (like ifDefined, live, repeat, classMap, etc.) are automatically traversed, and any string arguments inside their values array are escaped recursively.

Directives Rule:

Because the wrapper automatically processes directive arguments, you do not need to manually escape strings passed to standard Lit directives. They will be handled safely at runtime.

Correct Example:

title=${ifDefined(tooLong ? undefined : description)} // Automatically escaped!

4. Manual DOM Assignments & Non-Lit Rendering

Any manual assignments that bypass Lit entirely (e.g., setting element.textContent, element.title, or constructing DOM elements imperatively) will also bypass the Lit wrapper.

  • Always wrap user-controlled strings in these contexts with the appropriate escaping helper:
    • Use escapeUnicodeAsText if you want hidden characters to display as text (e.g., showing \\u202E).
    • Use safeEscapeUnicode if you want zero-width spaces to function but other dangerous characters to be escaped.

Correct Example:

nameElement.textContent = Platform.StringUtilities.escapeUnicodeAsText(name);

Version History

  • 678d19c Current 2026-08-20 15:20

Same Skill Collection

.agents/skills/devtools-ci/SKILL.md
.agents/skills/devtools-imports/SKILL.md
.agents/skills/devtools-model-management/SKILL.md
.agents/skills/devtools-setting-migration/SKILL.md
.agents/skills/devtools-source-maps/SKILL.md
.agents/skills/devtools-testing-guidance/SKILL.md
.agents/skills/devtools-ux-writing-refactor/SKILL.md
.agents/skills/devtools-verification/SKILL.md
.agents/skills/evaluate-ai-css-completion/SKILL.md
.agents/skills/fixing-skipped-tests/SKILL.md
.agents/skills/foundation-test-migration/SKILL.md
.agents/skills/gerrit-cli/SKILL.md
.agents/skills/merging-devtools-module/SKILL.md
.agents/skills/migrate-chromium-test/SKILL.md
.agents/skills/ui-eng-vision-local-lit-renderer/SKILL.md
.agents/skills/ui-eng-vision-logic-consolidator/SKILL.md
.agents/skills/ui-eng-vision-orchestrator/SKILL.md
.agents/skills/ui-eng-vision-test-scaffolder/SKILL.md
.agents/skills/ui-eng-vision-widget-promoter/SKILL.md
.agents/skills/ui-widgets/SKILL.md
.agents/skills/version-control/SKILL.md
.agents/skills/repro-flaky-tests/SKILL.md

Metadata

Files
0
Version
678d19c
Hash
7be58390
Indexed
2026-08-20 15:20

- 위키
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-25 12:07
浙ICP备14020137号-1 $방문자$