Skip to content

Commit 63a8d28

Browse files
alexbormarcbachmann
authored andcommitted
Option for waiting for event to trigger
Added an option to allow waiting for the page to say when it's finished rendering. if options.onTitleDone is set to true, the page will not take the screenshot until the title is set to "done" on the page. Signed-off-by: Alex Bor <alexhbor@gmail.com>
1 parent 027bfb9 commit 63a8d28

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

lib/scripts/pdf_a4_portrait.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,26 @@ page.onLoadFinished = function (status) {
6464
}
6565

6666
var filename = options.filename || (options.directory || '/tmp') + '/html-pdf-' + system.pid + '.' + fileOptions.type
67-
page.render(filename, fileOptions)
68-
system.stdout.write(JSON.stringify({filename: filename}))
6967

70-
exit(null)
68+
takeShot();
69+
function takeShot(){
70+
var title = page.evaluate(function() {
71+
return document.title;
72+
});
73+
74+
if(title.toUpperCase() != "DONE" && options.onTitleDone){
75+
window.setTimeout(function () {
76+
takeShot();
77+
}, 400);
78+
} else {
79+
page.render(filename, fileOptions)
80+
phantom.exit();
81+
82+
system.stdout.write(JSON.stringify({filename: filename}))
83+
84+
exit(null)
85+
}
86+
}
7187
}
7288

7389
// Returns a hash of HTML content

0 commit comments

Comments
 (0)