Rara pastes into the class computer’s box: the real paste event is laid out on the board, clipboardData.types in order, getData per format, image files, and…
Every comment box, editor or "paste a link" field has to handle paste. Pick the wrong format and you get stray Word styles, spreadsheet numbers glued together, or raw text/html going into innerHTML and running an onerror. That is one of the XSS paths that most often slips through code review.
One paste, many formats: types is the menu
getData('text/html') straight into innerHTML That is an XSS door: an <img onerror> from the clipboard runs. preventDefault() and insert getData('text/plain'), or clean the HTML with a sanitizer (DOMPurify, say) before rendering it.getData() A screenshot shows up in types only as "Files". It is in e.clipboardData.files (or items with kind === "file"). Loop over files and check file.type.clipboardData outside the paste event e.clipboardData can only be read while the paste handler runs; after that types is empty and getData() returns an empty string. Keep the value inside the handler. Want to read the clipboard at any time? That is another API: navigator.clipboard.readText() (async, secure context, needs permission or a Paste click).textContent or a regex, and the text comes out messy textContent picks up line breaks from the HTML source, <style> text and , but paragraph and table cell boundaries vanish. The source app already prepared a tidy text/plain: use that.types holds two: text/plain and text/html, from the same paste. Look for the <b style="font-weight:normal"> wrapper in its element tree.isTrusted becomes true. Look at the "after the handler" line on the board: types is empty, because the browser locks the clipboard once the event is over.isTrusted: false) never runs the default action; that is why a test that only calls dispatchEvent cannot prove the paste went in.types is just ["Files"], getData() is empty, and the picture comes from files[0] through URL.createObjectURL.