atlas-engineer / nyxt

Nyxt - the hacker's browser.
https://nyxt-browser.com/
9.77k stars 409 forks source link

Question : how to set the proxy #1088

Closed deb75 closed 2 years ago

deb75 commented 3 years ago

I have settled privoxy listening on 10.10.1.1:8118.

How do I tell nyxt to use my proxy ? Does it as to do with the proxy-mode ?

Regards

aartaka commented 3 years ago

Yes, it's about proxy-mode! You can see an example of configuration if you will do describe-class nyxt/proxy-mode:proxy-mode in Nyxt. I'm implying you're familiar with how commands are executed in Nyxt and how minibuffer works. If you're not, you better say it so I can explain ;)

For what you want, it should be something along the lines of:

(define-configuration nyxt/proxy-mode:proxy-mode
  ((nyxt/proxy-mode:proxy (make-instance 'proxy
                                         :server-address (quri:uri "socks5://10.10.1.1:8118")
                                         :allowlist '("localhost" "10.10.1.1:8118")
                                         :proxied-downloads-p t))))

in your init file.

EDIT: 10, not 0, in the first byte of adress.

aartaka commented 3 years ago

@deb75, did the code I suggested work for you?

deb75 commented 3 years ago

Hi,

Yes ! thanks very much for your kind and detailed answer.

I do not know if it really works, I can access internet but I saw the error :

                     <ERROR> [23:26:38] In #<FUNCTION (LAMBDA (NYXT/PROXY-MODE::MODE)
                                   :IN
                                   "/home/runner/work/nyxt/nyxt/source/proxy-mode.lisp")

I am ok with minibuffer, using emacs for several years.

I would also like to make the bottom bar a little bigger, how can I do that ?

Regards

aartaka commented 3 years ago

Oh, wait, I've had a mistake in the code I suggested -- "10.10.1.1:8118" shouldn't be in allowlist.

Regarding the error in logs: is it only this, or is there some other message after that? it looks like error message is incomplete.

Regarding status-buffer (i.e. bottom bar, as you call it) size -- try something like:

(define-configuration status-buffer
  ((height 40)
   (style (str:concat %slot-default
                      (cl-css:css
                       '((body
                          :font-size "30px"
                          :line-height "40px")))))))

And adjust numbers as you like :)

deb75 commented 3 years ago

Thanks for your reply.

Here is the configuration I use now :

(define-configuration (buffer web-buffer)
  ((default-modes (append '(emacs-mode) %slot-default))))

(define-configuration nyxt/proxy-mode:proxy-mode
  ((nyxt/proxy-mode:proxy (make-instance 'proxy
                                         :server-address (quri:uri "socks5://10.10.1.1:8118")
                                         :allowlist '("127.0.2.1")
                                         :proxied-downloads-p t))))

(define-configuration buffer
  ((default-modes (append '(proxy-mode) %slot-default))))

(define-configuration status-buffer
  ((height 30)
   (style (str:concat %slot-default
                      (cl-css:css
                       '((body
                          :font-size "20px"
                          :line-height "30px")))))))

I put "127.0.2.1" in the allow list because my local dns server (dnscrypt) listens on 127.0.2.1#53

I have two problems with it :

Then, if it try to access google C-l google.fr I get the message :

Error resolving “duckduckgo.com”: Temporary failure in name resolution

This is strange as other browsers succeed with the same configuration. If I remove "--net=br0", then this error disappears and I can access google.fr with nyxt. If you have any ideas ?

I will try to build a nyxt firejail profile.

aartaka commented 3 years ago
* first problem is that the status-bar is not displayed well as you can see on following screenshot, might be due to some missings settings
  ![2021-01-08-112230_2598x197_scrot](https://user-images.githubusercontent.com/19540378/104005336-4096a400-51a5-11eb-85eb-83a00d73bdb4.png)

Yes, it's about arrows not resizing properly. I was not sure about how to resize these, but adding .arrow, as in the code below seems to work:

(define-configuration status-buffer
  ((height 30)
   (style (str:concat %slot-default
                      (cl-css:css
                       '((body
                          :font-size "20px"
                          :line-height "30px")
                         (".arrow"
                          :height "30px")))))))

This is strange as other browsers succeed with the same configuration. If I remove "--net=br0", then this error disappears and I can access google.fr with nyxt. If you have any ideas ?

I'm not sure about that -- I had little to no experience with sandboxing and firejail in particular. @Ambrevar, @jmercouris?

deb75 commented 3 years ago

Thanks for the .arrow, it works fine.

Regarding my second issue, I think fist there may have a misconfiguration. My proxy is privoxy which listens only http and https requests. So, I would like to change the line :

:server-address (quri:uri "socks5://10.10.1.1:8118"

to something like :

:server-address (quri:uri "http://10.10.1.1:8118"
                           quri:uri "https://10.10.1.1:8118"

but I am new to the lisp xyntax, I do not know if nyxt can read that ?

aartaka commented 3 years ago

Regarding my second issue, I think fist there may have a misconfiguration. My proxy is privoxy which listens only http and https requests. So, I would like to change the line :

:server-address (quri:uri "socks5://10.10.1.1:8118"

to something like :

:server-address (quri:uri "http://10.10.1.1:8118"
                           quri:uri "https://10.10.1.1:8118"

but I am new to the lisp xyntax, I do not know if nyxt can read that ?

No, that won't be read well -- quri:uri is a function that creates URI object, and it accepts only one string to encode as URI.

Try using HTTPS-only (i.e. :server-address (quri:uri "https://10.10.1.1:8118")) first and switch to HTTP if things break. Shouldn't be necessary, though.

aartaka commented 3 years ago

@deb75, did that work for you?

montaropdf commented 3 years ago

Hello,

I have a similar question, with the addition that I need to authenticate to the proxy (corporate proxy). The authentication type is basic, so, in $http_proxy, for example, it would look like https://username:password@proxy-name:port. Can I just do the same with nyxt?

aartaka commented 3 years ago

I don't see any reason why it shouldn't: quri parses it alright, and WebKitGTK should recognize the format of the URL. Try it out and see whether it works :)

montaropdf commented 3 years ago

I don't see any reason why it shouldn't: quri parses it alright, and WebKitGTK should recognize the format of the URL. Try it out and see whether it works :)

Even with non-alphanumeric characters like space or accented ones?

aartaka commented 3 years ago

I don't see any reason why it shouldn't: quri parses it alright, and WebKitGTK should recognize the format of the URL. Try it out and see whether it works :)

Even with non-alphanumeric characters like space or accented ones?

Most of these, I guess. (quri:uri "https://user-34987b¿nfvÁname:pas73846sword@localhost:8080") just ran fine for me, and WebKit is reliable enough in this regard too, I suppose. Maybe you'll need some escaping for spaces or URL syntax characters, but let's first try it out :)

montaropdf commented 3 years ago

I don't see any reason why it shouldn't: quri parses it alright, and WebKitGTK should recognize the format of the URL. Try it out and see whether it works :)

Even with non-alphanumeric characters like space or accented ones?

Most of these, I guess. (quri:uri "https://user-34987b¿nfvÁname:pas73846sword@localhost:8080") just ran fine for me, and WebKit is reliable enough in this regard too, I suppose. Maybe you'll need some escaping for spaces or URL syntax characters, but let's first try it out :)

Ok. I will give it a try tomorrow.

montaropdf commented 3 years ago

Sorry for the late reply.

I have initialy used the configuration from @Ambrevar, which doesn't work out of the box, but I will contact him about this. So I am, now using a minimal configuration and except for converting space to %20 I manage to make the proxy configuration works.

My configuration:

(in-package :nyxt-user) ; While implicit, this allows SLY to know which package we are in.

(define-configuration nyxt/proxy-mode:proxy-mode
  ((nyxt/proxy-mode:proxy (make-instance 'proxy
                                         :server-address (quri:uri "user:pass with space and $ sign@corporate.proxy:8080")))))

(define-configuration (buffer web-buffer)
  ((default-modes (append '(proxy-mode
                            reduce-tracking-mode
                            blocker-mode
                            force-https-mode)
                          %slot-default))))

(load-after-system :slynk (nyxt-init-file "slynk.lisp"))

However, I always got the following error in stdout:

While evaluating the form starting at line 1, column 0
  of <INFO> [13:34:53] Loading Lisp file "/home/smals-re/.config/nyxt/init.lisp".
<ERROR> [13:34:53] In #<FUNCTION (LAMBDA (NYXT/PROXY-MODE::MODE)
                                   :IN
                                   "/tmp/guix-build-nyxt-2-pre-release-5.drv-0/source/source/proxy-mode.lisp") {526CDA0B}>: When
                                                                                                                            attempting
                                                                                                                            to
                                                                                                                            set the slot's value to #<PROXY {100AA57733}> (SETF of SLOT-VALUE),
                                                                                                                            the
                                                                                                                            slot
                                                                                                                            PROXY
                                                                                                                            is
                                                                                                                            missing
                                                                                                                            from
                                                                                                                            the
                                                                                                                            object
                                                                                                                            #<USER-INTERNAL-BUFFER {1009DFA073}>.

However, I see the following later in the logs:

<INFO> [13:34:55] Proxy set to http://user:pass with space and $ sign@corporate.proxy:8080 (allowlisting (localhost
                                                                              localhost:8080)).
<INFO> [13:34:55] Proxy set to http://user:pass with space and $ sign@corporate.proxy:8080 (allowlisting (localhost
                                                                              localhost:8080)).
<INFO> [13:34:56] Proxy set to http://user:pass with space and $ sign@corporate.proxy:8080 (allowlisting (localhost
                                                                              localhost:8080)).

Note: I have redacted the user, password and proxy fqdn I use, for security reasons.

jmercouris commented 3 years ago

Only set the proxy information for web-buffers, and not internal buffers. That is, your define-configuration form should only operate on a web-buffer. Internal buffers do not access the internet, and thus do not have proxy details :-) hope that helps!

zvolin commented 3 years ago

Hi, I'm trying to switch to nyxt as my daily driver, however I'm new to lisp. I'm experiencing an issue with the proxy settings. This is what I have in my .config/nyxt/init.lisp:

(define-configuration nyxt/proxy-mode:proxy-mode
  ((nyxt/proxy-mode:proxy (make-instance 'proxy
                                         :url (quri:uri "socks5://my-corpo-proxy:port")
                                         :allowlist '("localhost")
                                         :proxied-downloads-p t))))

It is taken from proxy-mode help. However I'm facing this error opening nyxt:

Could not load the init file: READ error during LOAD: The symbol "PROXY" is not external in the NYXT/PROXY-MODE package. 
Line: 2, Column: 25 Stream: #<SB-INT:FORM-TRACKING-STREAM for "file /home/mine/.config/nyxt/init.lisp" {1008696293}>
❯ nyxt --version
Nyxt version 2.0.0