106 lines
4.5 KiB
Bash
Executable File
106 lines
4.5 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
declare -r entropy=$(xxd -l16 -ps /dev/urandom)
|
|
|
|
#declare -r CHROME_DIR="${HOME}/.chromeDevTemp"
|
|
declare -r chrome_dir="/tmp/chrome/${entropy}"
|
|
|
|
# See flags available and documentation:
|
|
# https://chromium.googlesource.com/chromium/src/+/HEAD/chrome/common/chrome_switches.cc
|
|
# https://github.com/GoogleChrome/chrome-launcher/blob/main/docs/chrome-flags-for-tools.md
|
|
# https://peter.sh/experiments/chromium-command-line-switches/
|
|
|
|
# Seed the profile with DevTools preferences before Chrome starts.
|
|
# This sets: dock position = bottom, default panel = network.
|
|
# Chrome stores these in <user-data-dir>/Default/Preferences.
|
|
seed_devtools_preferences() {
|
|
local prefs='{"devtools":{"preferences":{"currentDockState":"\"bottom\"","panel-selected-tab":"\"network\""}}}'
|
|
|
|
# Seed both Default and Guest Profile — Chrome uses Guest Profile when
|
|
# launched with --guest, and Default otherwise.
|
|
for profile_name in "Default" "Guest Profile"; do
|
|
local prefs_dir="${chrome_dir}/${profile_name}"
|
|
mkdir -p "${prefs_dir}"
|
|
echo "${prefs}" > "${prefs_dir}/Preferences"
|
|
done
|
|
}
|
|
|
|
# TODO(bt): Math to determine better window placement.
|
|
|
|
# Flags reference:
|
|
# --auto-open-devtools-for-tabs Open DevTools automatically for every tab on launch.
|
|
# Dock position and default panel are set via seeded
|
|
# preferences (see seed_devtools_preferences above).
|
|
# --allow-running-insecure-content Allow HTTPS pages to load HTTP resources (mixed content).
|
|
# --disable-features=ChromeLabs, Disable Chrome Labs experiments UI and the
|
|
# DefaultBrowserPrompt feature-flag-based default browser prompt.
|
|
# --disable-site-isolation-trials Disable site isolation (allows cross-origin iframes
|
|
# to share process, useful for local dev).
|
|
# --disable-web-security Disable same-origin policy. Required for local dev
|
|
# where the frontend talks to a different-origin API.
|
|
# --ignore-certificate-errors Accept self-signed / invalid TLS certs.
|
|
# --no-default-browser-check Skip the "set as default browser" check on startup.
|
|
# --no-first-run Suppress the "Welcome to Google Chrome" first-run
|
|
# dialog (default browser checkbox, crash reporting, etc.).
|
|
# --install-autogenerated-theme Set a custom window color so the dev browser is
|
|
# visually distinct from your normal Chrome.
|
|
# --unsafely-treat-insecure-origin-as-secure
|
|
# Treat the given HTTP origin as secure. Required for
|
|
# APIs like getUserMedia() / navigator.mediaDevices
|
|
# which need a "secure context".
|
|
# --user-data-dir Use a throwaway profile directory so dev sessions
|
|
# don't pollute your real Chrome profile.
|
|
# --guest (Mac only) Launch in guest mode — no Google login screen.
|
|
# --window-position / --window-size Place the dev window predictably on screen.
|
|
|
|
launch_linux() {
|
|
seed_devtools_preferences
|
|
chromium \
|
|
--auto-open-devtools-for-tabs \
|
|
--allow-running-insecure-content \
|
|
--disable-features=ChromeLabs,DefaultBrowserPrompt \
|
|
--disable-site-isolation-trials \
|
|
--disable-web-security \
|
|
--ignore-certificate-errors \
|
|
--no-default-browser-check \
|
|
--no-first-run \
|
|
--install-autogenerated-theme="100,150,255" \
|
|
--unsafely-treat-insecure-origin-as-secure="http://localhost:5173" \
|
|
--user-data-dir="${chrome_dir}" \
|
|
--window-position=1200,300 \
|
|
--window-size=1500,1700 \
|
|
http://localhost:5173
|
|
}
|
|
|
|
launch_mac() {
|
|
seed_devtools_preferences
|
|
open -na "Google Chrome" --args \
|
|
--auto-open-devtools-for-tabs \
|
|
--disable-features=ChromeLabs,DefaultBrowserPrompt \
|
|
--disable-site-isolation-trials \
|
|
--disable-web-security \
|
|
--ignore-certificate-errors \
|
|
--no-default-browser-check \
|
|
--no-first-run \
|
|
--install-autogenerated-theme="100,150,255" \
|
|
--unsafely-treat-insecure-origin-as-secure="http://localhost:5173" \
|
|
--user-data-dir="${chrome_dir}" \
|
|
--window-position=1200,300 \
|
|
--window-size=1500,1700 \
|
|
--guest \
|
|
http://localhost:5173
|
|
}
|
|
|
|
case $OSTYPE in
|
|
linux*)
|
|
launch_linux
|
|
;;
|
|
darwin*)
|
|
launch_mac
|
|
;;
|
|
*)
|
|
echo "Unknown OS"
|
|
;;
|
|
esac
|
|
|