Core20 - setting default browser

Hey,

So I’m getting stuck into snapcrafting, and since most tutorials deal with kiosks that seemed like the logical place to go. Frankly its been fun so far.

So now I’m running Core20 on an AMD64 VM with Ubuntu Frame and my custom snap. The custom snap is simply wrapping the Epiphany Browser (aka Gnome Web) and turning it into a daemon. Which works like a charm!

The only issue I cannot for the life of me figure out is how to set Epiphany as the “default browser” within the snap. So the kiosk display has a big “do you want to set Epiphany as your default browser?” flag at the top.

Normally its just use xdg-config, but that’s X11 only and it would be nice not having to bundle the xdg-utils with a wayland based snap for the single purpose of setting a default browser option.

Anyone got any pointers or ideas?

Here is the snapcraft.yaml (it’s a bit of a mess, but works for prototyping :wink: ):

name: web-kiosk  # you probably want to 'snapcraft register <name>'
version: '0.2' # just for humans, typically '1.2+git' or '1.3.2'
summary: etc # 79 char long summary
description: |
  etc
  etc
confinement: devmode
#compression: lzo
grade: devel
base: core20

apps:
  daemon:
    extensions: [gnome-3-38]
    command-chain:
      - bin/wayland-launch
    command: bin/kiosk
    daemon: simple
    restart-condition: always
    restart-delay: 2s
    plugs:
      - opengl
      - wayland
      - network
      - network-bind

plugs:
  graphics-core20:
    interface: content
    target: $SNAP/graphics
    default-provider: mesa-core20
  gnome-3-38-2004:
    default-provider: gnome-3-38-2004
    interface: content
    target: $SNAP/gnome-platform
  gtk-3-themes:
    default-provider: gtk-common-themes
    interface: content
    target: $SNAP/data-dir/themes
  icon-themes:
    default-provider: gtk-common-themes
    interface: content
    target: $SNAP/data-dir/icons
  sound-themes:
    default-provider: gtk-common-themes
    interface: content
    target: $SNAP/data-dir/sounds

environment:
  # This is one of four snippets that relate to providing the userspace graphics needed by your application.
  LD_LIBRARY_PATH: $SNAP/graphics/lib:${SNAP}/usr/lib/:${SNAP}/usr/lib/x86_64-linux-gnu/
  LIBGL_DRIVERS_PATH: $SNAP/graphics/dri
  LIBVA_DRIVERS_PATH: $SNAP/graphics/dri
  __EGL_VENDOR_LIBRARY_DIRS: $SNAP/graphics/glvnd/egl_vendor.d
  # Other, generally useful environment settings...
  # XDG config
  XDG_CACHE_HOME:  $SNAP_USER_COMMON/.cache
  XDG_CONFIG_HOME: $SNAP_USER_DATA/.config
  XDG_CONFIG_DIRS: $SNAP/etc/xdg
  # XKB config
  XKB_CONFIG_ROOT: $SNAP/usr/share/X11/xkb

# The `layout` ensures that files can be found by applications where they are expected by the toolkit or application.
layout:
  # This is one of four snippets that relate to providing the userspace graphics needed by your application.
  # These paths (/usr/share/libdrm and /usr/share/drirc.d) are hardcoded in mesa.
  /usr/share/libdrm:  # Needed by mesa-core20 on AMD GPUs
    bind: $SNAP/graphics/libdrm
  /usr/share/drirc.d:  # Used by mesa-core20 for app specific workarounds
    bind: $SNAP/graphics/drirc.d
  # Other, generally useful paths
  /usr/share/fonts:
    bind: $SNAP/usr/share/fonts
  /usr/share/icons:
    bind: $SNAP/usr/share/icons
  /usr/share/sounds:
    bind: $SNAP/usr/share/sounds
  /etc/fonts:
    bind: $SNAP/etc/fonts
  # custom for browser profile management
  /usr/libexec/epiphany-browser/ephy-profile-migrator:
    bind-file: $SNAP/usr/libexec/epiphany-browser/ephy-profile-migrator
  /usr/libexec/epiphany-browser/epiphany-test:
    bind: $SNAP_COMMON/epiphany/.config
  # custom for browser x86_64
  /usr/lib/x86_64-linux-gnu/epiphany-browser:
    bind: $SNAP/usr/lib/x86_64-linux-gnu/epiphany-browser # should fix the library issue earlier!!!
  # custom for browser arm64
  /usr/lib/arm64-linux-gnu/epiphany-browser:
    bind: $SNAP/usr/lib/arm64-linux-gnu/epiphany-browser # should fix the library issue earlier!!!
  # custom for browser aarch64
  /usr/lib/aarch64-linux-gnu/epiphany-browser:
    bind: $SNAP/usr/lib/aarch64-linux-gnu/epiphany-browser # should fix the library issue earlier!!!



parts:
  kiosk:
    source: sh/
    plugin: dump
    stage-packages:
      - epiphany-browser
      - epiphany-browser-data # << after here
      - iso-codes
      - libatk1.0-0
      - libcairo2
      - libdazzle-1.0-0
      - libgcr-base-3-1
      - libgcr-ui-3-1
      - libgdk-pixbuf2.0-0
      - libglib2.0-0
      - libgmp10
      - libgtk-3-0
      - libhandy-0.0-0
      - libhogweed5
      - libjavascriptcoregtk-4.0-18
      - libjson-glib-1.0-0
      - libnettle7
      - libnotify4
      - libpango-1.0-0
      - libsecret-1-0
      - libsoup2.4-1
      - libsqlite3-0
      - libwebkit2gtk-4.0-37
      - libxml2
      - gstreamer1.0-gtk3
    organize:
      'kiosk': bin/kiosk


  # Some utility scripts for setting up the Wayland environment
  wayland-launch:
    plugin: dump
    source: ./wayland-launch
    override-build: |
      # The plugs needed to run Wayland. (wayland-launch checks them, setup.sh connects them)
      # You may add further plugs here if you want these options
      PLUGS="opengl wayland graphics-core20"
      sed --in-place "s/%PLUGS%/$PLUGS/g" $SNAPCRAFT_PART_BUILD/bin/wayland-launch
      sed --in-place "s/%PLUGS%/$PLUGS/g" $SNAPCRAFT_PART_BUILD/bin/setup.sh
      sed --in-place "s/%SNAP%/$SNAPCRAFT_PROJECT_NAME/g" $SNAPCRAFT_PART_BUILD/bin/setup.sh
      snapcraftctl build
    stage-packages:
      - inotify-tools

  # This is one of four snippets that relate to providing the userspace graphics needed by your application.
  # This ensures that your snap doesn't contain its own copy of the userspace drivers
  cleanup:
    after:
    # Your application packaging
      - wayland-launch
    plugin: nil
    build-snaps: [ mesa-core20 ]
    override-prime: |
      set -eux
      cd /snap/mesa-core20/current/egl/lib
      find . -type f,l -exec rm -f $SNAPCRAFT_PRIME/usr/lib/${SNAPCRAFT_ARCH_TRIPLET}/{} \;
      rm -fr "$SNAPCRAFT_PRIME/usr/lib/${SNAPCRAFT_ARCH_TRIPLET}/dri"
      for CRUFT in bug drirc.d glvnd libdrm lintian man; do
        rm -rf "$SNAPCRAFT_PRIME/usr/share/$CRUFT"
      done

Well, a bit of wandering and I found a solution. in prime/usr/share/glib-2.0/schemas/org.gnome.epiphany.gschema.xml there is the option to turn off asking to be made the default browser (~59th line).

                <key type="b" name="ask-for-default">
                        <default>true</default> <<<<----- set to false
                        <summary>Whether to ask for setting browser as default</summary>
                        <description>When this option is set to true, browser will ask for being default if it is not already set.</description>

So hooray! Hopefully someone else that isn’t a Gnome aficionado will find this useful as well.

1 Like