#!/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())