This commit is contained in:
2021-12-08 16:12:08 +00:00
parent a45468a402
commit acf816639d
3 changed files with 79 additions and 72 deletions

View File

@@ -461,79 +461,51 @@ namespace AyaNova.Biz
var lo = new LaunchOptions { Headless = true };
if (!AutoDownloadChromium)
{
lo.ExecutablePath = ServerBootConfig.AYANOVA_REPORT_RENDER_BROWSER_PATH;//"/usr/bin/chromium-browser";//this is the default path for docker based alpine dist, but maybe not others, need to make a config setting likely
// lo.Args = new string[] { "--no-sandbox" };
lo.ExecutablePath = ServerBootConfig.AYANOVA_REPORT_RENDER_BROWSER_PATH;
/*
troubleshooting links:
https://developers.google.com/web/tools/puppeteer/troubleshooting
Note: plenty of zombie process issues in regular puppeteer as well
These links might be worth looking at in future if diagnosing other issues:
https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#running-on-alpine
https://github.com/puppeteer/puppeteer/issues/1825
const chromeFlags = [
'--headless',
'--no-sandbox',
"--disable-gpu",
"--single-process",
"--no-zygote"
]
troubleshooting links:
https://developers.google.com/web/tools/puppeteer/troubleshooting
These links might be worth looking at in future if diagnosing other issues:
https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#running-on-alpine
https://github.com/puppeteer/puppeteer/issues/1825
const chromeFlags = [
'--headless',
'--no-sandbox',
"--disable-gpu",
"--single-process",
"--no-zygote"
]
*/
//was using this for a long period of time
//lo.Args = new string[] { "--disable-dev-shm-usage --no-sandbox --disable-gpu --single-process --no-zygote " };
//however chrome may be problematic on linux, I'm seeing issues under load testing where it freezes out the droplet at 100% cpu and ram and it's
//chrome processes piling up all churning away so experimenting with resolutions
//this guy says single process should NOT be used as recommended by Google
//and so far in testing I see no reason to doubt him so removed it
//https://github.com/puppeteer/puppeteer/issues/1825#issuecomment-792817748
//testing
lo.Args = new string[] { $"--disable-dev-shm-usage --no-sandbox --disable-gpu --no-zygote " };
}
else
{
//WINDOWS ONLY
log.LogDebug($"Windows: Calling browserFetcher download async now:");
await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultChromiumRevision);
// //TRY TO FORCE LANGUAGE THROUGH STARTUP PARAMETER
// lo.Args = new string[] { $"{LaunchParamLanguage}" };
}
//Set Chromium args
var DefaultArgs = "--disable-dev-shm-usage --no-sandbox --disable-gpu --no-zygote ";
if (!string.IsNullOrWhiteSpace(ServerBootConfig.AYANOVA_REPORT_RENDER_BROWSER_PARAMS))
{
log.LogDebug($"AYANOVA_REPORT_RENDER_BROWSER_PARAMS will be used: {ServerBootConfig.AYANOVA_REPORT_RENDER_BROWSER_PARAMS}");
lo.Args = new string[] { $"{ServerBootConfig.AYANOVA_REPORT_RENDER_BROWSER_PARAMS}" };// AYANOVA_REPORT_RENDER_BROWSER_PARAMS
}
else
{
log.LogDebug($"AYANOVA_REPORT_RENDER_BROWSER_PARAMS not set, using defaults '{DefaultArgs}'");
lo.Args = new string[] { DefaultArgs };
}
System.Text.StringBuilder PageLog = new System.Text.StringBuilder();
//API DOCS http://www.puppeteersharp.com/api/index.html
log.LogDebug($"Launching headless Browser now:");
using (var browser = await Puppeteer.LaunchAsync(lo))
using (var page = await browser.NewPageAsync())
// using (var page = (await browser.PagesAsync()).First())//for language setting version
{
//track this process so it can be cancelled if it times out
ReportRenderManager.AddProcess(browser.Process.Id);
// //========================================
// //TRY TO FORCE LANGUAGE ON ALL PLATFORMS
// var JScriptOverrideLanguage = "Object.defineProperty(navigator, 'language', {get: function() {return '" + ClientLanguage + "';}});Object.defineProperty(navigator, 'languages', {get: function() {return ['" + ClientLanguage + "'];}});";
// await page.EvaluateFunctionOnNewDocumentAsync(JScriptOverrideLanguage);
// await page.GoToAsync("about:blank");
// var hdrs = new Dictionary<string, string>();
// hdrs.Add("Accept-Language", ClientLanguage);
// await page.SetExtraHttpHeadersAsync(hdrs);
// //=========================================
page.DefaultTimeout = 0;//infinite timeout as we are controlling how long the process can live for with the reportprocessmanager
try
{

View File

@@ -79,6 +79,9 @@ namespace AyaNova.Util
//REPORT RENDERING BROWSER PATH (if not set then will attempt to auto-download on first render)
internal static string AYANOVA_REPORT_RENDER_BROWSER_PATH { get; set; }
//REPORT RENDERING BROWSER PARAMS
internal static string AYANOVA_REPORT_RENDER_BROWSER_PARAMS { get; set; }
//LOGGING
internal static string AYANOVA_LOG_PATH { get; set; }
@@ -169,9 +172,12 @@ namespace AyaNova.Util
AYANOVA_SET_SUPERUSER_PW = config.GetValue<string>("AYANOVA_SET_SUPERUSER_PW");
//REPORT RENDERING
//RENDER ENGINE PATH
AYANOVA_REPORT_RENDER_BROWSER_PATH = ActualFullPath(config.GetValue<string>("AYANOVA_REPORT_RENDER_BROWSER_PATH"));
//RENDER ENGINE PARAMS
AYANOVA_REPORT_RENDER_BROWSER_PARAMS = config.GetValue<string>("AYANOVA_REPORT_RENDER_BROWSER_PARAMS");
//PROCESS CONTROL
int? nTemp = config.GetValue<int?>("AYANOVA_REPORT_RENDERING_TIMEOUT");