Skip to content

Instantly share code, notes, and snippets.

@jamiehs
Forked from firedfox/onDOMContentLoaded.js
Created June 13, 2013 17:37
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 jamiehs/5775669 to your computer and use it in GitHub Desktop.
Save jamiehs/5775669 to your computer and use it in GitHub Desktop.
PhantomJS DOM Loaded
const PHANTOM_FUNCTION_PREFIX = '/* PHANTOM_FUNCTION */';
var page = require('webpage').create();
page.onConsoleMessage = function(msg) {
if (msg.indexOf(PHANTOM_FUNCTION_PREFIX) === 0) {
eval('(' + msg + ')()');
} else {
console.log(msg);
}
};
page.onInitialized = function() {
page.evaluate(function(domContentLoadedMsg) {
document.addEventListener('DOMContentLoaded', function() {
console.log(domContentLoadedMsg);
}, false);
}, PHANTOM_FUNCTION_PREFIX + page.onDOMContentLoaded);
};
page.onDOMContentLoaded = function() {
// your code here
console.log('DOMContentLoaded');
phantom.exit();
};
page.open('http://phantomjs.org/');
var page = require('webpage').create();
page.onInitialized = function() {
page.evaluate(function(domContentLoadedMsg) {
document.addEventListener('DOMContentLoaded', function() {
window.callPhantom('DOMContentLoaded');
}, false);
});
};
page.onCallback = function(data) {
// your code here
console.log('DOMContentLoaded');
phantom.exit(0);
};
page.open('http://phantomjs.org/');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment