Created
September 17, 2011 16:43
-
-
Save ariya/1224113 to your computer and use it in GitHub Desktop.
PhantomJS 1.3 example: prevent window.onload
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var page = new WebPage(), | |
address; | |
// Let's see what the web page's console might output. | |
page.onConsoleMessage = function (msg) { | |
console.log('from web page: ' + msg); | |
}; | |
// Hijack assignment to window.onload to do nothing. | |
page.onInitialized = function () { | |
page.evaluate(function () { | |
window.__defineSetter__('onload', function (handler) { | |
}); | |
}); | |
}; | |
if (phantom.args.length === 0) { | |
console.log('Usage: prevent-onload.js <some URL>'); | |
phantom.exit(); | |
} else { | |
address = phantom.args[0]; | |
page.open(address, function (status) { | |
if (status !== 'success') { | |
console.log('FAIL to load the address'); | |
} else { | |
console.log('Loading completed.'); | |
} | |
phantom.exit(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i have a question is what is the use of Hijack assignment to window.onload?What can we do?