Skip to content

Commit 36a45c1

Browse files
linesightclaude
andcommitted
Pass all switches in argv to CefMainArgs on Linux
OnBeforeChildProcessLaunch only delivers switches to child processes. Switches like --in-process-gpu and --single-process must be in the browser process's own command line to take effect; without them CEF still spawns a separate GPU/renderer subprocess that fails descriptor lookup 7 in --no-sandbox mode. Build a complete argv array from g_commandLineSwitches (which is populated before CefMainArgs is constructed) and pass it to the CefMainArgs(argc, argv) constructor so the browser process CommandLine is initialised with all user-supplied flags. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent dfa9e40 commit 36a45c1

1 file changed

Lines changed: 25 additions & 7 deletions

File tree

src/cefpython.pyx

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -577,13 +577,29 @@ def Initialize(applicationSettings=None, commandLineSwitches=None, **kwargs):
577577
cdef HINSTANCE hInstance = GetModuleHandle(NULL)
578578
cdef CefMainArgs cefMainArgs = CefMainArgs(hInstance)
579579
ELIF UNAME_SYSNAME == "Linux":
580-
# Pass argv[0] = Python executable so Chromium's CommandLine is
581-
# initialized with a valid program name. CEF 146 relies on this for
582-
# correct IPC channel bootstrap in subprocesses (global descriptor 7).
583-
cdef bytes _cefMainArgv0 = sys.executable.encode('utf-8')
584-
cdef char* _cefMainArgv0Ptr = _cefMainArgv0
585-
cdef char** _cefMainArgv = &_cefMainArgv0Ptr
586-
cdef CefMainArgs cefMainArgs = CefMainArgs(1, _cefMainArgv)
580+
# Build a complete argv so the browser process sees all switches.
581+
# OnBeforeChildProcessLaunch only reaches child processes; switches
582+
# like --in-process-gpu and --single-process must be in the browser
583+
# process's own command line to take effect.
584+
_cefMainArgvPyList = [sys.executable.encode('utf-8')]
585+
for _cefArgK, _cefArgV in g_commandLineSwitches.items():
586+
if _cefArgV:
587+
_cefMainArgvPyList.append(
588+
("--{}={}".format(_cefArgK, _cefArgV)).encode('utf-8'))
589+
else:
590+
_cefMainArgvPyList.append(
591+
("--{}".format(_cefArgK)).encode('utf-8'))
592+
cdef int _cefMainArgc = len(_cefMainArgvPyList)
593+
cdef char** _cefMainArgvC = \
594+
<char**>malloc(_cefMainArgc * sizeof(char*))
595+
cdef bytes _cefMainArgvItem
596+
cdef int _cefMainArgvI
597+
for _cefMainArgvI in range(_cefMainArgc):
598+
_cefMainArgvItem = _cefMainArgvPyList[_cefMainArgvI]
599+
_cefMainArgvC[_cefMainArgvI] = _cefMainArgvItem
600+
cdef CefMainArgs cefMainArgs = CefMainArgs(_cefMainArgc, _cefMainArgvC)
601+
# _cefMainArgvPyList keeps the bytes alive; freed below after
602+
# CefInitialize() has processed the command line.
587603
ELIF UNAME_SYSNAME == "Darwin":
588604
# TODO: use the CefMainArgs(int argc, char** argv) constructor.
589605
cdef CefMainArgs cefMainArgs
@@ -616,6 +632,8 @@ def Initialize(applicationSettings=None, commandLineSwitches=None, **kwargs):
616632
cdef cpp_bool ret
617633
with nogil:
618634
ret = CefInitialize(cefMainArgs, cefApplicationSettings, cefApp, NULL)
635+
IF UNAME_SYSNAME == "Linux":
636+
free(_cefMainArgvC)
619637

620638
global g_cef_initialized
621639
g_cef_initialized = True

0 commit comments

Comments
 (0)