Firefox - document.execCommand ('cut /' copy) was rejected because it was not called from a short run event handler created by the user

I am developing a one-page application, I have a button on the page when the user clicks the button that I would like to make an ajax call on my server, and then copy the return value (via the callback) to the user clipboard.

Each component works in isolation, but when I glue them together, Firefox returns the following error:

document.execCommand ('cut /' copy) was rejected because it was not called from within a short run of a custom event handler

I would like to know the features of this error, but there is absolutely no information on the Internet; what are the limit conditions causing this error, is the stack depth, timeout, etc.

+8
source share
3 answers

in Firefox, it only works with the click handler, link Interact_with_the_clipboard

+9
source

Wrap your call to execCommand('cut'/'copy') with an async request to execute it after user event processing is complete.

Example with $.Deferred :

 function asyncCall() { return $.Deferred().resolve().promise(); } asyncCall().then(function() { var supported = document.queryCommandSupported('copy'); if (supported) { // ... select action document.execCommand('copy'); } }); 
+1
source

I just had to deal with this issue.

For me, the solution was to simply set async to false, since the call is fast enough.

0
source

Source: https://habr.com/ru/post/1261119/


All Articles