Search code examples
javascriptgoogle-chrome-extensioncopy-paste

Disable copy and paste


I have used following code to disable copy paste

onpaste="return false;" oncut="return false;" oncontextmenu="return false;" oncopy="return false;".

This works all fine. I have install "easy-copy" extension in Google Chrome and can still copy paste. Is there a way to disable copy and paste from extensions as well?

I tried to capture all the events to see what even that extension fire to paste but it doesn't fire any even for pasting.

For event capturing, I used following code in chrome console:

monitorEvents($0)

In short, how to disable copy paste from browser extension? Why do I need this? I have a chat application and some people copy paste to spam.


Solution

  • In short, how to disable copy paste from browser extension?

    I don't think this is possible from the page Javascript, because extensions run at a higher trust level than the webpage. They can do things that webpages cannot such as change the browser's own behavior.

    In my opinion the best way to handle this is server-side. Give each post a spam score determined by relevant factors such as frequency of posts from the same user, duplicate content in posts, external links only, downvotes from other users... If a post exceeds a spam score limit, don't show it to other users. You could still show it to the poster herself if you want to make it harder for spammers to determine whether their spam is actually getting through.

    Disabling copy-paste for all users seems heavy handed to me.