I'm using following code to block paste to certain webpages:
document.addEventListener('paste', (event) => {
event.preventDefault();
});
It works in most cases except for prompt box in https://chatgpt.com
. Here is what I did step by step:
https://chatgpt.com
with chrome for Windows.I wonder how it pastes text and is there any way to block it?
Update:
Thanks to @Unmitigated, ChatGPT works now with useCapture
set to true.
document.addEventListener('paste', (event) => {
event.preventDefault();
}, true);
However, I find more sites that don't work even with useCapture
set to true, for example Gmail:
https://gmail.com
with Chrome on Windows.You could use event capturing and also stop the event from propagating.
document.addEventListener('paste', (event) => {
event.preventDefault();
event.stopPropagation();
}, true);