4 * Opens the given page and resolves when PhantomJS called back.
5 * Will be executed inside of PhantomJS.
10 * @param {Function} resolve
11 * @param {Function} reject
13 function openPage(url, resolve, reject) { /* jshint validthis: true */
14 this.open(url, function onPageLoaded(status) {
15 if (status !== "success") {
16 return reject(new Error("Cannot load " + url + ": PhantomJS returned status " + status));
23 * Calls phantom.exit() with errorcode 0
27 function exitPhantom() { /* global phantom */
28 Object.keys(pages).forEach(function (pageId) {
29 // Closing all pages just to cleanup properly
30 pages[pageId].close();
33 // Using setTimeout(0) to ensure that all JS code still waiting in the queue is executed before exiting
34 // Otherwise PhantomJS prints a confusing security warning
35 // @see https://github.com/ariya/phantomjs/commit/1eec21ed5c887bf21a1a6833da3c98c68401d90e
36 setTimeout(function () {
42 * Cleans all references to a specific page.
45 * @param {number} pageId
47 function disposePage(pageId) { /* global pages */
48 pages[pageId].close();
52 exports.openPage = openPage;
53 exports.exitPhantom = exitPhantom;
54 exports.disposePage = disposePage;