0

I want to start using 'jsdom' package jsdom: https://github.com/tmpvar/jsdom

I saw the following code snippet in the documentation:

var jsdom = require("jsdom");
jsdom.env("http://nodejs.org/dist/", [
        'http://code.jquery.com/jquery-1.5.min.js'
    ],
    function(errors, window) {
        console.log(window);
        // I want to open a browser window that will show the content of window
    }
);

As you can see, I can use 'jsdom' to pull the data from the website " http://code.jquery.com/jquery-1.5.min.js". Now, I want to take the data I have in 'window' variable, make some manipulations on it and then open a browser and show the manipulated data.

I know that 'open' package can help me open a browser, but I have to give it a URL as an argument. It cannot process 'window' object. Do you have any ideas?

CrazySynthax
  • 13,662
  • 34
  • 99
  • 183

1 Answers1

1

I'm not sure what do you want to achieve in long run. I assume that you run node.js on the client machine with a browser installed. If that is true then I would save contents of DOM to a file by using FS and then open a browser with parameters to load that html file.

To get contents you should be able to simply run jquery method:

var html = $("html").html();

How to use FS:

fs = require('fs');
fs.writeFile("/path/file.html", html)

To open a file in browser you can install opn and run it

const opn = require('opn');
opn ('file:///path/file.html')

Without opn you can run browser binary with a command like in answers to this question: Execute a command line binary with Node.js

Zbyszek
  • 1,420
  • 18
  • 23