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

Default Browser Not Opening Correctly with --default-browser Parameter #416

Closed
leinardi opened this issue Aug 28, 2024 · 14 comments
Closed
Labels
bug Something isn't working default-browser

Comments

@leinardi
Copy link

Describe the bug
Since a couple of releases of the GlobalProtect-openconnect CLI client, the default browser is not opening correctly anymore. My default browser is set to Chrome, and in the past, it always worked fine using the parameter --default-browser. However, now it always opens Firefox instead of Chrome.

Expected behavior
When using the GlobalProtect-openconnect CLI client with the --default-browser parameter, I expected my default browser, Chrome, to open automatically, as it did in previous versions.

Screenshots
No screenshots available

Logs

  • GUI version: Not applicable.
  • CLI version:
sudo gpclient --fix-openssl connect address-redacted.com --default-browser
[2024-08-28T13:10:12Z INFO  gpclient::cli] gpclient started: 2.3.7 (2024-08-16)
[2024-08-28T13:10:12Z INFO  gpapi::portal::prelogin] Portal prelogin with user_agent: PAN GlobalProtect
[2024-08-28T13:10:12Z INFO  gpapi::portal::prelogin] Perform prelogin, user_agent: PAN GlobalProtect
[2024-08-28T13:10:12Z INFO  gpauth::cli] gpauth started: 2.3.7 (2024-08-16)
[2024-08-28T13:10:12Z INFO  gpauth::cli] Fixing OpenSSL environment
[2024-08-28T13:10:12Z INFO  gpapi::process::browser_authenticator] Launching the default browser...
[2024-08-28T13:10:12Z INFO  gpauth::cli] Please continue the authentication process in the default browser
[2024-08-28T13:10:12Z INFO  gpauth::cli] Listening authentication data on port 36877
[2024-08-28T13:10:12Z INFO  gpauth::cli] If it hangs, please check the logs at `/tmp/gpcallback.log` for more information

Environment:

  • OS: Ubuntu 22.04.4 LTS
  • Desktop Environment: GNOME
  • Output of ps aux | grep 'gnome-keyring\|kwalletd5' | grep -v grep: rleinar+ 4311 0.0 0.0 388896 7372 ? Sl 08:42 0:00 /usr/bin/gnome-keyring-daemon --daemonize --login
  • Is remote SSH? No

Additional context
This issue started appearing after recent updates to the GlobalProtect-openconnect CLI client. Previously, using the --default-browser parameter correctly opened the default browser set in the system preferences.
Probably related to the changes from #360

@yuezk
Copy link
Owner

yuezk commented Aug 28, 2024 via email

@leinardi
Copy link
Author

Thanks, I'm already using that workaround, but still it's a issue that --default-browser is not actually starting the default browser, like it used to do before the regression.

@yuezk
Copy link
Owner

yuezk commented Aug 28, 2024 via email

@leinardi
Copy link
Author

Unfortunately not: it behaves exactly like --default-browser

@yuezk
Copy link
Owner

yuezk commented Aug 28, 2024

The default-browser option can still launch the browser, but it is not the default one, right?

Can you finish authentication in the launched browser?

@yuezk
Copy link
Owner

yuezk commented Aug 29, 2024

Hi @leinardi, both the --default-browser and --browser default options work as expected for me on Ubuntu 20.04.6 LTS, GNOME 3.36.8. Do you have other Linux machines to test with?

@leinardi
Copy link
Author

Hi @yuezk, I have another installation of Ubuntu 24.04, but I'm also available to do a remote debugging session using TeamViewer or some other remote desktop software if you want to have a look at what's going on on my 22.04.4.

Anyway, I did some more tests and I found out a strange behavior...
These 2 commands open Firefox correctly:

sudo -E gpclient --fix-openssl connect redacted-address.com --browser firefox
gpauth redacted-address.com --browser firefox

but if I replace --browser firefox with --browser default or --default-browser Chrome, the default browser, is not open but telegram-desktop is opened instead!

I installed telegram-desktop using snap.

How is --browser default trying to detect the default browser? Probably there is some issue in the detection logic because it worked fine in the previous versions and I had telegram-desktop installed since the beginning.

And I double checked and Chrome is the default browser of the system:
Screenshot from 2024-08-29 09-43-20

And this is the output of xdg-settings get default-web-browser:

