Skip to content

Instantly share code, notes, and snippets.

@jhnns
Created February 12, 2016 10:57
Show Gist options
  • Save jhnns/33662106036d4a607db3 to your computer and use it in GitHub Desktop.
Save jhnns/33662106036d4a607db3 to your computer and use it in GitHub Desktop.
var phridge = require('phridge');
var simpleLogScript = require.resolve('./simpleLogScript.js');
var phantomInstances = {};
function spawnPhantom(id) {
return phridge.spawn()
.then(function (phantom) {
phantomInstances[id] = phantom;
return phantom.run(function () {
this.page = webpage.create();
this.page.onCallback = console.log.bind(console);
})
})
.then(function () {
console.log('Phantom instance ('+ id +') successfully spawned.');
});
}
spawnPhantom('myId0')
.then(function () {
return phantomInstances['myId0'].run(simpleLogScript, function (scriptPath) {
this.page.injectJs(scriptPath);
});
});
window.callPhantom('Hello World!');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment