Stric confinement application must open firefox web browser

Hi,

I’m make snap of an application with snapcraft. I want to use strict confinement mode. Snap of my application work fine except about one point.

My application in sevral case must open firefox web-browser to display pages.

When this happens application continue to works but the web browser isn’t open. Application’s log show the following line :
sh: 1: firefox: not found

Can anyone can help me do this possible with strict confinement ?

Thanks by advance.

The correct way to open a system browser is to use the xdg-open mechanism.

Do you have exemple about how to do this ?

I previously tried to add these lines into snapcraft.yaml but no way to open web browser.

snapd-xdg-open:
source: https://github.com/ubuntu-core/snapd-xdg-open.git
plugin: dump
organize:
data/xdg-open: bin/xdg-open
stage-packages:
-dbus

For plugs:
plugs: [desktop, desktop-legacy,x11,home,browser-support,network,network-bing]

I may have missed something, but what ?

You should not pull in snapd-xdg-open. The core snap (or a relevant base) already ships xdg-open that does what you want. All your application needs to do is declare a desktop plug and run xdg-open <url>.

2 Likes

I do sevral snapcraft.yaml but the result is the same:

Remove snapd-xdg-open part. Leave dektop plug then create /bin/firefox into my my snap directory (so my snap app can try to open web browser as it designed).
The content of this file is just:

#! /bin/sh
echo “Call xdg-open”
echo "arg 1 : "$1
#Just for test
firefox http://www.free.fr

When i launch my snap (strict mode), firefox isn’t launch but the log is:


Run into game loop
Call xdg-open
arg 1 : file:///home/stan/snap/foobillard-plus/x1/foobillardplus-data/html/tournament.xml
Error org.freedesktop.DBus.Error.ServiceUnknown: The name com.canonical.SafeLauncher was not provided by any .service files

Snapd-xdg-open is install and run fine when i try ‘xdg-open http://www.free.fr’ into a terminal.

Any idea ?

As described above, don’t pull in xdg-open inside your snap. Snapd automatically provides one that works.

your script calls firefox http://www.free.fr

instead you want to follow @zyga-snapd’s advise and also make your script call:

xdg-open http://www.free.fr

that will open the site in the defined default browser of your desktop (typically firefox but users might have removed firefox and use chromium … xdg-open takes care of that so your snap does not break)