$ xdg-settings get default-web-browser
google-chrome.desktop

and xdg-open http://google.com it correctly opens in Chrome, the default browser, so I really think that there is something faulty in how the GlobalProtect-openconnect is detecting it.

@yuezk
Copy link
Owner

yuezk commented Aug 29, 2024

@leinardi under the hood, it will use xdg-open to launch the browser. https://github.com/Byron/open-rs/blob/c26d98cc66979f153682690201a4748026012224/src/unix.rs#L17-L22

  1. Try to run xdg-open https://google.com to see if it can open the default browser.
  2. Try to run echo '<h1>hello, world</h1>' > /tmp/test.html && xdg-open /tmp/test.html to see if it can open the default browser.

@leinardi
Copy link
Author

Hi @yuezk

  1. Try to run xdg-open https://google.com to see if it can open the default browser.

This question was already answered in my previous comment:

and xdg-open http://google.com it correctly opens in Chrome, the default browser, so I really think that there is something faulty in how the GlobalProtect-openconnect is detecting it.

  1. Try to run echo '<h1>hello, world</h1>' > /tmp/test.html && xdg-open /tmp/test.html to see if it can open the default browser.

ok this is very strange: xdg-open /tmp/test.html opens telegram but xdg-open http://google.com opens Chrome (the default browser).

image
It looks like telegram was somehow associated with the .html file extension.

The interesting thing is that the default application associated with it (if I press the "Reset" button) is Firefox and not Chrome:

image

Unfortunately xdg-open file:///tmp/test.html still opens the MIME type associated with .html and not the default browser.

But sensible-browser /tmp/test.html seems to work (it opens Chrome instead of Firefox), could you maybe evaluate to use sensible-browser when the --default-browser and --browser default options and fallback to xdg-open if sensible-browser is not available (should be preinstalled on all the Debian-based distributions)?

Btw you can find if there is a mismatch between the default browser and the MIME type associated with .html running these commands:

$ xdg-mime query default text/html
firefox.desktop
$ xdg-settings get default-web-browser
google-chrome.desktop

so it would be possible to find a solution that works on every distribution if you run xdg-settings get default-web-browser and extract the default browser from the .desktop file. Something like this perhaps?

#!/bin/bash

# Get the .desktop file for the default web browser
desktop_file=$(xdg-settings get default-web-browser)

# Look for the .desktop file in standard locations
desktop_file_path=$(find /usr/share/applications ~/.local/share/applications -name "$desktop_file" 2>/dev/null | head -n 1)

# Check if the .desktop file was found
if [ -z "$desktop_file_path" ]; then
    echo "Error: Could not find the .desktop file for the default web browser."
    exit 1
fi

# Extract the Exec line, which typically starts with "Exec="
exec_line=$(grep -i '^Exec=' "$desktop_file_path" | head -n 1)

# Remove the "Exec=" prefix and take only the first word (the binary path)
browser_binary=$(echo "$exec_line" | sed 's/^Exec=//' | awk '{print $1}' | sed 's/\"//g')

# Check if the binary path is found
if [ -z "$browser_binary" ]; then
    echo "Error: Could not extract the browser binary path."
    exit 1
fi

# Output the path to the binary
echo $browser_binary

@yuezk
Copy link
Owner

yuezk commented Aug 29, 2024

@leinardi thanks for sharing this! I will fix it. BTW, do you have the $BROWSER environment variable on your system?

@leinardi
Copy link
Author

leinardi commented Aug 29, 2024

@yuezk nope, it is not set: $ env | grep BROWSER returns nothing and echo $BROWSER returns an empty string.

@yuezk
Copy link
Owner

yuezk commented Sep 12, 2024

Yes, the default browser detection can be enhanced. I will fix it in the next release.

@yuezk yuezk added bug Something isn't working default-browser labels Sep 12, 2024
@yuezk
Copy link
Owner

yuezk commented Nov 1, 2024

This should be fixed in https://github.com/yuezk/GlobalProtect-openconnect/releases/tag/v2.3.8. Let me know if it still doesn't work.

@yuezk yuezk closed this as completed Nov 1, 2024
@leinardi
Copy link
Author

leinardi commented Nov 5, 2024

Hi @yuezk thank you for the fix! It's confirmed to be working for me on Ubuntu 24.04.1 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working default-browser
Projects
None yet
Development

No branches or pull requests

2 participants