rapp-playwright/tools/chromium-launcher.py
tegwick ccf46d8c59 Implement bounded browser service, consumer evidence and managed package
Assistant: codex
Assistant-Model: gpt-6-astra
Assistant-Session: 01a13590-a16f-7f60-be60-fd71627bc99d
2026-10-13 19:23:29 +02:00

29 lines
898 B
Python
Executable file

#!/usr/bin/python3
"""Keep the browser process group tied to its worker, even during launch/crash.
Playwright starts this launcher in a new process group. Linux PR_SET_PDEATHSIG
closes the gap before launchServer() has returned a browser PID to the service.
"""
import ctypes
import os
import signal
import subprocess
import sys
def terminate(_signal, _frame):
os.killpg(os.getpgrp(), signal.SIGKILL)
parent = os.getppid()
signal.signal(signal.SIGTERM, terminate)
signal.signal(signal.SIGINT, terminate)
libc = ctypes.CDLL(None, use_errno=True)
if libc.prctl(1, signal.SIGTERM, 0, 0, 0) != 0:
sys.exit(70)
if os.getppid() != parent or parent == 1:
terminate(None, None)
binary = os.environ['RAPP_CHROMIUM_EXECUTABLE']
# Playwright's --remote-debugging-pipe uses these inherited descriptors.
child = subprocess.Popen([binary, *sys.argv[1:]], pass_fds=(3, 4))
sys.exit(child.wait())