I'm copying some text from a google doc to the clipboard and inspecting its content.
I've tried inspecting it by using the paste event and by using the clipboard API.
When inspecting with the paste event, it exposes 3 items, but when using the clipboard API, only two items are available.
Here's my code for clipboard API, this only prints two items:
navigator.clipboard.read().then(clipboardItems => {
for (const clipboardItem of clipboardItems) {
for (const type of clipboardItem.types) {
clipboardItem.getType(type).then(blob => blob.text())
.then(console.log);
}
}
})
And here's my code using the paste event. Three items are available.
target.addEventListener('paste', (event) => {
let items = event.clipboardData.items
for(let i of items){
if(i.kind==='string'){
i.getAsString(console.log)
}
}
event.preventDefault();
});
Basically when using the paste event there's a new item of type application/x-vnd.google-docs-document-slice-clip+wrapped. Why doesn't it come up when using clipboard API?
This tool might be helpful to inspect the clipboard.