Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8214069

Use xdg-open to get default web browser on Linux systems

XMLWordPrintable

    • x86_64
    • linux

      ADDITIONAL SYSTEM INFORMATION :
      - Any Linux distribution with a desktop environment is concerned
      - Unrelated to the version of Java but found in JavaFX versions from Oracle's 8 releases until current OpenJFX's 11.0.1.

      A DESCRIPTION OF THE PROBLEM :
      From https://github.com/javafxports/openjdk-jfx/issues/260
      --

      Hello, I am pretty sure this has been reported already (at the very least, probably even discussed) but I just cannot find it, please do not hesitate to let me know if you have the original handy.

      On Linux systems, right now (i.e. in OpenJFX 11) getting a handle on the default browser is done through a static array in `HostServicesDelegate` as so :
      ```java
       static final String[] browsers = {"google-chrome", "firefox", "opera",
      "konqueror", "mozilla"};
      ```

      which is then iterated over to find the installed one and run a process to open it :
      ```java
      } else { //assume Unix or Linux
          String browser = null;
          for (String b : browsers) {
              if (browser == null && Runtime.getRuntime().exec(
                      new String[]{"which", b}).getInputStream().read() != -1) {
                  Runtime.getRuntime().exec(new String[]{browser = b, uri});
              }
          }
          if (browser == null) {
              throw new Exception("No web browser found");
          }
      }
      ```

      This :
      - Doesn't support third-party browsers (i.e. Brave, Vivaldi, Pale Moon and others)
      - Doesn't support beta versions of some major ones (e.g. Firefox whose beta version binary name is `firefox-beta` at least on Archlinux derivates)

      In regard to these issues, a simple fix would be to rely on the widely accepted default of relying on freedesktop's `xdg-open` command which will automatically select any OS-registered browser in most GUI-enabled Linux environments (while JavaFX has some headless support I find it more reasonable to assume users generally have a GUI given the very nature of JavaFX).

      I propose a fix that would remove the array and its subsequent usage to be replaced by `xdg-open`.

      In the very same vein, I would assume that this issue (or another one at least) should use Apple's `open` command for macOS rather than relying on AWT's `Desktop` class.

      Thank you for your consideration and sorry if this has been debated but again I could not easily find a place where such a debate would have been had (at least not in a reasonable search time).

      --- (If not clear I would of course volunteer for implementing that/these fixes)


            kcr Kevin Rushforth
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: