execCommand paste and clipboard

1,224 views
Skip to first unread message

Jamie R..

unread,
Jan 5, 2017, 1:27:10 PM1/5/17
to Chromium-discuss
I am working on a project that is attempting to perform client initiated pasting (this involves a custom context menu w/ cut, copy, paste). I understand this isn't possible via execCommand and haven't been able to find anything definitive from Google/Chromium that this is the case beyond (https://developers.google.com/web/updates/2015/04/cut-and-copy-commands which mentions cut/copy but not paste). We have been able to successfully get cut/copy to work via execCommand('copy'|'cut'). Is there a link or resource that is available that states that execCommand('paste') is not possible and the reasoning for this? The customer is requesting a definitive statement from an authoritative source (chrome 43 is our target browser) and any help would be appreciated.


originally posted at https://productforums.google.com/forum/#!topic/chrome/4-jbjPcW3MM;context-place=forum/chrome but was recommended to post here as well.

PhistucK

unread,
Jan 5, 2017, 1:48:09 PM1/5/17
to jamie.r...@atsid.com, Chromium-discuss
I do not think any browser supports that. I do not think you will find an official statement anywhere.

There is work towards a new, promise based (and possibly permission based) clipboard API that should let you paste stuff, but it is only starting now. It will take some time (it is in a very early stage of standardization).
Reference -

Plus, Chrome 43 is very old, I really hope you are not using (or recommending) it for anything, as it is wrought with known security holes.


PhistucK

On Thu, Jan 5, 2017 at 6:36 PM, Jamie R.. <jamie.r...@atsid.com> wrote:
I am working on a project that is attempting to perform client initiated pasting (this involves a custom context menu w/ cut, copy, paste). I understand this isn't possible via execCommand and haven't been able to find anything definitive from Google/Chromium that this is the case beyond (https://developers.google.com/web/updates/2015/04/cut-and-copy-commands which mentions cut/copy but not paste). We have been able to successfully get cut/copy to work via execCommand('copy'|'cut'). Is there a link or resource that is available that states that execCommand('paste') is not possible and the reasoning for this? The customer is requesting a definitive statement from an authoritative source (chrome 43 is our target browser) and any help would be appreciated.


originally posted at https://productforums.google.com/forum/#!topic/chrome/4-jbjPcW3MM;context-place=forum/chrome but was recommended to post here as well.

--
--
Chromium Discussion mailing list: chromium...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-discuss

---
You received this message because you are subscribed to the Google Groups "Chromium-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-discuss+unsubscribe@chromium.org.

Jon Perryman

unread,
Jan 6, 2017, 12:05:59 AM1/6/17
to PhistucK, jamie.r...@atsid.com, Chromium-discuss
As Phistuck said, paste from a javascript would be a security issue. Without some sort of restrictions, then any javascript could access something a user doesn't want accessed. When they come up with a solution, it probably won't be what you expect.

Is right mouse paste too difficult?

On Thu, Jan 5, 2017 at 10:47 AM, PhistucK <phis...@gmail.com> wrote:
I do not think any browser supports that. I do not think you will find an official statement anywhere.

On Thu, Jan 5, 2017 at 6:36 PM, Jamie R.. <jamie.r...@atsid.com> wrote:
I am working on a project that is attempting to perform client initiated pasting. The customer is requesting a definitive statement from an authoritative source?

Jamie R..

unread,
Jan 6, 2017, 10:50:01 AM1/6/17
to Chromium-discuss, phis...@gmail.com, jamie.r...@atsid.com
Unfortunately, we are using a custom context menu on the entire document (this is the menu that contains the paste functionality) so right click paste through browser's native context menu (I'm assuming that is what you mean by right mouse paste) isn't an option.  This is similar to the context menu in google docs (works in chrome only) and ms word online (popup stating the keyboard shortcuts to use) and it also contains copy and cut commands.  

PhistucK

unread,
Jan 6, 2017, 12:30:56 PM1/6/17
to Jamie R.., Chromium-discuss
Paste in Google Docs only works when the extension is installed. You can create an extension for your case as well.


PhistucK

Nance, Aaron

unread,
Jan 6, 2017, 1:07:31 PM1/6/17
to PhistucK, Jamie R.., Chromium-discuss
Just to provide a little background: pasting from the clipboard via execcommand is not allowed because it is a security risk. It could be used to paste from the users clipboard without their knowledge. GoogleDocs extension bypasses this, but you have to give it permission to do so. 

If you are only only copying/pasting within the boundaries of a single page app you could implement you own clipboard in JS.

If you don't want to write an extension or need to go beyond the apps boundaries you could pop up and appropriate dialog message telling the user to use the shortcuts. For example, go to tinymce.com and try to paste from the edit menu.

--
--
Chromium Discussion mailing list: chromium...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-discuss

---
You received this message because you are subscribed to the Google Groups "Chromium-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-discuss+unsubscribe@chromium.org.



--

Aaron Nance

Software Developer

Assessment & Instruction

Pearson


E: aaron...@pearson.com


Pearson

Always Learning

Learn more at www.pearsonk12.com

Jamie R..

unread,
Jan 6, 2017, 1:48:07 PM1/6/17
to Chromium-discuss, phis...@gmail.com, jamie.r...@atsid.com
Aaron and PhistucK,

Thanks for your feedback.  From within the app it wouldn't be too difficult to capture the content on copy and insert when the paste was clicked in the custom context menu.  The main problem would be trying to paste content that was copied from other sources (word, other web content, etc.).  I was pretty much aware of the limitations (and security reasons behind them) I just needed a confirmation that it wasn't possible w/o extensions.  We did try the dialog and and it wasn't a big hit :) 

To unsubscribe from this group and stop receiving emails from it, send an email to chromium-discu...@chromium.org.
Reply all
Reply to author
Forward
0 new messages