Skip to content

Commit a373243

Browse files
authored
Bummped PuppeteerSharp 10.1.2 -> 11.0.3
2 parents 77d18b1 + 7fd37b9 commit a373243

25 files changed

+96
-83
lines changed

.github/workflows/dotnet.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
uses: actions/setup-dotnet@v3
2424
with:
2525
dotnet-version: 6.0.x
26-
- uses: actions/setup-node@v3.7.0
26+
- uses: actions/setup-node@v3.8.1
2727
with:
2828
node-version: 18
2929
- name: Restore dependencies

Codeuctivity.HtmlRenderer/Codeuctivity.HtmlRenderer.csproj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
<AssemblyName>Codeuctivity.HtmlRenderer</AssemblyName>
3232
<RootNamespace>Codeuctivity.HtmlRenderer</RootNamespace>
3333
<EnableNETAnalyzers>true</EnableNETAnalyzers>
34+
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
35+
<AnalysisLevel>latest</AnalysisLevel>
3436
<ContinuousIntegrationBuild Condition="'$(GITHUB_ACTIONS)' == 'true'">true</ContinuousIntegrationBuild>
3537
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
3638
<AssemblyOriginatorKeyFile>Codeuctivity.HtmlRenderer.snk</AssemblyOriginatorKeyFile>
@@ -39,8 +41,8 @@
3941

4042
<ItemGroup>
4143
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="all" />
42-
<PackageReference Include="PuppeteerSharp" Version="10.1.2" />
43-
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.55.0.65544">
44+
<PackageReference Include="PuppeteerSharp" Version="11.0.3" />
45+
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.8.0.76515">
4446
<PrivateAssets>all</PrivateAssets>
4547
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
4648
</PackageReference>

Codeuctivity.HtmlRenderer/Renderer.cs

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public Renderer(string? customChromiumArgs)
2020
{
2121
if (customChromiumArgs == null)
2222
{
23-
LaunchOptions = SystemSpecificConfig();
23+
LaunchOptions = Renderer.SystemSpecificConfig();
2424
}
2525
else
2626
{
@@ -36,7 +36,7 @@ public Renderer(LaunchOptions? launchOptions = null)
3636
{
3737
if (launchOptions == null)
3838
{
39-
LaunchOptions = SystemSpecificConfig();
39+
LaunchOptions = Renderer.SystemSpecificConfig();
4040
}
4141
else
4242
{
@@ -89,15 +89,26 @@ public static Task<Renderer> CreateAsync(BrowserFetcher browserFetcher, LaunchOp
8989

9090
private async Task<Renderer> InitializeAsync(BrowserFetcher browserFetcher)
9191
{
92-
BrowserFetcher = browserFetcher;
93-
BrowserFetcher.DownloadProgressChanged += DownloadProgressChanged;
94-
var revisionInfo = await BrowserFetcher.DownloadAsync(BrowserFetcher.DefaultChromiumRevision ?? string.Empty).ConfigureAwait(false);
95-
LaunchOptions.ExecutablePath = revisionInfo.ExecutablePath;
96-
Browser = await Puppeteer.LaunchAsync(LaunchOptions).ConfigureAwait(false);
92+
// for macsome reason the download progress is not called on macos
93+
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
94+
{
95+
using var browserFetcher1 = new BrowserFetcher();
96+
await browserFetcher1.DownloadAsync();
97+
Browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = true });
98+
}
99+
else
100+
{
101+
BrowserFetcher = browserFetcher;
102+
BrowserFetcher.DownloadProgressChanged += DownloadProgressChanged;
103+
var revisionInfo = await BrowserFetcher.DownloadAsync(PuppeteerSharp.BrowserData.Chrome.DefaultBuildId).ConfigureAwait(false);
104+
LaunchOptions.ExecutablePath = revisionInfo.GetExecutablePath();
105+
Browser = await Puppeteer.LaunchAsync(LaunchOptions).ConfigureAwait(false);
106+
}
107+
97108
return this;
98109
}
99110

100-
private LaunchOptions SystemSpecificConfig()
111+
private static LaunchOptions SystemSpecificConfig()
101112
{
102113
if (IsRunningOnWslOrAzure() || IsRunningOnAzureLinux())
103114
{
@@ -126,8 +137,8 @@ private static bool IsRunningOnWslOrAzure()
126137
}
127138

128139
var version = File.ReadAllText("/proc/version");
129-
var IsWsl = version.IndexOf("Microsoft", StringComparison.OrdinalIgnoreCase) >= 0;
130-
var IsAzure = version.IndexOf("azure", StringComparison.OrdinalIgnoreCase) >= 0;
140+
var IsWsl = version?.IndexOf("Microsoft", StringComparison.OrdinalIgnoreCase) >= 0;
141+
var IsAzure = version?.IndexOf("azure", StringComparison.OrdinalIgnoreCase) >= 0;
131142

132143
return IsWsl || IsAzure;
133144
}
@@ -157,10 +168,10 @@ public async Task ConvertHtmlToPdf(string sourceHtmlFilePath, string destination
157168
}
158169

159170
var absolutePath = Path.GetFullPath(sourceHtmlFilePath);
160-
await using var page = (await Browser.NewPageAsync().ConfigureAwait(false));
171+
await using var page = await Browser.NewPageAsync().ConfigureAwait(false);
161172
await page.GoToAsync($"file://{absolutePath}").ConfigureAwait(false);
162173
// Wait for fonts to be loaded. Omitting this might result in no text rendered in PDF.
163-
await page.EvaluateExpressionHandleAsync("document.fonts.ready");
174+
await page.EvaluateExpressionHandleAsync("document.fonts.ready").ConfigureAwait(false);
164175
await page.PdfAsync(destinationPdfFilePath, pdfOptions).ConfigureAwait(false);
165176
}
166177

@@ -188,10 +199,10 @@ public async Task ConvertHtmlToPng(string sourceHtmlFilePath, string destination
188199
}
189200

190201
var absolutePath = Path.GetFullPath(sourceHtmlFilePath);
191-
await using var page = (await Browser.NewPageAsync().ConfigureAwait(false));
202+
await using var page = await Browser.NewPageAsync().ConfigureAwait(false);
192203
await page.GoToAsync($"file://{absolutePath}").ConfigureAwait(false);
193204
// Wait for fonts to be loaded. Omitting this might result in no text the screenshot.
194-
await page.EvaluateExpressionHandleAsync("document.fonts.ready");
205+
await page.EvaluateExpressionHandleAsync("document.fonts.ready").ConfigureAwait(false);
195206
await page.ScreenshotAsync(destinationPngFilePath, screenshotOptions).ConfigureAwait(false);
196207
}
197208

@@ -214,7 +225,7 @@ public async Task<byte[]> ConvertHtmlStringToPngData(string sourceHtmlData, Scre
214225
await using var page = await Browser.NewPageAsync().ConfigureAwait(false);
215226
await page.SetContentAsync(sourceHtmlData).ConfigureAwait(false);
216227
// Wait for fonts to be loaded. Omitting this might result in no text the screenshot.
217-
await page.EvaluateExpressionHandleAsync("document.fonts.ready");
228+
await page.EvaluateExpressionHandleAsync("document.fonts.ready").ConfigureAwait(false);
218229
return await page.ScreenshotDataAsync(screenshotOptions).ConfigureAwait(false);
219230
}
220231

@@ -243,9 +254,7 @@ public async ValueTask DisposeAsync()
243254
await DisposeAsyncCore().ConfigureAwait(false);
244255

245256
Dispose(disposing: false);
246-
#pragma warning disable CA1816 // Dispose methods should call SuppressFinalize
247257
GC.SuppressFinalize(this);
248-
#pragma warning restore CA1816 // Dispose methods should call SuppressFinalize
249258
}
250259

251260
/// <summary>

Codeuctivity.HtmlRendererCli/Codeuctivity.HtmlRendererCli.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
<OutputType>Exe</OutputType>
55
<TargetFrameworks>net6.0</TargetFrameworks>
66
<EnableNETAnalyzers>true</EnableNETAnalyzers>
7+
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
8+
<AnalysisLevel>latest</AnalysisLevel>
79
<RootNamespace>Codeuctivity.HtmlRendererCli</RootNamespace>
810
<DebugSymbols>true</DebugSymbols>
911
<DebugType>embedded</DebugType>

Codeuctivity.HtmlRendererCli/Program.cs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,26 @@
77

88
namespace Codeuctivity.HtmlRendererCli
99
{
10-
public class Program
10+
public static class Program
1111
{
1212
public static readonly Assembly Reference = typeof(Renderer).Assembly;
1313
public static readonly Version Version = Reference.GetName().Version;
1414
private static int _lastProgressValue;
1515

1616
public static async Task<int> Main(string[] args)
1717
{
18-
if (args.Length != 2)
18+
if (args?.Length != 2)
1919
{
2020
Console.WriteLine("Usage: PuppeteerSharp.RendererCli <sourceHtmlFilePath> <destinatioPdfFilePath>");
2121
return 1;
2222
}
2323

24-
var inputPathDocx = args[0];
24+
var inputPathDocX = args[0];
2525
var outputPathHtml = args[1];
2626

27-
if (!File.Exists(inputPathDocx))
27+
if (!File.Exists(inputPathDocX))
2828
{
29-
Console.WriteLine($"Could not find source {inputPathDocx}.");
29+
Console.WriteLine($"Could not find source {inputPathDocX}.");
3030
return 1;
3131
}
3232

@@ -36,14 +36,12 @@ public static async Task<int> Main(string[] args)
3636
return 1;
3737
}
3838

39-
Console.WriteLine($"Converting {inputPathDocx} to {outputPathHtml} using PuppeteerSharp.Renderer {Version}");
40-
BrowserFetcherOptions options = new BrowserFetcherOptions();
41-
options.Path = Path.GetTempPath();
42-
var browserFetcher = new BrowserFetcher(options);
43-
Console.WriteLine($"Fetching chromium from web, to {browserFetcher.DownloadsFolder} .... ");
39+
Console.WriteLine($"Converting {inputPathDocX} to {outputPathHtml} using PuppeteerSharp.Renderer {Version}");
40+
using var browserFetcher = new BrowserFetcher();
41+
Console.WriteLine($"Fetching chromium from web, to {browserFetcher.CacheDir} .... ");
4442
browserFetcher.DownloadProgressChanged += BrowserFetcher_DownloadProgressChanged;
45-
await using var chromiumRenderer = await Renderer.CreateAsync(browserFetcher, string.Empty);
46-
await chromiumRenderer.ConvertHtmlToPdf(inputPathDocx, outputPathHtml);
43+
await using var chromiumRenderer = await Renderer.CreateAsync(browserFetcher);
44+
await chromiumRenderer.ConvertHtmlToPdf(inputPathDocX, outputPathHtml);
4745
return 0;
4846
}
4947

Codeuctivity.HtmlRendererCliTests/Codeuctivity.HtmlRendererCliTests.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
11-
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.55.0.65544">
10+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
11+
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.8.0.76515">
1212
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1313
<PrivateAssets>all</PrivateAssets>
1414
</PackageReference>
15-
<PackageReference Include="xunit" Version="2.4.2" />
16-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
15+
<PackageReference Include="xunit" Version="2.5.0" />
16+
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
1717
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1818
<PrivateAssets>all</PrivateAssets>
1919
</PackageReference>

Codeuctivity.HtmlRendererCliTests/FactRunableOnWindowsAttribute.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
namespace Codeuctivity.HtmlRendererCliTests
55
{
6-
internal class FactRunableOnWindowsAttribute : FactAttribute
6+
internal class FactRunnableOnWindowsAttribute : FactAttribute
77
{
8-
public FactRunableOnWindowsAttribute()
8+
public FactRunnableOnWindowsAttribute()
99
{
1010
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
1111
{

Codeuctivity.HtmlRendererCliTests/RendererCliTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public void VersionShouldBeProcessed()
1919
[Fact]
2020
public async Task ConversionShouldWork()
2121
{
22-
var testFileName = "BasicTextFormated.html";
22+
var testFileName = "BasicTextFormatted.html";
2323
var sourceHtmlFilePath = $"../../../TestInput/{testFileName}";
2424
var actualFilePath = Path.Combine(Path.GetTempPath(), $"Actual{testFileName}.pdf");
2525

@@ -28,10 +28,10 @@ public async Task ConversionShouldWork()
2828
Assert.True(File.Exists(actualFilePath));
2929
}
3030

31-
[FactRunableOnWindows]
31+
[FactRunnableOnWindows]
3232
public void PublishedSelfContainedBinaryShouldWork()
3333
{
34-
var testFileName = "BasicTextFormated.html";
34+
var testFileName = "BasicTextFormatted.html";
3535
var sourceHtmlFilePath = Path.GetFullPath($"../../../TestInput/{testFileName}");
3636
var actualFilePath = Path.Combine(Path.GetTempPath(), $"Actual{testFileName}.pdf");
3737

@@ -40,13 +40,13 @@ public void PublishedSelfContainedBinaryShouldWork()
4040
File.Delete(actualFilePath);
4141
}
4242

43-
var acutualWindowsBinary = DotnetPublishFolderProfileWindows("Codeuctivity.HtmlRendererCli");
43+
var actualWindowsBinary = DotnetPublishFolderProfileWindows("Codeuctivity.HtmlRendererCli");
4444

4545
using var process = new Process
4646
{
4747
StartInfo = new ProcessStartInfo
4848
{
49-
FileName = acutualWindowsBinary,
49+
FileName = actualWindowsBinary,
5050
Arguments = $" {sourceHtmlFilePath} {actualFilePath}",
5151
RedirectStandardOutput = true,
5252
RedirectStandardError = true,
Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

3-
<PropertyGroup>
4-
<TargetFrameworks>net7.0;net6.0</TargetFrameworks>
5-
<IsPackable>false</IsPackable>
6-
<LangVersion>9.0</LangVersion>
7-
<Nullable>enable</Nullable>
8-
<IsPackable>false</IsPackable>
9-
<EnableNETAnalyzers>true</EnableNETAnalyzers>
10-
</PropertyGroup>
3+
<PropertyGroup>
4+
<TargetFrameworks>net7.0;net6.0</TargetFrameworks>
5+
<IsPackable>false</IsPackable>
6+
<LangVersion>9.0</LangVersion>
7+
<Nullable>enable</Nullable>
8+
<IsPackable>false</IsPackable>
9+
<EnableNETAnalyzers>true</EnableNETAnalyzers>
10+
</PropertyGroup>
1111

12-
<ItemGroup>
13-
<Compile Remove="SourceTestFiles\**" />
14-
<EmbeddedResource Remove="SourceTestFiles\**" />
15-
<None Remove="SourceTestFiles\**" />
16-
</ItemGroup>
12+
<ItemGroup>
13+
<Compile Remove="SourceTestFiles\**" />
14+
<EmbeddedResource Remove="SourceTestFiles\**" />
15+
<None Remove="SourceTestFiles\**" />
16+
</ItemGroup>
1717

18-
<ItemGroup>
19-
<PackageReference Include="Codeuctivity.ImageSharpCompare" Version="2.0.155" />
20-
<PackageReference Include="Codeuctivity.PdfjsSharp" Version="1.2.95" />
21-
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.55.0.65544">
22-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
23-
<PrivateAssets>all</PrivateAssets>
24-
</PackageReference>
25-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
26-
<PackageReference Include="xunit" Version="2.4.2" />
27-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
28-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
29-
<PrivateAssets>all</PrivateAssets>
30-
</PackageReference>
31-
</ItemGroup>
18+
<ItemGroup>
19+
<PackageReference Include="Codeuctivity.ImageSharpCompare" Version="2.0.182" />
20+
<PackageReference Include="Codeuctivity.PdfjsSharp" Version="1.2.95" />
21+
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.8.0.76515">
22+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
23+
<PrivateAssets>all</PrivateAssets>
24+
</PackageReference>
25+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
26+
<PackageReference Include="xunit" Version="2.5.0" />
27+
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
28+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
29+
<PrivateAssets>all</PrivateAssets>
30+
</PackageReference>
31+
</ItemGroup>
3232

33-
<ItemGroup>
34-
<ProjectReference Include="..\Codeuctivity.HtmlRenderer\Codeuctivity.HtmlRenderer.csproj" />
35-
</ItemGroup>
33+
<ItemGroup>
34+
<ProjectReference Include="..\Codeuctivity.HtmlRenderer\Codeuctivity.HtmlRenderer.csproj" />
35+
</ItemGroup>
3636
</Project>

0 commit comments

Comments
 (0)