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.
Wasm guides
Editing approaches
contenteditable + WASM: source of truth, event order, DOM↔model loop, normalization, and when to call Rust.
IME & composition
composition events, syncing a Rust document model, and why the browser still owns the IME.
JS ↔ WASM boundary
Strings, copies, batched ops, async vs input events, and keeping the hot path cheap.
Tooling, bundle & workers
wasm-pack, wasm-opt, code splitting, Web Workers, COOP/COEP and threads.
Collaboration & CRDT (WASM)
Yrs/y-crdt, bridging to Yjs, snapshots vs update streams with an editor host.
Selection, Range & offsets
UTF-16 vs UTF-8 indices, Selection/Range in JS, mapping to a Rust model and getTargetRanges.
Undo & redo model
Browser undo stack vs model history, programmatic DOM, and WASM-hosted transactions.
Accessibility (WASM host)
Roles, focus, screen readers when the editable surface is still the browser.
Testing & debugging
E2E, profiling the JS↔WASM boundary, reproducing IME and paste in CI.
Security & deployment
CSP, SRI, module integrity, and hosting WASM next to contenteditable.