Chromeにロードされたウェブサイトを変更しようとしたときにXサーバーまたは$ DISPLAY不足を解決する方法

Chromeにロードされたウェブサイトを変更しようとしたときにXサーバーまたは$ DISPLAY不足を解決する方法

私はラズベリーの使用が初めてで、チリパイキオスクを使用してラズベリーパイでキオスクを開発しています。アイデアは、Raspberry Piが起動すると、ChromiumブラウザがApacheサーバー(localhost)のページから起動されることです。次の構成(.xsession)を使用してこれを達成します。


#!/bin/bash

## Establece la variable de entorno DISPLAY para que los programas X11 sepan dónde mostrar su interfaz gráfica. En este caso, :0.0 indica que el servidor de visualización X11 local está en la pantalla 0.
export DISPLAY=:0.0

# Start cursor at the top-left corner, as opposed to the default of dead-center
# (so it doesn't accidentally trigger hover styles on elements on the page)
xdotool mousemove 0 0

# Set some useful X preferences
xset s off # don't activate screensaver
xset -dpms # disable DPMS (Energy Star) features.
xset s noblank # don't blank the video device

# Set X screen background: Unicornio
sudo nitrogen --set-centered background.png

# Hide cursor afer 5 seconds of inactivity
unclutter -idle 5 -root &

# Make sure Chromium profile is marked clean, even if it crashed

# Verifica si el archivo de preferencias de chromium existe: .config/chromium/Default/
if [ -f .config/chromium/Default/Preferences ]; then
    # Existe: cat .config/chromium/Default/Preferences (en la .5 existe este archivo)
    # jq procesa el json de preferencias y se cambian exit_type y exited_cleanly
    # Se redirige la salida del comando jq a .config/chromium/Default/Preferences-clean    
    cat .config/chromium/Default/Preferences \
        | jq '.profile.exit_type = "SessionEnded" | .profile.exited_cleanly = true' \
        > .config/chromium/Default/Preferences-clean
    # Se renombra el archivo eliminando la extension -clean del nombre del archivo
    mv .config/chromium/Default/Preferences{-clean,}
fi

# Remove notes of previous sessions, if any
# Busca y elimina cualquier archivo dentro del directorio .config/chromium/ cuyo nombre comience con "Last 
find .config/chromium/ -name "Last *" -exec rm {} +

# Get URL from file (if set)
URL=""

# no parece que exista en .5: /boot/chilipie_url.txt
if [ -f /boot/chilipie_url.txt ]; then
    URL="$(head -n 1 /boot/chilipie_url.txt)"
elif [ -f /home/pi/chilipie_url.txt ]; then
    # Extrae la primera linea
    URL="$(head -n 1 /home/pi/chilipie_url.txt)"
fi


if [ -n "$URL" ]; then
    # URL no vacia: Obtiene el numero de serie de la raspberry pi
    SERIAL="$(cat /proc/cpuinfo | grep Serial | cut -d ' ' -f 2 | xargs)" # Get serial number

    # Reemplaza la variable SERIAL en la URL (si está presente) con el número de serie del dispositivo: http://example.com/?serial=$SERIAL deberia cambiar por http://example.com/?serial=10000000f9f937b8
    URL="$(echo $URL | SERIAL=$SERIAL envsubst '$SERIAL')"
fi

# Start and detach Chromium
# http://peter.sh/experiments/chromium-command-line-switches/
# Note that under matchbox, starting in full-screen without a window size doesn't behave well when you try to exit full screen (see https://unix.stackexchange.com/q/273989)
chromium-browser \
  --start-fullscreen \
  --window-position=9000,9000 \
  --disable-infobars \
  --kiosk\
  --overscroll-history-navigation=0 \
  --check-for-update-interval=1 --simulate-critical-update \ $URL &
# See https://github.com/futurice/chilipie-kiosk/issues/99#issuecomment-597119842 for 
# the need for the fishy-sounding "--check-for-update-interval=1 
# --simulate-critical-update" switches; TODO: remove when not needed
 
# Hide Chromium while it's starting/loading the page
wid=`xdotool search --sync --onlyvisible --class chromium`
xdotool windowunmap $wid
sleep 10 # give the web page time to load
xdotool windowmap $wid

# Finally, switch process to our window manager
exec matchbox-window-manager -use_titlebar no

これまではうまくいくようです。

実行時に表示されるローカルウェブサイトを変更し、google.esを表示したいJavaコードがあります。

            String url = "https://www.google.com/?hl=es";

            // Comando para abrir Chromium en modo kiosco con la URL de Google
            String command = "chromium-browser --start-fullscreen --kiosk --new-window --no-sandbox " + url;

            // Ejecutar el comando en el sistema operativo
            Process process = Runtime.getRuntime().exec(command);
            
            LogManager.getInstance().println(LogManager.INFO, "intenta ejecutar la llamada a google.es");

            
            // Capturar la salida de Chromium
            InputStream inputStream = process.getInputStream();
            BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
            
         // Capturar la salida de error de Chromium
            InputStream errorStream = process.getErrorStream();
            BufferedReader errorReader = new BufferedReader(new InputStreamReader(errorStream));

            
            String line = "";
            
            while ((line = reader.readLine()) != null) {
                LogManager.getInstance().println(LogManager.INFO, "Salida estándar: " + line);
            }
            
            while ((line = errorReader.readLine()) != null) {
                LogManager.getInstance().println(LogManager.ERROR, "Salida de error: " + line);
            }

ただし、常にエラーが発生します。

[2099:2099:0322/164415.631324:ERROR:ozone_platform_x11.cc(243)] Missing X server or $DISPLAY
03/22/2024 16:44:15 --> ERROR: [2099:2099:0322/164415.631658:ERROR:env.cc(257)] The platform failed to initialize. Exiting.

私はユーザーpiを使用してSSH経由でラズベリーパイに接続しています。 /etc/environmentを修正し、DISPLAY=:0を追加しました。 /etc/environment.d/90qt-a11y.confでも行いました。

存在する/etc/X11/Xwrapper.configallowed_users=anybodyに設定しました。

走れば所有者私は持っています:

access control enabled, only authorized clients can connect
YES:localuser:pi

私の無知のためにすべてが大丈夫に見えます。

誰かがこのエラーを解決するのを手伝ってください。

ベストアンサー1

おすすめ記事