Open URL in external browser


#1

Hi, I’m struggling with opening an URL in an external browser (chromium-browser in my case). I was searching already in the forum and came across this discussion so my current approach looks like the following:

    {spawn} = require 'child_process'
    cmd = spawn('chromium-browser', ["https://www.google.com"])
    cmd.stdout.on "data", (data) ->
      console.log "stdout: " + data
      return
    cmd.stderr.on "data", (data) ->
      console.log "stderr: " + data
      return
    cmd.on "close", (code) ->
      console.log "child process exited with code " + code
      return

So far so good but when I try to spawn the child process I get always the following error:

stderr: The setuid sandbox is not running as root. Common causes:
  * An unprivileged process using ptrace on it, like a debugger.
  * A parent process set prctl(PR_SET_NO_NEW_PRIVS, ...)
Failed to move to new namespace: PID namespaces supported, Network namespace supported, but failed: errno = Operation not permitted

Does anybody have a guess what goes wrong in my case?

Btw: I’m aware of the atom web-browser package but I explicitly want to open the URL in an external browser.


#2

I think for this you should be able to use Atom Shell / Electron’s shell module: https://github.com/atom/atom-shell/blob/master/docs/api/shell.md#shellopenexternalurl

So it would be something like:

shell = require 'shell'

shell.openExternal('https://www.google.com')

#3

@mnquintana Thanks a lot for the quick reply! I was testing shell.openExternal as well but stopped experimenting with it as it caused Atom to freeze completely. I was testing it now once more with Firefox as default browser and interestingly it works now. Only if I set Chrome (i.e. chromium-browser) as default then it causes Atom to freeze. But sadly the website I want to open only works in Chrome so using Firefox won’t help me at this point :frowning:

Also if I spawn manually the child process pointing to the firefox binary it works as expected… only chromium-browser is causing this strange error. If I pass in the flag --no-sandbox when spawning the chromium-browser process it also starts up but I doubt that it’s a smart idea to use chromium in this insecure state.

I’ve modified my standard browser via sudo update-alternatives --config x-www-browser


#4

When Atom finally crashes (using the shell approach) I get the following console dump

[9784:0416/151609:ERROR:browser_main_loop.cc(170)] Running without the SUID sandbox! See https://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment for more information on developing with the sandbox on.
App load time: 224ms
...
The setuid sandbox is not running as root. Common causes:
  * An unprivileged process using ptrace on it, like a debugger.
  * A parent process set prctl(PR_SET_NO_NEW_PRIVS, ...)
Failed to move to new namespace: PID namespaces supported, Network namespace supported, but failed: errno = Operation not permitted
The program 'atom' received an X Window System error.
This probably reflects a bug in the program.
The error was 'BadWindow (invalid Window parameter)'.
  (Details: serial 789 error_code 3 request_code 40 minor_code 0)
  (Note to programmers: normally, X errors are reported asynchronously;
   that is, you will receive the error a while after causing it.
   To debug your program, run it with the --sync command line
   option to change this behavior. You can then get a meaningful
   backtrace from your debugger if you break on the gdk_x_error() function.)



#5

Rather than trying to work around the problem … have you reported the problem as a bug? If shell.openExternal is failing on your machine, it might be failing on other’s machines. And I’m pretty sure the Atom team would want to fix that. If you’ve got a set of repro steps that consistently expose the problem, you should probably report it as a bug.

If you do so, please link the bug here so others who find this topic can follow it.


#6

Sure, I’ll create an issue on electron for that and describe there more in detail my current platform on which I experience the bug.

Edit: Created issue, see https://github.com/atom/atom-shell/issues/1431