FROM node:22-alpine

RUN apk add --no-cache \
    # Playwright deps
    nss \
    freetype \
    freetype-dev \
    harfbuzz \
    ca-certificates \
    ttf-freefont \
    # Firefox deps
    libstdc++ \
    dbus-glib \
    # Xvfb for headless mode
    xvfb \
    xauth \
    # General
    wget \
    curl \
    yt-dlp

# Install Camofox browser globally
RUN npm install -g @askjo/camofox-browser@1.13.1

# Install Playwright Firefox
RUN npx playwright install firefox

EXPOSE 9377

ENV CAMOFOX_PORT=9377
ENV CAMOFOX_REWRITE_LOOPBACK_URLS=true
ENV CAMOFOX_LOOPBACK_HOST_ALIAS=host.docker.internal
ENV DISPLAY=:99

CMD Xvfb :99 -screen 0 1920x1080x24 & sleep 0.5 && camofox-browser
