From dd81962704848d2f7134b5800fb7076ec367c7b4 Mon Sep 17 00:00:00 2001 From: Nigel Gutzmann Date: Mon, 26 Oct 2026 17:01:02 -0700 Subject: [PATCH] fix: do not crash in headless mode before the package is loaded (#8392) Since Chromium 151, headless startup on Linux and macOS calls chrome::GetDefaultUserDataDirectory() from ChromeMain(), when no --user-data-dir is given, to place its temporary profile. That runs before ChromeMainDelegate::BasicStartupComplete() calls nw::InitNWPackage(), so nw::package() is still null and the patched path functions crashed dereferencing it. Fall back to "nwjs", the default Package::GetName() name, when the package is not loaded yet, as the Windows version already does. Co-Authored-By: Claude Opus 5.5 --- chrome/common/chrome_paths_linux.cc | 7 +++++-- chrome/common/chrome_paths_mac.mm | 6 +++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/chrome/common/chrome_paths_linux.cc b/chrome/common/chrome_paths_linux.cc index f76296d8bbe6a..53b22dc4917fb 100644 --- a/chrome/common/chrome_paths_linux.cc +++ b/chrome/common/chrome_paths_linux.cc @@ -97,10 +97,13 @@ bool GetDefaultUserDataDirectory(base::FilePath* result) { #elif 0 //BUILDFLAG(GOOGLE_CHROME_BRANDING) std::string data_dir_basename = "google-chrome"; #else - std::string data_dir_basename = nw::package()->GetName(); + // Headless mode asks for this path from ChromeMain(), before + // ChromeMainDelegate::BasicStartupComplete() has loaded the package. + nw::Package* package = nw::package(); + std::string data_dir_basename = package ? package->GetName() : "nwjs"; #endif - *result = config_dir.Append(nw::package()->GetName()); + *result = config_dir.Append(data_dir_basename); //*result = config_dir.Append(data_dir_basename + GetChannelSuffixForDataDir()); return true; } diff --git a/chrome/common/chrome_paths_mac.mm b/chrome/common/chrome_paths_mac.mm index de1ea50c045ef..53702a34c5d49 100644 --- a/chrome/common/chrome_paths_mac.mm +++ b/chrome/common/chrome_paths_mac.mm @@ -88,7 +88,11 @@ bool GetDefaultUserDataDirectoryForProduct(const std::string& product_dir, namespace chrome { bool GetDefaultUserDataDirectory(base::FilePath* result) { - return GetDefaultUserDataDirectoryForProduct(nw::package()->GetName(), result); + // Headless mode asks for this path from ChromeMain(), before + // ChromeMainDelegate::BasicStartupComplete() has loaded the package. + nw::Package* package = nw::package(); + return GetDefaultUserDataDirectoryForProduct( + package ? package->GetName() : "nwjs", result); } bool GetUserDocumentsDirectory(base::FilePath* result) {