phantom-render-stream icon indicating copy to clipboard operation
phantom-render-stream copied to clipboard

STDOUT from phantom-process.js being silently ignored (except JSON communication)

Open markstos opened this issue 10 years ago • 3 comments

In index.js, there are these lines which make it appear that you might be able to see STDOUT output from the phantom-process.js file if you have debugging turned on with DEBUG=phantom-render-stream:

 var output = ldjson.parse({strict: false}); 
 child.stdout.pipe(debugStream('phantom (%s) stdout', child.pid)).pipe(output)

What's actually happening is that any output to STDOUT from phantom-process.js that isn't valid JSON is silently discarded.

A design that would be more helpful for debugging would be to check to see if the output is valid JSON or not. If it's not, assume it's debugging output and pass it on through.

The phantomstream process also communicates with Phantom via JSON. They deal with this issue by explicitly sending a "prefix" to all of their JSON communication lines that are sent back on STDOUT. The parent process then checks to see if the response matches the expected prefix. If not, the output is passed through the parent's stdout, with a prefix of "[phantom-stdout] ".

The code doesn't currently run for me due to apparently changes in CoffeeScript, but the code is nicely structured, commented and easy to read:

https://github.com/mjpizz/phantomstream/blob/master/lib/stream.coffee

When debugging why generic "Render failed" messages are returned, having more diagnostic output like could be gold.

I recommend adopting the approach of phantomstream (or something like it) for dealing with adhoc output from phantom-process.js

markstos avatar Oct 17 '14 20:10 markstos

@davisford You may be interested in this patch, since its similar to one you developed increase the amount of diagnostic output available.

markstos avatar Oct 20 '14 19:10 markstos

@markstos I can verify that my PR https://github.com/e-conomic/phantom-render-stream/pull/65 definitely allows for page console.log output regardless of whether it is valid json or not. I've been using it for a while now.

davisford avatar Oct 27 '14 18:10 davisford

there is "log" event which you can listen from stream - it will give you any js errors, console.logs, resource timeouts etc occurred while rendering.

if you need other customer stdout logs from inside phantom-process, it's recommended to use page.log function, otherwise these logs might affect worker.error and other processing

https://github.com/e-conomic/phantom-render-stream/pull/95#issuecomment-191696092

bubenshchykov avatar Mar 03 '16 16:03 bubenshchykov