Skip to content

Commit c50ec10

Browse files
committed
Collect console.log messages and add them in the returned JSON
1 parent 1f60f32 commit c50ec10

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/scripts/pdf_a4_portrait.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ page.onLoadFinished = function (status) {
5757
// The paperSize object must be set at once
5858
page.paperSize = definePaperSize(getContent(page), options)
5959

60+
// Collect console.log messages in rendered web page and custom script
61+
var consoleMessages = []
62+
page.onConsoleMessage = function (msg) {
63+
consoleMessages.push(msg)
64+
}
65+
6066
// Evaluate custom JavaScript
6167
if (options.evaluateScript) page.evaluateJavaScript(options.evaluateScript)
6268

@@ -68,7 +74,7 @@ page.onLoadFinished = function (status) {
6874

6975
var filename = options.filename || (options.directory || '/tmp') + '/html-pdf-' + system.pid + '.' + fileOptions.type
7076
page.render(filename, fileOptions)
71-
system.stdout.write(JSON.stringify({filename: filename}))
77+
system.stdout.write(JSON.stringify({filename: filename, consoleMessages: consoleMessages}))
7278

7379
exit(null)
7480
}

0 commit comments

Comments
 (0)