Skip to content

Instantly share code, notes, and snippets.

@ahomu
Created November 6, 2012 11:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahomu/4024077 to your computer and use it in GitHub Desktop.
Save ahomu/4024077 to your computer and use it in GitHub Desktop.
% phantomjs snapshot.js > stdoutfilename
var page = require('webpage').create();
var url = 'http://localhost:1234/';
page.viewportSize = {
width: 1024,
height: 768
};
page.settings.userAgent = 'I am Phantom';
page.open(url, function (a, b, c) {
setTimeout(function() {
console.log(page.content);
phantom.exit();
}, 2000);
/*
// browser JavaScript call `window.callPhantom` when receive request from PhantomJS
if (navigator.userAgent.toUpperCase().indexOf('PHANTOM') !== -1) {
window.callPhantom();
}
// phantomjs's onCallback
page.onCallback = function() {
console.log(page.content);
phantom.exit();
};
*/
});
@ahomu
Copy link
Author

ahomu commented Nov 6, 2012

if ('callPhantom' in window) {
  window.callPhantom()
}

also correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment