Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Run snapsvg on node server using jsdom
let {JSDOM} = require('jsdom')
var resolve = require('resolve');
resolve('snapsvg', { basedir: __dirname }, function (err, res) {
if (err) console.error(err)
else {
console.log('si')
var scriptDir = res
console.log(scriptDir)
const options = {
runScripts: "dangerously",
resources: "usable"
};
const dom = new JSDOM(`
<!DOCTYPE html><html><body><div id="test"></div></body></html>
`, options);
var script = dom.window.document.createElement('script');
script.onload = function() {
console.log("Script loaded and ready");
};
script.src = `file://${scriptDir}`;
var head= dom.window.document.getElementsByTagName('head')[0];
head.appendChild(script);
console.log(dom.serialize())
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment