How to open a new browser window from command line?

Given that nyxt has already been started,
can one open a new nyxt browser window from the command line, displaying an URL?

If I just invoke
nyxt https://github.com
then that URL is displayed in the already existing nyxt browser window. This is of course expected.

With an already running google-chrome one can open a new browser window with, for example:
google-chrome --new-window https://github.com

Why do I want to do this? When using a window manager, such as i3 or sway, it can be convenient to open a new browser window, and to do that in a specific position on the display. With other browsers this can be achieved by invoking a command in the window manager that executes a script to create the new browser window. The window manager controls where the new window will be displayed.

@johan_widen what you’re trying to achieve is not to start another Nyxt process, but to create a new window. For that we have the command make-window. Does that help? Thanks.

I tried with
$ nyxt -r -e ‘(make-window “https://github.com”)’

but it displays the URL in the already existing nyxt window. I did not get a new nyxt window.

I also tried this:
$ nyxt -r -e ‘(make-window (make-buffer “https://github.com”))’

If I just submit the inner sexpr (make-buffer) that one succeeds and creates the buffer in the existing nyxt window. But if I try the whole sexpr, I get the error:
Could not extract URLs from “(make-window (make-buffer "https://github.com"))”.

@johan_widen if you want to programmatically create a new window and load a specific URL you need to issue (make-window (make-buffer :url "https://en.wikipedia.org/wiki/Tomato")).


For reference, for those that want to control a running Nyxt process from the the command line:

  • Add the snippet below to your config file;
(define-configuration browser
  (
   ;; Whether code sent to the socket gets executed.  You must understand the
   ;; risks before enabling this: a privileged user with access to your system
   ;; can then take control of the browser and execute arbitrary code under your
   ;; user profile.
   (remote-execution-p t)))
  • Start Nyxt;
  • To communicate with the Nyxt process: (1) issue nyxt --remote which behaves as a Nyxt interpreter or (2) send a single sexp for evaluation, for instance nyxt --remote --eval '(echo "Hello Nyxt!")'.
2 Likes

Thank you so much! I was successful with your recipe.
I used the following shell command (after having added the define-configuration snippet to nyxt config):
nyxt -r -e ‘(make-window (make-buffer :url “Tomato - Wikipedia”))’ -q

The -q is so that the command terminates, instead of waiting for input from stdin.

1 Like

Good @johan_widen! I see that you were able to figure out the --quit flag by yourself. I argued, in issue #3047, that --quit should be the default when using both --remote and one of --load or --eval.

What do you think? We’re interested in your opinion!

Yes, that sounds reasonable: --quit should be default in those cases.

Jumping in here, I need to be able to do this as well, but it isn’t working for me:

  1. I downloaded and compiled Nyxt tonight (v 4.0). As a side point, holy moly is this a lot faster than 3.x. I do expect bugs so no worries.

  2. I have added the following to my config.lisp:

;; from url: How to open a new browser window from command line? - #4 by johan_widen
;; allow remote control over nyxt
(define-configuration browser
(
;; Whether code sent to the socket gets executed. You must understand the
;; risks before enabling this: a privileged user with access to your system
;; can then take control of the browser and execute arbitrary code under your
;; user profile.
(remote-execution-p t)))

  1. Started up Nyxt, it is running in a window.

  2. Tried to open up a new window with this command:

bin-local/nyxt/nyxt -r -e ‘(make-window (make-buffer :url “Tomato - Wikipedia”))’

The error message returned:
[03:39:59] Probing remote instance listening to /run/user/1001/nyxt/nyxt.socket.
[03:39:59] No instance running.

QUESTION: What I missing here? Any suggestions are welcome, I don’t see anything obvious.

GOAL: I need to create some scripts to open up multiple windows of Nyxt, log in to interfaces and have it click on default items. The first step is to get Nyxt to just open up a window though.

Thanks!

@holycow if you’re experiencing that Nyxt feels faster, it might be due to changes in a newer WebKit version.


I don’t understand why it isn’t working for you, but I’m leaving some hints below.

Try to test it with a config file that only includes the relevant bit (setting remote-execution-p to t).

Are you sure that the binary that you’re calling to start Nyxt and the one to which you’re sending the sexp for evaluation is the same?

Aha!

I had an error in my config + I had a shortcut that was starting up Nyxt with --no-socket for some reason. And wow, 3.x was much faster than 2.x, but 4.x is a bit of a game changer. I was not expecing this. Going to do a bit more testing.

This works now. Great! Thanks for the heads up.

Next question: The warning about enabling connection to a socket is interesting. Would the proper way to mitigate any security issues be opening up Nyxt as separate processes?

@holycow are you wondering about the implications of enabling remote-execution-p?

Basically it means that if an attacker is able to login to your system, then he’s able to send arbitrary code to Nyxt.

If your goal is to control a Nyxt process externally, then you need to enable. Otherwise, I’d suggest disabling it.

Does this answer your question?

By the way, my sincere apologies for the way I phrased my last question. Reading it now, it sounds so demanding!

Argh!

I very much appreciate your and the teams time and appreciate any help. Yes that answer the question.

Thank you kindly.

@holycow I didn’t sense any negativity from your question!

Feel free to pose more questions :smiley: