Documenting Problems That Were Difficult To Find The Answer To

PhantomJS Exit Doesn’t Exit Where You Expect It To Exit

Here’s a little trick using PhantomJS 1.9:

var system = require('system');

system.stdout.writeLine( "This is printed after exit!" );

Here’s what it does – it prints out:

This is printed after exit!

This doesn’t happen if you use the console.log() function but it does with the system.stdout and system.stderr objects.

It appears that PhantomJS finishes running the current function before actually terminating the JavaScript interpreter. So one should always take preventative actions to ensure no more code can run after a call to phantom.exit().

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: