Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

We don't execute document.execCommand() this time, because it is called recursively. #3403

Closed
broderix opened this issue Apr 24, 2015 · 4 comments

Comments

@broderix
Copy link

Hi, folks!
I'm trying to clean paste-data like this:
<textarea id="edit456"></textarea>

var onpaste = function(e) {
    e.preventDefault();
    var text = e.clipboardData.getData("text/plain");
    document.execCommand("insertHTML", false, text);
};
var edit = document.getElementById('edit456');
edit.addEventListener('paste', onpaste);

Then I paste data via context menu (or you can do it on console for tests)

    document.execCommand("paste");

and got warning from console:
"We don't execute document.execCommand() this time, because it is called recursively."

The data will not be pasted.

@TrevorPT
Copy link

TrevorPT commented May 1, 2015

I was looking for info on the same console message that's appearing when trying to cut-to-clipboard within a nw app. I came across this link which, though old, may help in your case? They use setTimeout() to get around the issue -- so I don't know if it's a bug or a security "feature".

https://code.google.com/p/chromium/issues/detail?id=363288#c3

@broderix
Copy link
Author

broderix commented May 6, 2015

@TrevorPT I have tried it, didn't help

@TrevorPT
Copy link

TrevorPT commented May 7, 2015

It works in my case but I didn't try to set up your code. Where did you invoke the setTimeout, like this?

setTimeout( function () {
    document.execCommand("insertHTML", false, text);
}, 0 );

@broderix
Copy link
Author

@TrevorPT thank you very much!
Found out that setTimeout not necessary - works without it, also helped gui.Clipboard:

var gui = require('nw.gui');
var clipboard = gui.Clipboard.get();
document.execCommand("insertHTML", false, clipboard.get()); //or insertText

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants