1

I am using paste execCommand to get the system clipboard data.

document.execCommand("Paste", null, null);
var paste = pasteTarget.innerText;

I am trying to read data in every one sec delay, but pasteTarget.innerText is always returning null.

I am executing the above code in the handle message from native client. It seems this code is not executing on background page. How to execute the code in background page?

I am using the pepper API example(nacl_sdk\pepper_35\examples\api\input_event).

common.js

function getClipboard() {
            var pasteTarget = document.createElement("div");
            pasteTarget.contentEditable = true;
            var actElem = document.activeElement.appendChild(pasteTarget).parentNode;
            pasteTarget.focus();
            document.execCommand("Paste", null, null);
            var paste = pasteTarget.innerText;
            console.log("paste = " + paste);
            actElem.removeChild(pasteTarget);
            return paste;
    };

Whenever right button is clicked I am trying to get the clipboard data. But always null is returned.

manifest.json

    {
  "name": "Input Event",
  "version": "35.0.1916.114",
  "minimum_chrome_version": "35.0.1916.114",
  "manifest_version": 2,
  "description": "Input Event Example",
  "offline_enabled": true,
  "icons": {
    "128": "icon128.png"
  },
  "app": {
    "background": {
      "scripts": ["background.js"]
    }
  },
  "key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCMN716Qyu0l2EHNFqIJVqVysFcTR6urqhaGGqW4UK7slBaURz9+Sb1b4Ot5P1uQNE5c+CTU5Vu61wpqmSqMMxqHLWdPPMh8uRlyctsb2cxWwG6XoGSvpX29NsQVUFXd4v2tkJm3G9t+V0X8TYskrvWQmnyOW8OEIDvrBhUEfFxWQIDAQAB",
  "oauth2": {
    "client_id": "903965034255.apps.googleusercontent.com",
    "scopes": ["https://www.googleapis.com/auth/drive"]
  },
  "permissions": [
    "clipboardWrite",
    "clipboardRead"
  ]
}
psraju
  • 23
  • 5
  • Do you focus on the target first? See if this resolves your problem: https://stackoverflow.com/questions/7144702/the-proper-use-of-execcommandpaste-in-a-chrome-extension – Xan Mar 16 '15 at 12:53
  • I have the focus for that element. I am using the above in the handle message from native client. It seams it is not executing on background page. – psraju Mar 16 '15 at 14:15
  • The question needs more of your code then, perhaps. – Xan Mar 16 '15 at 14:16
  • sorry i am new to javascript, i will update the question with my code – psraju Mar 16 '15 at 14:27
  • What kind of element is `pasteTarget`? – Xan Mar 16 '15 at 14:50
  • I copied the getClipboard function from one of the stack overflow question. – psraju Mar 16 '15 at 15:02
  • Do you have the `"clipboardRead"` permission declared? – Xan Mar 16 '15 at 15:05
  • 1
    I have the permission. if i use the same code in background page it is working fine. – psraju Mar 16 '15 at 15:07
  • 1
    Can you tell more about where this code is, show the native client side, show the manifest? – Xan Mar 16 '15 at 16:49

0 Answers0