Clipboard & input routing

Decide what runs in the JS event handler vs what crosses into WASM for HTML cleanup, normalization, or schema enforcement.

Overview

Paste delivers rich HTML, plain text, or files. Browsers normalize whitespace differently. Your Rust core may be the best place for deterministic parsing—but you still receive raw clipboard data on the JS side (clipboardData, async Clipboard API).

Cross-reference: JS ↔ WASM boundary for passing payloads without copying megabytes per paste.

beforeinput & paste

Use beforeinput where you need to cancel or modify incoming edits. IME and some platforms restrict cancelability—see site scenarios on beforeinput and composition.

For paste, typical flow: JS reads clipboard data → optional quick pre-filter → WASM parses/sanitizes → returns ops or clean HTML string → JS applies to DOM or model.

Where to sanitize

  • Rust/WASM: deterministic, testable HTML/XML subset handling; good for shared native + web pipelines.
  • JS: easier integration with DOMParser and existing browser APIs; may duplicate rules if you also ship native.

Whatever you choose, keep one policy: mismatched sanitize layers between paste and load paths are a common XSS footgun.

Clipboard APIs

Async clipboard read requires user gesture and permissions in many browsers; plan fallbacks. Copy/cut may need synthetic events when integrating with custom selection models.

Related doc: Editor → Sanitization & security.