Promise-based Web page open callback

This commit is contained in:
Antonin Stefanutti 2016-05-12 14:55:40 +02:00
parent 560cfb71c6
commit 5222c9837a

View File

@ -163,19 +163,24 @@ page.onConsoleMessage = function (msg) {
console.log(msg);
};
page.open(options.url, function (status) {
if (status !== 'success') {
console.log('Unable to load the address: ' + options.url);
openUrl(page, options.url)
.then(delay(options.loadPause))
.then(exportSlides)
.catch(function (url) {
console.log('Unable to load the URL: ' + url);
phantom.exit(1);
}
});
if (options.loadPause > 0)
Promise.resolve()
.then(delay(options.loadPause))
.then(exportSlides);
else
exportSlides();
});
function openUrl(page, url) {
return new Promise(function (resolve, reject) {
page.open(url, function (status) {
if (status !== 'success')
reject(url);
else
resolve();
});
});
}
function exportSlides() {
var plugin;