Since you want to do this from node.js, you should use a PhantomJS bridge, for example phantomjs-node (phantom npm module).
PhantomJS, : '--local-to-remote-url-access = yes' PhantomJS, . , --web-security=false, --ssl-protocol=any ignore-ssl-errors=true .
DOM, injectJs() includeJs() . , DOM PhantomJS, . (page.evaluate()) , , , .
var phantom = require('phantom');
var async = require('async');
function run(page, ph) {
page.evaluate(function () {
return document.title;
}, function (title) {
console.log('Page title is ' + title);
ph.exit();
});
}
var remoteScripts = [ "http://d3js.org/d3.v3.min.js" ];
var localScripts = [ "../js/d3.v3.min.js", "../js/jquery-2.1.3.min.js" ];
phantom.create('--local-to-remote-url-access=yes', '--web-security=false', function (ph) {
ph.createPage(function (page) {
async.series(remoteScripts.map(function(url){
return function(next){
page.includeJs(url, function(){
next();
});
};
}), function(){
async.series(localScripts.map(function(url){
return function(next){
page.injectJs(url, function(){
next();
});
};
}), function(){
run(page, ph);
});
});
});
});
async script DOM. series().