Hi I'm trying to capture the buffer in cut copy paste. I can get the paste, but the copy and cut do not appear to work.
Env: Windows 10 x64: Google Chrome is up to date Version 65.0.3325.181 (Official Build) (64-bit)
index.html
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml' xmlns:v='urn:schemas-microsoft-com:vml'>
<body>
<hr/>Clipboard TEST<br/>
<textarea id='idCut'
rows='8'
cols='32'>
Cut something from here
</textarea>
</body>
</html>
manifest.json
{
"name": "Chrome Extension",
"description": "Stuff",
"version": "2.0",
"permissions": [
"nativeMessaging",
"notifications",
"activeTab",
"tabs",
"webRequest",
"webRequestBlocking",
"downloads",
"clipboardWrite",
"clipboardRead",
"*://*/*"
],
"content_scripts": [
{
"matches": ["http://*/*", "https://*/*"],
"js": ["content.js"],
"run_at": "document_end"
}],
"browser_action": {
"default_title": "Make this page do Stuff"
},
"manifest_version": 2
}
content.js
function onCut(e)
{
console.log( 'onCut ENTER' );
var buf = e.clipboardData.getData('text/plain');
console.log( 'onCut EXIT ' + buf );
}
function onCopy(e)
{
console.log( 'onCopy ENTER' );
var buf = e.clipboardData.getData('text/plain');
console.log( 'onCopy EXIT ' + buf );
}
function onPaste(e)
{
console.log( 'onPaste ENTER' );
var buf = e.clipboardData.getData('text/plain');
console.log( 'onPaste EXIT ' + buf );
}
document.addEventListener('cut',onCut,true);
document.addEventListener('copy',onCopy,true);
document.addEventListener('paste',onPaste,true);
I then select "something" from the text area and do ctrl X, ctrl C, ctrl V which results in:
content.js:8 onCut ENTER
content.js:12 onCut EXIT
content.js:17 onCopy ENTER
content.js:21 onCopy EXIT
content.js:26 onPaste ENTER
content.js:30 onPaste EXIT something
So, Paste gives me the buffer, but the others do not.
My question is why aren't cut and copy showing me the buffer but paste is?
I've read that I need to use background.js and exec the op into a temp dom element like a div, and then native message it out, but if that is true, why is paste working? It seems like the security / impl is not consistent.
Is there a reason this is the way it is?
Or am I missing something?
I just added the html and manifest... Sorry, it didn't seem like it was needed because paste was working. I believe that makes it complete?
Thanks