Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spawn fixes when used by tape-run/browser-run with xvfb, docker #36

Open
siosonel opened this issue Mar 23, 2021 · 3 comments
Open

spawn fixes when used by tape-run/browser-run with xvfb, docker #36

siosonel opened this issue Mar 23, 2021 · 3 comments

Comments

@siosonel
Copy link
Contributor

electron-stream/index.js

Lines 79 to 97 in 0e25d55

Electron.prototype._spawn = function(url){
debug('spawn %s', url);
var self = this;
var ps = self.ps = spawn(electron, [runner], {
stdio: [null, null, null, 'ipc']
});
ps.on('exit', self._exit.bind(self));
ps.on('message', function(msg){
switch (msg[0]) {
case 'ready': ps.send(['init', stringify(self.opts)]); break;
case 'initialized': ps.send(['goto', url]); break;
case 'stdout': self.stdout.write(msg[1]); break;
case 'stderr': self.stderr.write(msg[1]); break;
}
});
};

related to juliangruber/browser-run#153

In a Docker container, I was able to make tape-run work after specifying the --no-sandbox option and the process.[stdout|stderr].on(...) handlers:

Electron.prototype._spawn = function(url){
  debug('spawn %s', url)

  var self = this;
  var ps = self.ps = spawn(electron, [runner, "--no-sandbox"], {
    stdio: [null, null, null, 'ipc']
  });

  ps.on('exit', self._exit.bind(self));

  ps.on('message', function(msg){
    switch (msg[0]) {
      case 'ready': ps.send(['init', stringify(self.opts)]); break;
      case 'initialized': ps.send(['goto', url]); break;
      case 'stdout': self.stdout.write(msg[1]); break;
      case 'stderr': self.stderr.write(msg[1]); break;
    }
  });

  const errs = [], outs = []
  ps.stdout.on('data', function(data) {
    outs.push(data)
  })
  ps.stderr.on('data', function(data) {
    errs.push(data)
  })
  ps.on('close', function(code) {
    const err = errs.join('').trim()
    if (err.length) {
      console.error(err)
      return
    }
    var lst = outs
      .join('')
      .trim()
      .split('\n')
    console.log(lst.slice(1).join(''))
  })
};
@juliangruber
Copy link
Owner

Thanks for looking into this! Code looks good on first sight. Could you open a Pull Request for this change? Also I think we should export --no-sandbox as an option, because using the sandbox is safer and we need to be that by default

@siosonel
Copy link
Contributor Author

Ok, I will submit a pull request later today or tomorrow.

For the option, what will be the option name? maybe

var ps = self.ps = spawn(electron, [runner, self.opts.electronOpts], {

so the usage would be ... | tape-run electronOpts="--no-sandbox".

Or please offer some guidance on option naming if the above does not fit in with your API design.

@juliangruber
Copy link
Owner

Great idea to discuss the option name 👍

I would propose to add an argument just for this, we've done this before in

https://github.com/juliangruber/tape-run/blob/ccad1ead6c5bbcf78d9e1a5007a2a53e769d816e/bin/run.js#L32-L35

So maybe just tape-run --no-sandbox?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants