Skip to content

Instantly share code, notes, and snippets.

@macbre
Forked from gleicon/perfcap.js
Last active August 29, 2015 14:07
Show Gist options
  • Save macbre/9f23f314d8a3ff69313b to your computer and use it in GitHub Desktop.
Save macbre/9f23f314d8a3ff69313b to your computer and use it in GitHub Desktop.
var page = require('webpage').create(),
MSG_SCREENSHOT = '123screenshot123';
page.onConsoleMessage = function(msg) {
if (msg === MSG_SCREENSHOT) {
page.render('screenshot.png');
phantom.exit()
}
console.log('INFO: ' + msg);
};
page.onError = function(msg, trace) {
console.log('ERROR: ' + msg);
trace.forEach(function(item) {
console.log(' ', item.file, ':', item.line);
});
};
page.open('http://www.example.com', function() {
page.evaluate(function(MSG_SCREENSHOT) {
console.log('Navigation Timing object: ' + typeof window.performance);
console.log("Loading perfmap.js..");
var el=document.createElement('script');
el.src='https://zeman.github.io/perfmap/perfmap.js';
document.body.appendChild(el);
setTimeout(function() {
console.log("Triggering a screenshot...");
console.log(MSG_SCREENSHOT);
}, 1000);
}, MSG_SCREENSHOT);
});
@gleicon
Copy link

gleicon commented Oct 21, 2014

cool stuff, thanks !

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