Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Added check for enoent error #10

merged 1 commit into from

3 participants

Spencer Scott Feeney David Björklund

This package is used by browser-launcher to launch a browser headlessly. When run on OSX, which doesn't have Xvfb installed by default, the call to spawn triggers an error event which is unhanded and displays this useless output:

        throw er; // Unhandled 'error' event
Error: spawn ENOENT
    at errnoException (child_process.js:980:11)
    at Process.ChildProcess._handle.onexit (child_process.js:771:34)

Added an listener for "error" that will pass back a useful error message when it can.

Spencer spalger added check for enoent error, as well as a general 'error' event hand…
…ler on the child process, preventing 'uncaught error event' on systems without Xvfb installed
Scott Feeney

Same here, on Ubuntu — I didn't have Xvfb installed, and was baffled at the spawn ENOENT error that Testling (which uses this package) threw up. A friendly error message like this would have saved me some time :+1:

David Björklund kesla merged commit d3c0c85 into from
David Björklund

So, I haven't actually tested this PR (I don't use this module frequently anymore) - could someone take a look and ping me if it works as expected?

Scott Feeney

Aw shoot. It doesn't. At least, Testling depending on browser-launcher depending on this doesn't work as expected. Now I feel bad for (implicitly) advocating for this to be merged, without trying it. Sorry about that.

What I did: uninstalled Xvfb from my system, and replaced Testling's node_modules/browser-launcher/node_modules/headless with latest master (both with and without this change). Without this change I get the ENOENT error. With this change it simply hangs, not reporting an error or anything. I'm currently trying to figure out why.

Scott Feeney

Ah, never mind. node-headless is working perfectly. It's browser-launcher's fault for not checking for and re-throwing the error, and @spenceralger has already submitted a separate PR there: substack/browser-launcher#22. Thank you @kesla for merging this!

David Björklund

Release as 0.1.7

David Björklund

And @graue thanks for helping out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 22, 2013
  1. Spencer

    added check for enoent error, as well as a general 'error' event hand…

    spalger authored
    …ler on the child process, preventing 'uncaught error event' on systems without Xvfb installed
This page is out of date. Refresh to see the latest.
Showing with 21 additions and 1 deletion.
  1. +21 −1 index.js
22 index.js
@@ -29,18 +29,38 @@ module.exports = function headless(startnum, callback) {
// assume starting Xvfb takes less than 500 ms and continue if it hasn't
// exited during that time
var timeout = setTimeout(function() {
- childProcess.removeListener('exit', onExit);
+ cleanUpListeners();
callback(null, childProcess, servernum);
}, 500);
function onExit() {
+ cleanUpListeners();
headless(servernum, callback);
+ function onError (err) {
+ clearTimeout(timeout);
+ cleanUpListeners();
+ if (~err.message.indexOf('ENOENT')) {
+ callback(new Error('Xvfb is not installed or is not in your $PATH'));
+ } else {
+ callback(err);
+ }
+ }
// if Xvfb exits prematurely the servernum wasn't valid.
// Happens if there's already an X-server running on @servernum but no file was created in /tmp
childProcess.once('exit', onExit);
+ // if Xvfb is not installed, the childProcess will emit an ENOENT error
+ childProcess.once('error', onError);
+ function cleanUpListeners() {
+ childProcess.removeListener('exit', onExit);
+ childProcess.removeListener('error', onError);
+ }
Something went wrong with that request. Please try again.