O'Reilly logo

Cross-platform Desktop Application Development: Electron, Node, NW.js, and React by Dmitry Sheiko

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Taking a screenshot

The previously created static prototype may look fancy, but is not of much use. We need a service capable of taking screenshots and recording screencasts.

If it was about a screenshot of the application window, we would simply use the API on NW.js:

import * as fs from "fs"; function takeScreenshot( filePath ){   appWindow.capturePage(( img ) => {     fs.writeFileSync( filePath, img, "base64" );   }, {     format : "png",     datatype : "raw"   }); } 

But we need a screenshot of the screen and, therefore, we have to get access to display input. W3C includes a specification draft, "Media Capture and Streams" (http://bit.ly/2qTtLXX), which describes an API to capture displayed media (mediaDevices.getDisplayMedia). Unfortunately, at ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required