#!/usr/bin/env bash
# Run "$@" with an X DISPLAY available — passes through if one is already set,
# otherwise wraps in xvfb-run. Needed because nix-pinned headless chromium on
# a true-headless Linux box silently no-ops page.fill on plain HTML inputs and
# crashes the renderer on some pages; giving it a real X display avoids both.
# On Mac this is a no-op (xvfb-run isn't on PATH and Apple's chromium doesn't
# need it).
#
# Part of the @norskvideo/ctl-dev-kit doc-guide toolchain. A product copies this
# to its own scripts/ (it must be a repo-local executable the package.json guide
# scripts can invoke); the dev-kit is the canonical source.

set -euo pipefail

if [ -n "${DISPLAY:-}" ] || ! command -v xvfb-run >/dev/null 2>&1; then
  exec "$@"
fi

exec xvfb-run -a --server-args="-screen 0 1280x720x24" "$@"
