Phenomenon
When serializing contenteditable content (e.g., using innerHTML) in Chrome, special characters may be encoded as HTML entities or kept as actual characters inconsistently. This makes it difficult to predict the output format.
Reproduction example
- Insert text with special characters:
<div>Test</div> - Serialize using
element.innerHTML - Observe the output
Observed behavior
- Characters may be encoded:
<div>Test</div> - Or characters may be kept as-is:
<div>Test</div> - Encoding is inconsistent
- Output format is unpredictable
Expected behavior
- Entity encoding should be consistent
- Or encoding should be predictable
- Special characters should be handled correctly
- Output format should be reliable
Browser Comparison
- Chrome/Edge: Encoding inconsistent (this case)
- Firefox: Similar encoding inconsistency
- Safari: Encoding behavior varies
Notes and possible direction for workarounds
- Normalize entity encoding after serialization
- Use consistent encoding strategy
- Document expected encoding behavior
- Handle special characters explicitly