Skip to content

Commit b943426

Browse files
BenDuguid-MRMMaxMelcher
authored andcommitted
#121 Use local temp folder to download chromium headless
1 parent 7a5ab99 commit b943426

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

AzureDevOps.WikiPDFExport/Options.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public class Options
5959
[Option("mermaidjs-path", Required = false, HelpText = "Path of the mermaid.js file. It'll be used if mermaid diagrams support is turned on (-m/--mermaid). If not specified, 'https://cdnjs.cloudflare.com/ajax/libs/mermaid/8.6.4/mermaid.min.js' will be used.")]
6060
public string MermaidJsPath { get; set; }
6161

62-
[Option("chrome-path", Required = false, HelpText = "Path of the chrome or chromium executable. It'll be used if mermaid diagrams support is turned on (-m/--mermaid). If not specified, a headless version will be downloaded.")]
62+
[Option("chrome-path", Required = false, HelpText = "Path of the chrome or chromium executable. If not specified, a headless version will be downloaded.")]
6363
public string ChromeExecutablePath { get; set; }
6464

6565
[Option("chrome-timeout", Required = false, HelpText = "Timeout for Chrome operations in seconds (default 30 seconds).", Default = 30)]

AzureDevOps.WikiPDFExport/PDFGenerator.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,28 @@ internal async Task<string> ConvertHTMLToPDFAsync(SelfDeletingTemporaryFile temp
3131
output = Path.Combine(Directory.GetCurrentDirectory(), "export.pdf");
3232
}
3333

34-
if (string.IsNullOrEmpty(_options.ChromeExecutablePath))
34+
string chromePath = _options.ChromeExecutablePath;
35+
36+
if (string.IsNullOrEmpty(chromePath))
3537
{
36-
_logger.Log("No Chrome path defined, downloading...");
37-
_ = await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultChromiumRevision);
38+
string tempFolder = Path.Join(Path.GetTempPath(), "AzureDevOpsWikiExporter");
39+
40+
_logger.Log("No Chrome path defined, downloading to user temp...");
41+
42+
var fetcherOptions = new BrowserFetcherOptions
43+
{
44+
Path = tempFolder,
45+
};
46+
47+
var info = await new BrowserFetcher(fetcherOptions).DownloadAsync(BrowserFetcher.DefaultChromiumRevision);
48+
chromePath = info.ExecutablePath;
49+
3850
_logger.Log("Chrome ready.");
3951
}
4052

4153
var launchOptions = new LaunchOptions
4254
{
43-
ExecutablePath = _options.ChromeExecutablePath ?? string.Empty,
55+
ExecutablePath = chromePath,
4456
Headless = true, //set to false for easier debugging
4557
Args = new[] { "--no-sandbox", "--single-process" }, //required to launch in linux
4658
Devtools = false,

0 commit comments

Comments
 (0)