Automate copy of screen contents to clipboard

137 views
Skip to first unread message

JavaScriptDude

unread,
Apr 7, 2015, 9:43:04 PM4/7/15
to chromium...@chromium.org
Is it possible to automate the process of copying rendered html to the system clipboard? I have a usecase to do this in a NodeWebkit app I'm developing and was wondering if its possible to do this in Chromium under the hood?

The usecase is to give an easy way to get rendered html over to disparate applications like an email client or to a word processor. The user would just need to trigger an event in the Chromium based app which would build html, render it to a temporary hidden frame, select all, copy to the clipboard and then close the temporary frame. At this point, the user could just paste into their app of choise like an email client or word processor.

I know I can do this at the OS level but it would be pretty rough and would not translate to a maintainable cross platform app.


MSI Team

unread,
Apr 8, 2015, 12:49:40 PM4/8/15
to chromium...@chromium.org
The problem is that webpages are huge and copying such content to the clipboard would probably constantly trigger memory errors and crashes.

Jonathan Garbee

unread,
Apr 8, 2015, 1:58:17 PM4/8/15
to chromium...@chromium.org
Copying page code to the clipboard won't cause memory issues unless your computer is from 1995.

If you can use flash, then ZeroClipboard [1] should help do what you want. Just reach into the iframe and pull the text content out (should be doable) then pass it into this.

Other than using some flash system to get data into the clipboard, I don't know of any solution for this myself. Copying to the clipboard is not allowed with JS (save IE) for security reasons.

On Wed, Apr 8, 2015 at 12:49 PM MSI Team <msimprovert...@gmail.com> wrote:
The problem is that webpages are huge and copying such content to the clipboard would probably constantly trigger memory errors and crashes.

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

To unsubscribe from this group and stop receiving emails from it, send an email to chromium-discu...@chromium.org.
Message has been deleted

JavaScriptDude

unread,
Apr 8, 2015, 2:04:34 PM4/8/15
to chromium...@chromium.org
I found out how to do this in Node Webkit with some simple JavaScript. This can be tweaked pretty easily to be used in a Chrome browser.

var nw_gui = require('nw.gui');
// In my usecase, I write the HTML to a file in a temp directory (sTmpDir) before loading
var nw_win_new = nw_gui.Window.open("file://"+sTmpDir+"/index.html");
nw_win_new.on("loaded", function new_win_loaded(){
var wNew = nw_win_new.window, dNew=wNew.document

var range = dNew.createRange();
var sel = wNew.getSelection();
sel.removeAllRanges();
range.selectNode(dNew.getElementById('divMain'));
sel.addRange(range);
dNew.execCommand('copy')
sel.removeAllRanges();

try { nw_win_new.close(true); }catch(exc){}
})



PhistucK

unread,
Apr 8, 2015, 2:15:03 PM4/8/15
to Jonathan Garbee, Chromium-discuss
Unless you have a requirement that copying will not originate from a user gesture (a click, a keypress, or a tap, though I think Flash also requires that?), you will soon be able to use normal JavaScript -


PhistucK
Reply all
Reply to author
Forward
0 new messages