This is a solution with Node.js, I can't tell you one with SpiderMonkey. Like Node.js, SpiderMonkey has no browser env as it's only a JavaScript engine. But Node.js has many library for simulating a browser env. Thus I suggest you to use Node.js instead of SpiderMonkey.
npm install domino
(you will need Node.js)- Change your js source (let's say
dom.js
) to:
var domino = require('domino');
var window = domino.createWindow();
var document = window.document;
var pzt = document.createElement('iframe');
pzt.src = 'http://www.abc.com';
pzt.style.width = '100px';
if (!document.getElementById('pzt')) {
document.body.innerHTML = '<div id=\'pzt\'></div>';
document.getElementById('pzt').appendChild(pzt);
}
console.log(document.documentElement.outerHTML);
- Then
node dom.js > out.html