Theme:
I am creating a chrome extension and, for some functions, I would like to copy some text to the clipboard and automatically paste it into any element that has focus for the user.
Getting my text to the clipboard is not a problem. I can simply create textarea on my background page, set its value accordingly and then select its contents. Then I can use document.execCommand("copy");
Problem:
The problem occurs when I try to use document.execCommand('paste') in my script content. It works great in simple text areas (like the one I'm typing now). However, on many sites it does not work. This usually happens when the item being edited is inside an Iframe or is actually a regular <div> rather than a vanilla <textarea> / <input>
Despite the fact that my trivial attempt does not work in these cases, the built-in paste option provided by Google works every time without fail.
Is it possible for the chrome extension to mimic this functionality in a custom context menu setting? If so, how can this function be achieved?
Additional Information:
This operation is called when you click on the context menu. The specified context menu option is visible only when the item currently in focus is classified as editable using the chrome.contextMenus API
Related questions:
None of them gave me a satisfactory answer.
source share