Skip to content

Command line arguments inherited by BrowserSubprocess in CefSharp 143.0.90 #5207

@mteneglio

Description

@mteneglio

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

  1. Launch the application with command line arguments (e.g., -p "C:\path\to\file.json")
  2. Initialize CefSharp with Cef.Initialize()
  3. The subprocess CefSharp.BrowserSubprocess.exe receives 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 BrowserSubprocessPath to an absolute path
  • Ensuring all CEF runtime files are present
  • Verifying CefSettings configuration

Additional Information

  • All CEF runtime files are present in the output directory
  • The log file is empty (no CEF initialization errors logged)
  • Cef.IsInitialized returns null before initialization and should become true after successful initialization
  • This appears to be a regression or bug introduced in version 143.0.90

Related Issues

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 WcfBrowserSubprocessExecutable with Program.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 BrowserSubprocessExecutable and appears to inherit command-line arguments from the parent process, causing this regression

Workaround Attempted

  • Setting BrowserSubprocessPath to an absolute path
  • Setting CommandLineArgsDisabled = true in CefSettings (doesn't solve the issue)
  • Ensuring all CEF runtime files are present
  • Verifying CefSettings configuration

Additional Information

  • All CEF runtime files are present in the output directory
  • The log file is empty (no CEF initialization errors logged)
  • Cef.IsInitialized returns null before initialization and should become true after 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.h line 64 uses Environment::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

Metadata

Metadata

Assignees

No one assigned

    Labels

    upstreamThese issues require fixing in the Chromium Embedded Framework(CEF) or Chromium.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions