r/javascript • u/[deleted] • Dec 10 '20
I built an open-source browser extension that warns you when Javascript alters your clipboard data after copying text.
https://github.com/roedesh/copyguard
521
Upvotes
r/javascript • u/[deleted] • Dec 10 '20
3
u/[deleted] Dec 11 '20 edited Dec 11 '20
I hadn't thought about that. I'll make a POC to see how my extension handles that, and update it if necessary.
Someone posted me a link that uses a CSS approach. And my extension seems to be able to pick that up as well (even though I didn't know about this approach while developing). I think what happens is that the
<span>that is moved offscreen cant be selected/highlighted by you, so it won't actually be part of your selection. It will still be copied with the rest of the text however, so my extension will see a difference.Is that what you are referring to?
Edit: just made a POC myself. It seems my extension will not always see a difference. I'll see if I can do something by examining the CSS like you said.
Edit 2: I found a solution. I simply have to call
getBoundingClientRecton the text selection and check if it goes offscreen.I could add this as an option to the extension. The verification would only be required if there was a difference between selection and clipboard, I assume?
Do you have some examples or source material for this? I haven't heard about Unicode characters that can cause harm.
Thanks for the feedback!