Skip to content

Preview in browser fails in WSL with: exec: "xdg-open": executable file not found in $PATH #826

Closed

Description

@valorin

Describe the bug

The Preview in Browser option for a new pull request (via gh pr create) fails with the following error when used in WSL (I'm using the Pengwin distro on WSL2):

exec: "xdg-open": executable file not found in $PATH

As a result, you lose the PR body you've typed into the editor and have to start the PR creation process again.

$ gh --version
gh version 0.7.0 (2020-04-22)
https://github.com/cli/cli/releases/tag/v0.7.0

$ wslsys
Locale: en_AU
Release Install Date: Sat Apr 18 18:02:48 AEST 2020
Branch: rs_prerelease
Build: 19608
Full Build: 19608.1000.amd64fre.rs_prerelease.200410-1438
Display Scaling: 1
Windows Theme: light
Windows Uptime: 0d 13h 55m
WSL Uptime: 0d 5h 16m
WSL Release: Pengwin
WSL Kernel: Linux 4.19.104-microsoft-standard
Packages Count: 659

Steps to reproduce the behavior

  1. Using WSL on Windows 10
  2. Follow the prompts in gh pr create
  3. Select the Preview in Browser option

Expected vs actual behavior

This error is thrown and the command exits, losing all information:

exec: "xdg-open": executable file not found in $PATH

Ideally it should open the browser on the host to preview the PR, as if it was run on the host directly. wslview is included with most WSL distros and can be used to open the browser in Windows 10. More information: https://github.com/wslutilities/wslu

The alternative would be to provide the user the option to submit the PR directly or display a URL to manually paste into the browser for the preview.

Logs

valorin@Pengwin:~/dev/project/www (FB834)$ gh pr create

Creating pull request for FB834 into master in project/project-www

? Title FB834: Tweak width of invoice to/from/status for comfort
? Body <Received>
? What's next? Preview in browser
Enumerating objects: 13, done.
Counting objects: 100% (13/13), done.
Delta compression using up to 4 threads
Compressing objects: 100% (7/7), done.
Writing objects: 100% (7/7), 1.43 KiB | 1.43 MiB/s, done.
Total 7 (delta 6), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (6/6), completed with 6 local objects.
remote:
remote: Create a pull request for 'FB834' on GitHub by visiting:
remote:      https://github.com/project/project-www/pull/new/FB834
remote:
To github.com:project/project-www.git
 * [new branch]        HEAD -> FB834
Branch 'FB834' set up to track remote branch 'FB834' from 'origin'.
Opening github.com/project/project-www/compare/master...FB834 in your browser.
exec: "xdg-open": executable file not found in $PATH

Activity

  1. added
    bug
    on Apr 24, 2020
  2. mislav commented on May 7, 2020

    @mislav
    Contributor

    As a result, you lose the PR body you've typed into the editor and have to start the PR creation process again.

    Ouch, sorry for that. We should try to save your PR title & body on failure so you can reuse those on next retry.

    wslview is included with most WSL distros and can be used to open the browser in Windows 10

    Thanks for sharing that! We will try to detect and use that in the future. Until then, you can set export BROWSER=wslview in the shell where you use gh and GitHub CLI will use that executable when opening a browser.

  3. valorin commented on May 7, 2020

    @valorin
    Author

    Awesome, thanks! I'll enable export BROWSER=wslview now. 😁

  4. viperfx commented on May 9, 2020

    @viperfx

    For me, it opens at http://127.0.0.1:39337/callback?browser_session_id=.... and chrome cannot connect to this server.

    EDIT:

    Followed comment in #597 and its working now!

  5. jetersen commented on Jun 12, 2020

    @jetersen

    This is my tiny hack for xdg-open not being available and without need to install xdg-utils other tools might stumble ie. kubelogin

    use these two tweaks for the best experience on WSL.

    export BROWSER=wslview
    
    sudo ln -s $(which wslview) /usr/local/bin/xdg-open
    
  6. mislav commented on Jun 12, 2020

    @mislav
    Contributor

    @jetersen Thanks, but this seems like more steps than just setting export BROWSER=wslview in your shell config file 🤔 Do you recommend people to take yours over the environment variable approach?

  7. jetersen commented on Jun 12, 2020

    @jetersen

    No I suggest both fixes to have the most success with compatibility.

    I still use export BROWSER=wslview for those programs that support it.
    Sadly kubelogin uses pkg/browser which seems unmaintained: https://github.com/pkg/browser/pulse/monthly
    PRs are there that would fix compatiblity.

    I put my BROWSER=wslview into the /etc/environment when multiple users are involved on WSL.

  8. mislav commented on Jun 17, 2020

    @mislav
    Contributor

    No I suggest both fixes to have the most success with compatibility.

    @jetersen Ah I see now that you were not solving this issue just for gh, but for other tools as well. Thanks!

  9. felipecrs commented on Jun 19, 2020

    @felipecrs

    I take a similar approach as @jetersen, but easier:

    sudo ln -s $(which wslview) /usr/local/bin/xdg-open

    Just run and you should be good to go.

  10. jetersen commented on Jun 19, 2020

    @jetersen

    @felipecassiors good point, I did not think of symlinking.
    I suspect search engines are leading a lot of users to this issue.

  11. Stilborg commented on Feb 8, 2021

    @Stilborg

    This is my tiny hack for xdg-open not being available and without need to install xdg-utils other tools might stumble ie. kubelogin

    use these two tweaks for the best experience on WSL.

    export BROWSER=wslview
    
    sudo ln -s $(which wslview) /usr/local/bin/xdg-open
    

    Thx @jetersen you saved me! , fandme verdensklasse

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions