0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Raspberry Pi起動時にChromiumを自動起動させる方法

Posted at

Raspberry Pi起動時にChromiumを自動起動させる方法 という昔の記事の最新版です。

前提:Raspberry Pi 3B+/Raspberry Pi OS 32bit(最新、Wayland+labwcのまま)

方針:
• デスクトップは Wayland+labwc を維持
• Chromium だけ X11 バックエンドで起動(--ozone-platform=x11)
• unclutter で 一定時間未操作ならカーソル非表示/動かせば再表示
• 画面の自動スリープは GUI の Screen Blanking を OFF

1) 必要パッケージの導入

bash
$ sudo apt update
$ sudo apt install -y chromium unclutter

2) 自動ログイン(まだなら)

bash
$ sudo raspi-config

・System Options → S6 Auto Login → Desktop Autologin を選択 → 終了

3) 起動スクリプトを作成(nanoで新規)

bash
$ mkdir -p ~/kiosk
$ nano ~/kiosk/start_browser.sh

↓ この内容を丸ごと貼り付けて保存(Ctrl+O → Enter → Ctrl+X)

start_browser.sh
#!/bin/bash
# ====== 設定 ======
URL="https://YOUR_URL_HERE"   # ←開きたいURLに変更
DELAY_SEC=2                   # 起動直後の安定待ち(必要に応じ2→3へ)
LOG="/home/pi/kiosk/kiosk.log"
# ==================

{
  echo "==== kiosk start $(date) ===="
  echo "URL=$URL"
} >> "$LOG" 2>&1

sleep "${DELAY_SEC}"

# Chromium 実体の検出(環境で 'chromium' または 'chromium-browser')
BROWSER="$(command -v chromium || command -v chromium-browser)"
if [ -z "$BROWSER" ]; then
  echo "Chromium not found. Try: sudo apt install chromium" >> "$LOG" 2>&1
  exit 1
fi

# ★ Waylandセッションのまま、Chromiumのみ X11 バックエンドで起動
exec "$BROWSER" \
  --enable-features=UseOzonePlatform \
  --ozone-platform=x11 \
  --kiosk \
  --start-fullscreen \
  --no-first-run \
  --disable-session-crashed-bubble \
  --disable-infobars \
  --noerrdialogs \
  "$URL" >> "$LOG" 2>&1

実行権限を付与:

bash
$ chmod +x ~/kiosk/start_browser.sh

手動テスト(起動確認・閉じる時は Alt+F4):

bash
$ bash ~/kiosk/start_browser.sh

4) labwc の自動起動ファイルを作成(nanoで新規)

bash
$ mkdir -p ~/.config/labwc
$ nano ~/.config/labwc/autostart
autostart
↓ この内容を丸ごと貼り付けて保存

#!/bin/sh
# 少し遅らせてから起動(競合回避)
sleep 1

# ★ 一定時間アイドルでカーソルを隠す。動かせば復活。
#   -idle 1.0 : 1秒未操作で非表示(0.5〜3.0など好みで)
#   -jitter 3 : 3px以内の微小揺れを無視(値を増やすと安定)
unclutter -idle 1.0 -jitter 3 -root &

# ★ Chromium(X11 バックエンド指定)を起動
/home/pi/kiosk/start_browser.sh &

実行権限を付与:

bash
$ chmod +x ~/.config/labwc/autostart

5) 画面の自動スリープを無効化(GUIで確実)

•デスクトップ右上 → Raspberry Pi Configuration
•Display → Screen Blanking: Disabled に変更 → 再起動を促されたら従う

(参考:確認)

bash
$ pgrep -a swayidle || echo "OK: swayidle not running"

6) 最終テスト

bash
$ sudo reboot

期待動作:
•自動ログイン → 数秒後に Chromium がフルスクリーンで URL 表示
•未操作でカーソル非表示、動かすと復活
•放置しても 画面が暗転しない

うまくいかない時のチェック

•Chromium が見つからない/起動しない:

bash
$ which chromium || which chromium-browser
$ chromium --version || chromium-browser --version

出なければ再インストール:

bash
sudo apt install -y chromium

• unclutter が動いているか:

bash
$ pgrep -a unclutter

出ない場合:~/.config/labwc/autostart の 先頭 #!/bin/sh・行末 &・chmod +x を再確認。
起動競合が疑わしければ sleep 1 を 2〜3 に。

  • 起動順で真っ黒になる等:
    • ~/.config/labwc/autostart の sleep を増やす
    • ~/kiosk/start_browser.sh の DELAY_SEC を 3〜4 に
  • ログで原因を追う:
bash
$ tail -n 80 ~/kiosk/kiosk.log

よくある微調整(お好み)

  • カーソルの消えるまでの時間:
    • 早く:unclutter -idle 0.5
    • 遅く:unclutter -idle 2.0 や 3.0
  • 微小揺れ対策:-jitter 3 → 4〜8 へ

後片付け(元に戻す場合)

bash
$ rm -f ~/.config/labwc/autostart
$ rm -f ~/kiosk/start_browser.sh
$ rmdir --ignore-fail-on-non-empty ~/kiosk
$ sudo apt remove -y unclutter   # 任意
# Chromiumも消すなら:
# $ sudo apt remove -y chromium chromium-browser

この手順のまま進めればOK。
URL を確定したら ~/kiosk/start_browser.sh の URL= を書き換えてください。
エラーが出たら、下の3つを貼ってくれれば即特定できます:

bash
$ cat ~/.config/labwc/autostart
$ cat ~/kiosk/start_browser.sh
$ tail -n 80 ~/kiosk/kiosk.log
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?