Sorry i didn’t understand exactly what you mean ;(

This is my current snapcraft.yaml, maybe this can help…
Firefox is just the default choice of application conceptors to display results of the game…

name: foobillardplus
version: '3.43.0'

summary: billard game simulator
description: |
   FooBillard++ is an advanced 3D OpenGL billiard game based on the original foobillard 3.0a sources from Florian Berger.
   You can play it with one or two players or against the computer.
   |
   The game features:
   * Wood paneled table with gold covers and gold diamonds.
   * Reflections on balls.
   * Zoom in and out, rotation, different angles and bird's eye view.
   * Different game modes: 8 or 9-ball, Snooker or Karambol.
   * Tournaments. Compete against other players.
   * Animated cue with strength and eccentric hit adjustment.
   * Jump shots and snipping.
   * Realistic gameplay and billiard sounds.
   * Red-Green stereo.
   * And much more.
   |
   Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
   Upstream-Name: FooBillard++
   Upstream-Contact: Holger Schäkel <foobillardplus@go4more.de>
   Source: http://sourceforge.net/projects/foobillardplus
   |
   Copyright: 2001-2003, Florian Berger
              2010-2013, Holger Schäkel <foobillardplus@go4more.de>
   License: GPL-2

#grade: devel,stable
grade: stable
#confinement: devmode,classic,strict
confinement: strict

architectures: [amd64]
type: app

#before launch snapcraft use get_foobillardplus.sh shell script to generate foobillardplusmake.tar.gz archive.
#foobillardplusmake.tar.gz archive created from source files contents the configure file needed to apply snapcraft make plugin.
#Readme.txt informs about configuration options to use to generate this snapfile.
#For developpement of snapfile :
#-use Ubuntu 16.04 Xenial distribution to generate snapfile, and check if snap-packages specified into snapcraft are installed on for building step.
#-use sudo strace foobillardplus.launcher command to locate errors at startup if needed.

#command exposition from outside of the snap
apps:
  launcher:
    #launcher for foobillardplus binary
    #for devmode and strict confinement use command : desktop-launch $SNAP/usr/games/foobillardplus/bin/foobillardplus
    command: desktop-launch $SNAP/usr/games/foobillardplus/bin/foobillardplus
    #for classic mode (no confinement)use command: bin/desktop-launch $SNAP/usr/games/foobillardplus/bin/foobillardplus
    #command: bin/desktop-launch $SNAP/usr/games/foobillardplus/bin/foobillardplus
    #desktop application menu shortcut
    desktop: usr/games/foobillardplus/foobillardplus.desktop
    #define interfaces for strict confinement 
    plugs: [desktop, desktop-legacy, wayland, x11, opengl, home, pulseaudio, network, network-bind]

#order of snap creation step : pull > build > stage > prime > snap
#application parts
parts:   
  #build foobillardplus from sources with snapcraft make plugin
  foobillardplus:
    source: foobillardplusmake.tar.gz
    plugin: make
    #if artifacts used then no make install done. Just specified artifacts files/directory will be add to snap 
    artifacts : [src,data,AUTHORS,COPYING,INSTALL,README,ChangeLog,TODO,foobillardplus.png,foobillardplus.xbm]
    #after directive is mandatory for devmode and strict modes
    after:
      - desktop-qt5
    stage-packages:
      - dbus
      - libslang2
      - libglu1
      - libglu1-mesa
      - libgl1
      - libgl1-mesa-glx
      - libfreetype6
      - fonts-dejavu
      - fonts-dejavu-core
      - ttf-dejavu-core
      - libpng12-0
      - libsdl1.2-dev
      - libpcre3
      - zlib1g
      - libsdl-mixer1.2
      - libsdl-net1.2
      - libjack0
      - libopenal1
      - libmad0
      - libvorbisfile3
      - libmikmod3
      - libfluidsynth1
    organize:
      src/foobillardplus: usr/games/foobillardplus/bin/foobillardplus
      src: usr/games/foobillardplus/src
      data: usr/games/foobillardplus/data
      'AUTHORS': usr/games/foobillardplus/AUTHORS
      'COPYING': usr/games/foobillardplus/COPYING
      'INSTALL': usr/games/foobillardplus/INSTALL
      'README': usr/games/foobillardplus/README
      'ChangeLog': usr/games/foobillardplus/ChangeLog
      'TODO': usr/games/foobillardplus/TODO
      'foobillardplus.png': usr/games/foobillardplus/foobillardplus.png
      'foobillardplus.xbm': usr/games/foobillardplus/foobillardplus.xbm

  foobillardplus-dump:
    #dump context : 
    #at least to files/directories needed into archive to copy archive content into snap at the wright path,
    #otherwise use organize directive.
    #misc/snapcraft.yaml [snapcraft.yaml use to generate this foobillardplus snapfile]
    #misc/foobillardplusdump.tar.gz [archive of files to add into the snap]
    #misc/get_foobillardplus.sh [shell script to download sources then generate the configure fine needed for snapcraft make plugin]
    #usr/games/foobillardplus/data/foobillardplus.desktop [desktop application launcher file]
    #usr/games/foobillardplus/data/*.ttf [all fonts .ttf files needed]
    #bin/firefox [shell script include into the application source, and used by application binary itself to display results of the game]
    source: foobillardplusdump.tar.gz
    plugin: dump

You are running firefox path/to/file.xml. Don’t do that. Do xdg-open path/to/file.xml.

P.S. I don’t know whether xdg-open supports file:/// paths, so you might fail to launch your file in the browser because it is local.

Yes, i did it and change bin/firefox to test with something different from /// url,

#! /bin/sh
echo “Call xdg-open”
echo "arg 1 : "$1
#Just for test
xdg-open http://www.free.fr

But the error is the same:
Error org.freedesktop.DBus.Error.ServiceUnknown: The name com.canonical.SafeLauncher was not provided by any .service files

But if i test it outside snap, on host, in terminal xdg-open http://www.free.fr works fine… very strange…
My host is clean Ubuntu 16.04 Xenial with all snaps core, snapcraft, … refreshed… and tested generated snapfile on Ubuntu 18.10 Cosmic but the rest is the same…

PS : you’re wright file:/// could be change to another path (in $SNAP_USER for exemple with home plug), but before i need to validate xdg-open http://www.free.fr works fine.

this looks like your snap still contains xdg-utils … did you do a snapcraft clean before you re-built the snap when you dropped xdg-utils from your snapcraft.yaml ?

Perfect guys.

You’re wright : the trouble come from my snap wich contained xdg-utils of my previous try, even if this part was removed from my snapcraft.yaml.

I just use ‘snapcraft clean’ to really remove it, then rebuild with snapcraft command my project. Now it is possible to open urls like www.free.fr into web-browser from my snap.

Thanks a lot for your help !