demo · v143
Paste sanitizer
The motivating editor use case for Chrome 143: let the paste land, read the clipboard payload from input.dataTransfer, and immediately clean the editor with the selected rules. beforeinput is logged beside it so you can see the pre-v143 contrast.
Try copying a heading, link, and image from a webpage, then pasting in here. The sanitizer keeps the structure you choose and drops the rest.
Try pasting here
The sanitizer reads dataTransfer on input, then rewrites the editor with the cleaned-up version.
paste log
the call
editor.addEventListener("beforeinput", (e) => {
if (e.inputType !== "insertFromPaste") return;
logContrast("beforeinput had dataTransfer:", !!e.dataTransfer);
});
editor.addEventListener("input", (e) => {
if (e.inputType !== "insertFromPaste") return;
// v143: the final input event carries the transfer payload too.
const html = e.dataTransfer?.getData("text/html");
if (!html) return; // older browser: leave the default paste intact
editor.innerHTML = sanitize(editor.innerHTML);
});
why this angle
The other concept just shows what's in the event. This one is the actual reason this property was added: editors that want to act after a committed paste (sanitize, transform, deduplicate links) can now do so from the same input event that represents the edit.