A
A
Alexander Kulik2015-12-21 16:23:00
Node.js
Alexander Kulik, 2015-12-21 16:23:00

How to force nodejs to execute in nwjs application?

Good afternoon.
I'm trying to make a desktop application on nwjs and ran into one problem.
After loading the page into the application window, I try to download the image, and if I load a local html page, then using the node it turns out to save the image to disk, but if I try to load a site from the web with identical content into the application window, saving does not occur.
manifest.json:

....
  "main": "/здесь локальный путь/saveimg.html",
// "main": "http://site.com", //при этой точке входа не хочет работать с содержимым 
  "inject-js-end": "test.js",
...

saveimg.html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <div id="imgid" class="imgclass">
        <img id="imgimg" src="http://cs631122.vk.me/v631122037/5952/retsE5oGX9w.jpg" alt="">
    </div>    
</body>
</html>

test.js:
var fs = require('fs');
var request = require('request');
var img = document.querySelector('div#imgid>img');
console.log(img);
var url=img.src;
console.log(url);
request(url).pipe(fs.createWriteStream('opa.jpg'));

with "main": " site.com " manipulations are obtained and getting the value of the link to the images using javascript, but as soon as I connect the contents of test.js with the node, it starts swearing to the console (it is impossible to connect the module).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artur Atnagulov, 2016-01-07
@atnartur

Why do it through the site? Let the site return a list of URLs, and the program will request and download them. The fact that it is impossible to connect node modules from the site is quite logical. Maybe it's some kind of security restriction in nwjs

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question