var phantom = this.phantom || {exit: function () {}}; var page = require('webpage').create(); // code, code, code… page.open('about:blank', function () { page.close(); console.log('☮ out!'); phantom.exit(); });