Is it possible to fully mimic clipboard functionality using the chrome extension APIs?

蹲街弑〆低调 提交于 2019-12-23 02:17:17

问题


Subject:

I'm in the process of creating a chrome extension and, for certain features, I would like to copy some text to the clipboard and automatically paste it into whatever element has the focus for the user.

Getting my text into the clipboard is no problem. I can simply create a textarea in my background page, set its value accordingly and then select it's contents. Then, I can use document.execCommand("copy");


Problem:

The problem comes when I try to use document.execCommand('paste') in my content script. It works fine on simple text areas (like the one I'm typing in now). However, on many sites, it tends not to work. This typically happens when the editable element is inside an Iframe, or is actually a custom <div> rather than a vanilla <textarea>/<input>

Even though my trivial attempt fails to work in these cases, the built-in paste option that is provided by Google, works every time without fail.

Is it possible for a chrome extension to mimic this functionality in a customized context menu option? If so, how can this functionality be achieved?


Additional Info:

This operation is invoked when a context menu option is clicked. Said context menu option is only visible when the element currently in focus is categorized as editable by the chrome.contextMenus API


Similar Questions:

None of these provided me with a satisfactory answer

  • the proper use of execcommand("paste") in a chrome extension

  • clipBoard using chrome api execCommand

来源:https://stackoverflow.com/questions/28130521/is-it-possible-to-fully-mimic-clipboard-functionality-using-the-chrome-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!