Is it possible to take desktop screenshot using NW ?

630 views
Skip to first unread message

ankit.icode...@gmail.com

unread,
Jul 14, 2014, 1:16:31 PM7/14/14
to node-...@googlegroups.com
Hello Everyone,

I'm doing analysis for an App, that app will work same like Elance / Odesk TimeTracker, so I want to make sure that something we can easily do it using NW.

so do you guys think, Is it possible ?

I had reviewed documentation of NW but I didn't get any direction.

Small help would be appreciated! :)




Nikola Jokic

unread,
Jul 14, 2014, 1:41:32 PM7/14/14
to node-...@googlegroups.com
You could look into ffi package (https://www.npmjs.org/package/ffi).

"node-ffi is a Node.js addon for loading and calling dynamic libraries using pure JavaScript. It can be used to create bindings to native libraries without writing any C++ code."

Depending on your target platform you may be possible to access what you need. 


--
You received this message because you are subscribed to the Google Groups "node-webkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-webkit...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

jsbhalo...@gmail.com

unread,
Jul 14, 2014, 11:39:51 PM7/14/14
to node-...@googlegroups.com, ankit.icode...@gmail.com
Hi,

You could use ImageMagick ( http://www.imagemagick.org/ ), it is third partly Lib that provide bunch of functions to play with Image

You can easy install ImageMagick like

Ubuntu - sudo apt-get install imagemagick
Mac - brew install imagemagick
Windows - you can download executable file from  http://www.imagemagick.org/

so using NodeJS child process you can easily run any CLI.

var exec = require('child_process').exec, child;

child = exec('import -window root /tmp/screenshot.jpg',
  function (error, stdout, stderr) {
    console.log('stdout: ' + stdout);
    console.log('stderr: ' + stderr);
    if (error !== null) {
      console.log('exec error: ' + error);
    }
});

so that code will generate screenshot here :  /tmp/screenshot.jpg

I hope, this would be helpful for you ;)

Denys Khanzhyiev

unread,
Jul 15, 2014, 1:18:20 AM7/15/14
to node-webkit
this works for me in nw 0.9.2

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<html>
<head>
    <title></title>
</head>
<body onload="init();" >
<video id='vd'></video>
<script>

    function init(){
    var constraints =  {
        video: {
            mandatory: {
                maxWidth: window.screen.width,
                maxHeight: window.screen.height,
                maxFrameRate: 30,
                chromeMediaSource: 'screen'
            }
        }
    };
   // constraints =  {video: true, audio: true};
    console.log(constraints);
    navigator.webkitGetUserMedia(constraints, function(localSource){
        console.log(localSource);
        vd.src = webkitURL.createObjectURL(localSource);
        vd.play();
    },function(err){
        console.log('error',err);
    });

    }

</script>
</body>
</html>


Denys Khanzhyiev

unread,
Jul 15, 2014, 1:20:52 AM7/15/14
to node-webkit
This is not full example. You have to take picture from video element - there are examples of that on the Web.

Luc Renambot

unread,
Jul 16, 2014, 10:06:39 AM7/16/14
to node-...@googlegroups.com
But it seems that screen-capture is broken in v10.rc
My app used to work on v9.x but now I always get  TrackStartError
when navigator.webkitGetUserMedia requests the screen.
It seems to work for video/audio though.

Luc

lokt...@gmail.com

unread,
Sep 4, 2014, 10:32:58 PM9/4/14
to node-...@googlegroups.com
Make sure to add the following in your package.json

  "chromium-args": "--enable-usermedia-screen-capturing"

after doing that it worked perfectly for me.

Germán Arduino

unread,
Apr 4, 2016, 8:06:52 PM4/4/16
to nw.js, node-...@googlegroups.com
Hi:

I found this thread searching in the group because I need exactly to take desktop screenshots using nw (natively, not using third part programs).

This example show how to start the audio/video stream, but I can't figure out how to take a desktop screenshot (the complete desktop, not only the active window) and I can't find any example.

Any hint will be appreciated.

Thanks

lokt...@gmail.com

unread,
Apr 4, 2016, 8:34:51 PM4/4/16
to nw.js, node-...@googlegroups.com
I do that in a project of mine, check out the code here on how I do it.

https://github.com/loktar00/web-screensavers/blob/master/src/screensaver.js#L48

Germán Arduino

unread,
Apr 4, 2016, 9:49:24 PM4/4/16
to nw.js, node-...@googlegroups.com, lokt...@gmail.com
Thanks for your reply!

I'm trying your code in Mac (nwjs v 0.12.3) but I can't make it work (For example the nw.js window get minimized and I can't restore it to debug or so).

I think that the part of the code where the screenshot is captured is:

video.addEventListener("play", function() {
    nwin.show();
    nwin.resizeTo(screenWidth, screenHeight);
    nwin.moveTo(0, 0);
    ngui.Window.get().enterKioskMode();
    desktopCtx.drawImage(video,0,0);
    // We just need the first frame for a screenshot so stop streaming
    mediaStream.stop();

 but (and sorry with my almost no knowledge on these topics), how I can manipulate the captured image? I mean, how to save it as a png/jpg file or similar?

Thanks.
Reply all
Reply to author
Forward
0 new messages