Skip to content

Commit cf9de7e

Browse files
authored
Fixed custom chromium arguments specific bug
2 parents ec0e033 + 2c04594 commit cf9de7e

File tree

4 files changed

+39
-7
lines changed

4 files changed

+39
-7
lines changed

.editorconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ csharp_prefer_static_local_function = true:suggestion
9494
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:silent
9595

9696
# Code-block preferences
97-
csharp_prefer_braces = true:silent
97+
csharp_prefer_braces = true:warning
9898
csharp_prefer_simple_using_statement = true:suggestion
9999

100100
# Expression-level preferences

Codeuctivity.HtmlRenderer.sln

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ VisualStudioVersion = 17.0.31903.59
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{FC3F4498-FA14-48A8-AA41-8D9095A0844F}"
77
ProjectSection(SolutionItems) = preProject
8+
.editorconfig = .editorconfig
89
.github\workflows\dotnet.yml = .github\workflows\dotnet.yml
910
README.md = README.md
1011
EndProjectSection

Codeuctivity.HtmlRenderer/Renderer.cs

+17-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ private async Task<Renderer> InitializeAsync(BrowserFetcher browserFetcher)
6565

6666
private LaunchOptions SystemSpecificConfig()
6767
{
68-
if (!string.IsNullOrEmpty(LaunchOptions) && (IsRunningOnWsl() || IsRunningOnAzureLinux()))
68+
if (string.IsNullOrEmpty(LaunchOptions) && (IsRunningOnWsl() || IsRunningOnAzureLinux()))
6969
{
7070
return new LaunchOptions { Headless = true, Args = new string[] { "--no-sandbox" } };
7171
}
@@ -75,12 +75,26 @@ private LaunchOptions SystemSpecificConfig()
7575

7676
private static bool IsRunningOnAzureLinux()
7777
{
78-
return RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && Environment.GetEnvironmentVariable("WEBSITE_SKU").Contains("Linux");
78+
var websiteSku = Environment.GetEnvironmentVariable("WEBSITE_SKU");
79+
80+
if (string.IsNullOrEmpty(websiteSku))
81+
{
82+
return false;
83+
}
84+
85+
return RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && websiteSku.IndexOf("Linux", StringComparison.OrdinalIgnoreCase) >= 0;
7986
}
8087

8188
private static bool IsRunningOnWsl()
8289
{
83-
return RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && File.ReadAllText("/proc/version").Contains("Microsoft");
90+
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
91+
{
92+
return false;
93+
}
94+
95+
var version = File.ReadAllText("/proc/version");
96+
var IsWsl = version.IndexOf("Microsoft", StringComparison.OrdinalIgnoreCase) >= 0;
97+
return IsWsl;
8498
}
8599

86100
/// <summary>

Codeuctivity.HtmlRendererTests/RendererTests.cs

+20-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using Codeuctivity.HtmlRenderer;
22
using Codeuctivity.HtmlRendererTests.Infrastructure;
33
using Codeuctivity.PdfjsSharp;
4+
using System;
45
using System.IO;
56
using System.Linq;
7+
using System.Runtime.InteropServices;
68
using System.Threading.Tasks;
79
using Xunit;
810

@@ -30,14 +32,29 @@ public async Task ShouldConvertHtmlToPdf(string testFileName)
3032
var actualImagePathDirectory = Path.Combine(Path.GetTempPath(), testFileName);
3133

3234
using var rasterize = new Rasterizer();
33-
var actualImages = await rasterize.ConvertToPngAsync(actualFilePath, actualImagePathDirectory);
3435

35-
Assert.Single(actualImages);
36-
DocumentAsserter.AssertImageIsEqual(actualImages.Single(), expectReferenceFilePath, 2000);
36+
if (!IsRunningOnWsl())
37+
{
38+
var actualImages = await rasterize.ConvertToPngAsync(actualFilePath, actualImagePathDirectory);
39+
Assert.Single(actualImages);
40+
DocumentAsserter.AssertImageIsEqual(actualImages.Single(), expectReferenceFilePath, 2000);
41+
}
3742
}
3843
await ChromiumProcessDisposedAsserter.AssertNoChromeProcessIsRunning();
3944
}
4045

46+
private static bool IsRunningOnWsl()
47+
{
48+
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
49+
{
50+
return false;
51+
}
52+
53+
var version = File.ReadAllText("/proc/version");
54+
var IsWsl = version.Contains("Microsoft", StringComparison.InvariantCultureIgnoreCase);
55+
return IsWsl;
56+
}
57+
4158
[Theory]
4259
[InlineData("BasicTextFormated.html")]
4360
public async Task ShouldConvertHtmlToPng(string testFileName)

0 commit comments

Comments
 (0)