-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Description
Is there an existing issue for this?
- I have searched both open/closed issues, no issue already exists.
CefSharp Version
143.0.90
Operating System
Windows 11
Architecture
x86
.Net Version
.NET 4.8
Implementation
WinForms
Reproduction Steps
Description
The command line arguments from the main application process are being inherited by the CefSharp.BrowserSubprocess.exe subprocess, causing it to fail with "Invalid command-line arguments" error.
Steps to Reproduce
- Launch the application with command line arguments (e.g.,
-p "C:\path\to\file.json") - Initialize CefSharp with
Cef.Initialize() - The subprocess
CefSharp.BrowserSubprocess.exereceives the main process arguments and fails
Code Example
var settings = new CefSettings
{
BrowserSubprocessPath = @"C:\path\to\CefSharp.BrowserSubprocess.exe",
CachePath = @"%localappdata%\MyApp\Cache",
LogSeverity = LogSeverity.Info
};
settings.CefCommandLineArgs.Add("no-proxy-server", "1");
bool result = Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: null);Command Line Arguments Passed to Subprocess
When the main application is launched with: MyApp.exe -p "C:\path\to\Host.Json"
The subprocess receives:
--browser-subprocess-path=C:\path\to\CefSharp.BrowserSubprocess.exe
--no-sandbox
--lang=en-US
--log-file=C:\path\to\debug.log
--log-severity=info
--disable-features=EnableHangWatcher,GlicActorUi,LensOverlay
--disable-chrome-login-prompt
--hide-crash-restore-bubble
--disable-back-forward-cache
--no-proxy-server=1
--flag-switches-begin
--flag-switches-end
--do-not-de-elevate
-p
c:\path\to\Host.Json
The -p and file path arguments should NOT be passed to the subprocess.
Workaround Attempted
- Setting
BrowserSubprocessPathto an absolute path - Ensuring all CEF runtime files are present
- Verifying
CefSettingsconfiguration
Additional Information
- All CEF runtime files are present in the output directory
- The log file is empty (no CEF initialization errors logged)
Cef.IsInitializedreturnsnullbefore initialization and should becometrueafter successful initialization- This appears to be a regression or bug introduced in version 143.0.90
Related Issues
- Similar initialization issues: Invalid file descriptor to ICU data received. #4163, OffScreen - Browser fails to complete loading when CEF is initialized shortly before the browser is created #3850
- Command line arguments discussion: Example code/documentation for CefCommandLineArgs usage is misleading #2858
Expected behavior
Expected Behavior
The browser subprocess should only receive CEF-specific command line arguments, not the main application's command line arguments.
Actual behavior
Actual Behavior
The subprocess receives all command line arguments from the main process, including application-specific arguments like -p "Host.Json", which causes the subprocess to fail with:
Invalid command-line arguments: '-p --browser-subprocess-path=... --no-sandbox ... c:\path\to\Host.Json'
Root Cause
The issue occurs in BrowserSubprocessExecutable.h (line 64) where the subprocess calls Environment::GetCommandLineArgs(), which retrieves ALL command line arguments from the main process, not just CEF-specific ones. The CommandLineArgsDisabled property only prevents configuration via CEF settings, but doesn't prevent the subprocess from reading the main process arguments.
Note: This line (Environment::GetCommandLineArgs()) existed in version 107.1.40 but didn't cause issues because:
- The subprocess used
WcfBrowserSubprocessExecutablewithProgram.Main(string[] args)which received arguments explicitly - The subprocess was launched as a separate process with explicit arguments, not inheriting from the parent
- In version 143.0.90, the subprocess now uses
BrowserSubprocessExecutableand appears to inherit command-line arguments from the parent process, causing this regression
Workaround Attempted
- Setting
BrowserSubprocessPathto an absolute path - Setting
CommandLineArgsDisabled = trueinCefSettings(doesn't solve the issue) - Ensuring all CEF runtime files are present
- Verifying
CefSettingsconfiguration
Additional Information
- All CEF runtime files are present in the output directory
- The log file is empty (no CEF initialization errors logged)
Cef.IsInitializedreturnsnullbefore initialization and should becometrueafter successful initialization- This appears to be a regression introduced in version 143.0.90. The same code (
Environment::GetCommandLineArgs()) existed in version 107.1.40 but didn't cause issues due to different subprocess launch mechanism (WCF vs non-WCF, explicit arguments vs inherited arguments) - The subprocess should filter command line arguments and only accept CEF-specific ones
- Source code location:
packages/CefSharp.Common.143.0.90/src/CefSharp.BrowserSubprocess.Core/BrowserSubprocessExecutable.hline 64 usesEnvironment::GetCommandLineArgs()which retrieves all arguments from the main process
Regression?
No response
Known Workarounds
No response
Does this problem also occur in the CEF Sample Application
Yes using WPF/OffScreen command line args
Other information
No response