@@ -12,13 +12,36 @@ namespace Codeuctivity.HtmlRenderer
12
12
/// </summary>
13
13
public class Renderer : IAsyncDisposable , IDisposable
14
14
{
15
+ /// <summary>
16
+ /// Ctor
17
+ /// </summary>
18
+ /// <param name="customChromeiumArgs"></param>
19
+ public Renderer ( string ? customChromeiumArgs )
20
+ {
21
+ if ( customChromeiumArgs == null )
22
+ {
23
+ LaunchOptions = SystemSpecificConfig ( ) ;
24
+ }
25
+ else
26
+ {
27
+ LaunchOptions = new LaunchOptions ( ) { Args = new [ ] { customChromeiumArgs } } ;
28
+ }
29
+ }
30
+
15
31
/// <summary>
16
32
/// Ctor
17
33
/// </summary>
18
34
/// <param name="launchOptions"></param>
19
- public Renderer ( string ? launchOptions = null )
35
+ public Renderer ( LaunchOptions ? launchOptions = null )
20
36
{
21
- LaunchOptions = launchOptions ;
37
+ if ( launchOptions == null )
38
+ {
39
+ LaunchOptions = SystemSpecificConfig ( ) ;
40
+ }
41
+ else
42
+ {
43
+ LaunchOptions = launchOptions ;
44
+ }
22
45
}
23
46
24
47
private IBrowser Browser { get ; set ; } = default ! ;
@@ -29,7 +52,7 @@ public Renderer(string? launchOptions = null)
29
52
/// </summary>
30
53
public BrowserFetcher BrowserFetcher { get ; private set ; } = default ! ;
31
54
32
- private string ? LaunchOptions { get ; }
55
+ private LaunchOptions LaunchOptions { get ; }
33
56
34
57
/// <summary>
35
58
/// Call CreateAsync before using ConvertHtmlTo*
@@ -45,9 +68,20 @@ public static Task<Renderer> CreateAsync()
45
68
/// Call CreateAsync before using ConvertHtmlTo*, accepts custom BrowserFetcher and custom chromium launch options
46
69
/// </summary>
47
70
/// <param name="browserFetcher"></param>
48
- /// <param name="launchOptions ">Adds launch options to chromium</param>
71
+ /// <param name="chromeiumArguments ">Adds custom arguments to chromium</param>
49
72
/// <returns></returns>
50
- public static Task < Renderer > CreateAsync ( BrowserFetcher browserFetcher , string ? launchOptions = null )
73
+ public static Task < Renderer > CreateAsync ( BrowserFetcher browserFetcher , string chromeiumArguments )
74
+ {
75
+ return CreateAsync ( browserFetcher , new LaunchOptions ( ) { Args = new [ ] { chromeiumArguments } } ) ;
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 )
51
85
{
52
86
var html2Pdf = new Renderer ( launchOptions ) ;
53
87
return html2Pdf . InitializeAsync ( browserFetcher ) ;
@@ -59,18 +93,17 @@ private async Task<Renderer> InitializeAsync(BrowserFetcher browserFetcher)
59
93
BrowserFetcher . DownloadProgressChanged += DownloadProgressChanged ;
60
94
61
95
_ = 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 ) ;
63
97
return this ;
64
98
}
65
99
66
100
private LaunchOptions SystemSpecificConfig ( )
67
101
{
68
- if ( string . IsNullOrEmpty ( LaunchOptions ) && ( IsRunningOnWslOrAzure ( ) || IsRunningOnAzureLinux ( ) ) )
102
+ if ( IsRunningOnWslOrAzure ( ) || IsRunningOnAzureLinux ( ) )
69
103
{
70
104
return new LaunchOptions { Headless = true , Args = new string [ ] { "--no-sandbox" } } ;
71
105
}
72
-
73
- return new LaunchOptions { Headless = true } ;
106
+ return new LaunchOptions ( ) ;
74
107
}
75
108
76
109
private static bool IsRunningOnAzureLinux ( )
0 commit comments