@@ -12,13 +12,36 @@ namespace Codeuctivity.HtmlRenderer
1212 /// </summary>
1313 public class Renderer : IAsyncDisposable , IDisposable
1414 {
15+ /// <summary>
16+ /// Ctor
17+ /// </summary>
18+ /// <param name="customChromiumArgs"></param>
19+ public Renderer ( string ? customChromiumArgs )
20+ {
21+ if ( customChromiumArgs == null )
22+ {
23+ LaunchOptions = SystemSpecificConfig ( ) ;
24+ }
25+ else
26+ {
27+ LaunchOptions = new LaunchOptions ( ) { Args = new [ ] { customChromiumArgs } } ;
28+ }
29+ }
30+
1531 /// <summary>
1632 /// Ctor
1733 /// </summary>
1834 /// <param name="launchOptions"></param>
19- public Renderer ( string ? launchOptions = null )
35+ public Renderer ( LaunchOptions ? launchOptions = null )
2036 {
21- LaunchOptions = launchOptions ;
37+ if ( launchOptions == null )
38+ {
39+ LaunchOptions = SystemSpecificConfig ( ) ;
40+ }
41+ else
42+ {
43+ LaunchOptions = launchOptions ;
44+ }
2245 }
2346
2447 private IBrowser Browser { get ; set ; } = default ! ;
@@ -29,7 +52,7 @@ public Renderer(string? launchOptions = null)
2952 /// </summary>
3053 public BrowserFetcher BrowserFetcher { get ; private set ; } = default ! ;
3154
32- private string ? LaunchOptions { get ; }
55+ private LaunchOptions LaunchOptions { get ; }
3356
3457 /// <summary>
3558 /// Call CreateAsync before using ConvertHtmlTo*
@@ -45,9 +68,20 @@ public static Task<Renderer> CreateAsync()
4568 /// Call CreateAsync before using ConvertHtmlTo*, accepts custom BrowserFetcher and custom chromium launch options
4669 /// </summary>
4770 /// <param name="browserFetcher"></param>
48- /// <param name="launchOptions ">Adds launch options to chromium</param>
71+ /// <param name="chromiumArguments ">Adds custom arguments to chromium</param>
4972 /// <returns></returns>
50- public static Task < Renderer > CreateAsync ( BrowserFetcher browserFetcher , string ? launchOptions = null )
73+ public static Task < Renderer > CreateAsync ( BrowserFetcher browserFetcher , string chromiumArguments )
74+ {
75+ return CreateAsync ( browserFetcher , new LaunchOptions ( ) { Args = new [ ] { chromiumArguments } } ) ;
76+ }
77+
78+ /// <summary>
79+ /// Call CreateAsync before using ConvertHtmlTo*, accepts custom BrowserFetcher and custom chromium launch options
80+ /// </summary>
81+ /// <param name="browserFetcher"></param>
82+ /// <param name="launchOptions">Adds launch options to puppeteer</param>
83+ /// <returns></returns>
84+ public static Task < Renderer > CreateAsync ( BrowserFetcher browserFetcher , LaunchOptions ? launchOptions = null )
5185 {
5286 var html2Pdf = new Renderer ( launchOptions ) ;
5387 return html2Pdf . InitializeAsync ( browserFetcher ) ;
@@ -59,18 +93,17 @@ private async Task<Renderer> InitializeAsync(BrowserFetcher browserFetcher)
5993 BrowserFetcher . DownloadProgressChanged += DownloadProgressChanged ;
6094
6195 _ = await BrowserFetcher . DownloadAsync ( BrowserFetcher . DefaultChromiumRevision ?? string . Empty ) . ConfigureAwait ( false ) ;
62- Browser = await Puppeteer . LaunchAsync ( SystemSpecificConfig ( ) ) . ConfigureAwait ( false ) ;
96+ Browser = await Puppeteer . LaunchAsync ( LaunchOptions ) . ConfigureAwait ( false ) ;
6397 return this ;
6498 }
6599
66100 private LaunchOptions SystemSpecificConfig ( )
67101 {
68- if ( string . IsNullOrEmpty ( LaunchOptions ) && ( IsRunningOnWslOrAzure ( ) || IsRunningOnAzureLinux ( ) ) )
102+ if ( IsRunningOnWslOrAzure ( ) || IsRunningOnAzureLinux ( ) )
69103 {
70104 return new LaunchOptions { Headless = true , Args = new string [ ] { "--no-sandbox" } } ;
71105 }
72-
73- return new LaunchOptions { Headless = true } ;
106+ return new LaunchOptions ( ) ;
74107 }
75108
76109 private static bool IsRunningOnAzureLinux ( )
0 commit comments