case 4690 - report browser: launch chrome-headless-shell; writable config/cache folders for the browser; Ubuntu 24.04 droplet results
Full Chrome 155 would not start under a Linux service user with no writable home (chrome_crashpad_handler: --database is required). chrome-headless-shell starts, and measured on a 1 GB droplet is 3-4x faster and smaller per render. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -795,8 +795,11 @@ What could be the issue here?
|
||||
|
||||
//case 4586
|
||||
//puppeteer has gone chrome dev by default and so does puppeteersharp which tests ok so I'm going to allow the default
|
||||
//this means the files go into Chrome and ChromeHeadlessShell folders, under the data path (not beside the app, see ServerBootConfig)
|
||||
var FetcherOptions = new BrowserFetcherOptions();
|
||||
//this means the files go into a ChromeHeadlessShell folder, under the data path (not beside the app, see ServerBootConfig)
|
||||
//chrome-headless-shell, not full Chrome: it is Chrome's headless-only build for automation and PDF printing.
|
||||
//Measured on a 1GB Ubuntu droplet printing a report-sized page: about 1s and 620MB vs 4.5s and 1.6GB for full Chrome,
|
||||
//and a browser is started for every report render. Full Chrome also failed to start under a service user with no writable home
|
||||
var FetcherOptions = new BrowserFetcherOptions { Browser = SupportedBrowser.ChromeHeadlessShell };
|
||||
if (!string.IsNullOrWhiteSpace(ServerBootConfig.REPORT_RENDER_BROWSER_DOWNLOAD_PATH))
|
||||
FetcherOptions.Path = ServerBootConfig.REPORT_RENDER_BROWSER_DOWNLOAD_PATH;
|
||||
try
|
||||
@@ -804,6 +807,7 @@ What could be the issue here?
|
||||
var InstalledBrowser = await new BrowserFetcher(FetcherOptions).DownloadAsync();
|
||||
//launch exactly what was downloaded, otherwise Puppeteer looks in its default folder beside the app
|
||||
lo.ExecutablePath = InstalledBrowser.GetExecutablePath();
|
||||
lo.HeadlessMode = HeadlessMode.Shell;
|
||||
log.LogDebug($"Report browser: {lo.ExecutablePath}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -856,6 +860,27 @@ What could be the issue here?
|
||||
{
|
||||
lo.Args = lo.Args.Append($"--lang={ServerLanguage}").ToArray();
|
||||
}
|
||||
//Chrome keeps config and crash-reporter files under the user's home folder and fails to start when it isn't writable,
|
||||
//as for a Linux service user like www-data (home /var/www). Point it at folders we own instead; harmless on Windows.
|
||||
//Matters mostly for a full Chrome given in AYANOVA_REPORT_RENDER_BROWSER_PATH, chrome-headless-shell starts without them
|
||||
var BrowserWorkFolder = Path.Combine(
|
||||
string.IsNullOrWhiteSpace(ServerBootConfig.REPORT_RENDER_BROWSER_DOWNLOAD_PATH)
|
||||
? ServerBootConfig.AYANOVA_TEMP_FILES_PATH
|
||||
: ServerBootConfig.REPORT_RENDER_BROWSER_DOWNLOAD_PATH,
|
||||
"browser-home"
|
||||
);
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(Path.Combine(BrowserWorkFolder, "config"));
|
||||
Directory.CreateDirectory(Path.Combine(BrowserWorkFolder, "cache"));
|
||||
lo.Env["XDG_CONFIG_HOME"] = Path.Combine(BrowserWorkFolder, "config");
|
||||
lo.Env["XDG_CACHE_HOME"] = Path.Combine(BrowserWorkFolder, "cache");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//not fatal, the launch below reports any real problem
|
||||
log.LogWarning(ex, $"Could not create report browser work folders under {BrowserWorkFolder}");
|
||||
}
|
||||
log.LogDebug($"Report browser launch arguments: '{string.Join(" ", lo.Args)}'");
|
||||
System.Text.StringBuilder PageLog = new System.Text.StringBuilder();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user