How a snap can use the default system browser to open a URL?

Bug #1831992 reported by Aston
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
snapd
Won't Fix
Low
Unassigned

Bug Description

I have a snap with a JavaFX application, which should be able to use the system's browser to show some URL.

However, it seems that no browser can be found in the environment by the snap. The following error occurs:

>> java.lang.Exception: No web browser found
 at com.sun.javafx.application.HostServicesDelegate$StandaloneHostService.showDocument(HostServicesDelegate.java:146)
 at javafx.application.HostServices.showDocument(HostServices.java:115)
 at org.rustkeylock.fragments.EditConfiguration$Center.org$rustkeylock$fragments$EditConfiguration$Center$$handleGetToken(EditConfiguration.scala:201)
 at ...
...more stacktrace messages...

I tried including the browser-support plug in the snapcraft.yaml with no luck.

How can the system browser be called? Is there some interface that I can use?

You can find the snapcraft yaml here: https://github.com/rust-keylock/rust-keylock-ui/blob/master/snap/snapcraft.yaml

I use base18 and openjdk 11.

Tags: browser javafx
Revision history for this message
Maciej Borzecki (maciek-borzecki) wrote :

You should use `xdg-open <url>` to open the browser. Looking at the implementation here: http://hg.openjdk.java.net/openjfx/jfx-dev/rt/file/981cff5755bc/modules/javafx.graphics/src/main/java/com/sun/javafx/application/HostServicesDelegate.java the upstream code seems to do that already, though I cannot tell whether that's the same version of runtime as you have.

On the snap side, it should be enough to use the `desktop` plug.

Revision history for this message
Aston (astonbitecode) wrote :

Thanks for that,

Adding the desktop plug alone did not help, but I tweaked a bit the code to call the xdg-open directly, rather than letting JavaFX doing the job.

I am not sure why JavaFX call did not work, but anyway this is not a snap issue.

affects: snapcraft → snapd
Revision history for this message
Zygmunt Krynicki (zyga) wrote :

@Aston: is it possible that you had somehow bundled the xdg-open from a Debian package into your snap? Inside the core/core16/core18 snaps there's a special version of xdg-open that talks to snapd directly.

Alternatively: can you please provide a simple java program that attempts to open a program (I'm sorry, my java is so rusty I would not want to write that myself) and we can run that as a part of the regression suite.

Changed in snapd:
status: New → Incomplete
importance: Undecided → Low
Revision history for this message
Aston (astonbitecode) wrote :

I just use core18, no special tweaks or packaging.

I created a simple example here: https://github.com/astonbitecode/javafx-xdg-open-snap

It is a simple snap that uses JavaFX and offers two buttons. The one uses JavaFX's functionality to open the web browser, whereas the second uses xdg-open.

The JavaFX code to open a browser is as simple as:

`getHostServices().showDocument("https://snapcraft.io/")`

Please tell me if I can help further.

Revision history for this message
Launchpad Janitor (janitor) wrote :

[Expired for snapd because there has been no activity for 60 days.]

Changed in snapd:
status: Incomplete → Expired
Revision history for this message
Ian Johnson (anonymouse67) wrote :

IIUC, this is where JavaFX implements the showDocument method:

https://github.com/teamfx/openjfx-9-dev-rt/blob/master/modules/javafx.graphics/src/main/java/com/sun/javafx/application/HostServicesDelegate.java

which implies that it tries to check for the various browser executables existing on $PATH and when they don't it considers them as not available. I'm not sure how snaps could be adapted to work with this other than making the java application classic.

Changed in snapd:
status: Expired → Won't Fix
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.