-1

Is there a such way to capture the loaded page screen of user browser, using my node app.

For Example if user visits the profile page, and i get the screenshot of that user loaded page.

I have tried to do so but end up getting the screenshot of my own screen.

Here is my Code:

var http = require("http")
var fs = require("fs")
var screenshot = require('desktop-screenshot');

function onRequest(req, res) {
    res.writeHead(200, {'Content-Type': 'text/html'})
    fs.readFile('./profile.html', null, function(err, data) {
        if (err) {
            res.writeHead(404)
            res.write('File not found')
        } else{
            res.write(data)
            screenshot("screenshot.png", function(error, complete) {
    if(error)
        console.log("Screenshot failed", error);
    else
        console.log("Screenshot succeeded");
});
        }
        res.end()
    })  
}

http.createServer(onRequest).listen(3000)

P.S: I want it to be done from the server side only.

Osama Xäwãñz
  • 437
  • 2
  • 8
  • 21

1 Answers1

1

Using desktop-screenshot you can't take screenshot of browser. From it's docs:

Take a screenshot of the computer on which Node is running

You need to use some service which runs client side like hotjar to do that. Even then, full screen screenshot won't be possible. Browsers run in sandboxes.

tbking
  • 8,796
  • 2
  • 20
  • 33