Score:0

Unable to launch browser from shell - it opens VSCode instead

us flag

I have a problem when some shell command is trying to launch my browser. Example below with browse command, but same with jupyter notebook. It looks like the target is opened in VSCode instead.

I'm running Ubuntu 20.04, with zsh, in a pyenv virtual environment.

Thanks!

~ browse askubuntu.com
    command= "code" args= ("code", "http://askubuntu.com")                                                                                                                                
~ Copying QUrl("http://askubuntu.com/")  to QUrl("file:///home/username/.cache/kioexec/krun/8292_0/unnamed")
    Telling kioexecd to watch path "/home/username/.cache/kioexec/krun/8292_0/unnamed" dest "http://askubuntu.com/"
    All files downloaded, will call slotRunApp shortly
    EXEC "/snap/bin/code /home/username/.cache/kioexec/krun/8292_0/unnamed"
    EXEC done

... then VSCode opens the target as a html file.

  • EDIT: Same error when I run xdg-open 'http://askubuntu.com'

  • EDIT: xdg-settings get default-web-browser yields code-2.desktop

  • EDIT: if I do xdg-settings set default-web-browser firefox.desktop, no error raised but it doesn't actually change the value (stays as code-2.desktop)

  • EDIT: $BROWSER askubuntu.com works perfectly fine

  • SOLVED: Thanks to @Koen I went to System settings/Applications/Default Applications (I'm on KDE) --> Web Browser --> Open http and https URLs "in the following application: Firefox" instead of "in an application based on the contents of the URL"

edmz avatar
us flag
I meant Ubuntu 20.04.3 LTS
Koen avatar
ca flag
do a "echo ?" after setting the default web browser - correct value is probably firefox_firefox.desktop
Score:1
in flag

You forgot the http:// which defines that what you are browsing is a website instead of a file. when you type "browse" alone you get

xdg-open - opens a file or URL in the user's preferred application

Try browse http:/google.com

This should fix the issue.

edmz avatar
us flag
Thanks for your answer but it does not fix the issue. The issue is really that it does not launch my browser. Same when I use jupyter. It opens VSCode instead
Score:0
ca flag

xdg-settings fails silently - an echo $? can show you that return code is not 0 when it failed

return codes:

1 Error in command line syntax.
2 One of the files passed on the command line did not exist.
3 A required tool could not be found.
4 The action failed.

browse is a link to xdg-open - so you need to supply an url to open the default browser

the default browser can also be set via gui tools

  • gnome: gnome-control-center - default applications - web
  • KDE: System settings/Applications/Default Applications --> Web Browser --> Open http and https URLs "in the following application: Firefox"
edmz avatar
us flag
Thank you, but `echo $?` yields code `4` when I try setting with `firefox_firefox.desktop` as well
Koen avatar
ca flag
in my system the desktop files are stored here : /var/lib/snapd/desktop/applications/ - check if you have a desktop file there for firefox
Koen avatar
ca flag
otherwise start gnome-control-center and select the default browser via "default applications" menu
edmz avatar
us flag
It's /usr/share/applications/firefox.desktop ...while the one actually called is ~/.local/share/applications/code-2.desktop
edmz avatar
us flag
Great! It works: I went to System settings/Applications/Default Applications (I'm on KDE) --> Web Browser --> Open http and https URLs "in the following application: Firefox" instead of "in an application based on the contents of the URL"
edmz avatar
us flag
Jupyter notebook also launches in the browser now. Thank you!
edmz avatar
us flag
I'm a bit new to this stack: should I edit your answer to match the actual solution? Anyway I edited the main question text
Koen avatar
ca flag
I updated my answer with the different points
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.