Skip to content

Commit

Permalink
Merge pull request #1016 from IgorAlymov/SITKO-CORE-T-25
Browse files Browse the repository at this point in the history
feat: updated PuppeteerSharp
  • Loading branch information
pogromistik authored Aug 26, 2024
2 parents 28ad3e3 + 9e2fdcd commit b9a0a6d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<PackageVersion Include="ImgProxy" Version="2.3.2" />
<PackageVersion Include="Nito.AsyncEx" Version="5.1.2" />
<PackageVersion Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="11.1.0" />
<PackageVersion Include="PuppeteerSharp" Version="13.0.1" />
<PackageVersion Include="PuppeteerSharp" Version="19.0.1" />
<PackageVersion Include="NATS.Client" Version="1.1.0" />
<PackageVersion Include="STAN.Client" Version="0.3.0" />
<PackageVersion Include="System.Linq.Dynamic.Core" Version="1.4.3" />
Expand Down
26 changes: 8 additions & 18 deletions src/Sitko.Core.Puppeteer/BrowserProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,14 @@

namespace Sitko.Core.Puppeteer;

public class BrowserProvider : IBrowserProvider
public class BrowserProvider(
IOptionsMonitor<PuppeteerModuleOptions> optionsMonitor,
ILoggerFactory loggerFactory,
ILogger<BrowserProvider> logger)
: IBrowserProvider
{
private readonly ILogger<BrowserProvider> logger;
private readonly ILoggerFactory loggerFactory;
private readonly IOptionsMonitor<PuppeteerModuleOptions> optionsMonitor;

public BrowserProvider(IOptionsMonitor<PuppeteerModuleOptions> optionsMonitor, ILoggerFactory loggerFactory,
ILogger<BrowserProvider> logger)
{
this.optionsMonitor = optionsMonitor;
this.loggerFactory = loggerFactory;
this.logger = logger;
}

private PuppeteerModuleOptions Options => optionsMonitor.CurrentValue;


public async Task<IBrowser> GetBrowserAsync()
{
if (!string.IsNullOrEmpty(Options.BrowserWsEndpoint))
Expand All @@ -30,7 +21,7 @@ public async Task<IBrowser> GetBrowserAsync()
new ConnectOptions
{
BrowserWSEndpoint = Options.BrowserWsEndpoint,
IgnoreHTTPSErrors = Options.IgnoreHTTPSErrors,
AcceptInsecureCerts = Options.AcceptInsecureCerts,
DefaultViewport = Options.ViewPortOptions
},
loggerFactory);
Expand All @@ -39,7 +30,7 @@ public async Task<IBrowser> GetBrowserAsync()
if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("PUPPETEER_EXECUTABLE_PATH")))
{
logger.LogDebug("Download browser");
using var browserFetcher = new BrowserFetcher(Options.Product);
var browserFetcher = new BrowserFetcher(Options.Product);
if (!string.IsNullOrEmpty(Options.Revision))
{
await browserFetcher.DownloadAsync(Options.Revision);
Expand All @@ -58,9 +49,8 @@ public async Task<IBrowser> GetBrowserAsync()
{
Headless = Options.Headless,
Args = Options.BrowserArgs,
IgnoreHTTPSErrors = Options.IgnoreHTTPSErrors,
AcceptInsecureCerts = Options.AcceptInsecureCerts,
DefaultViewport = Options.ViewPortOptions
}, loggerFactory);
}
}

2 changes: 1 addition & 1 deletion src/Sitko.Core.Puppeteer/PuppeteerModuleOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Sitko.Core.Puppeteer;
public class PuppeteerModuleOptions : BaseModuleOptions
{
public string? BrowserWsEndpoint { get; set; }
public bool IgnoreHTTPSErrors { get; set; }
public bool AcceptInsecureCerts { get; set; }

[JsonIgnore] public ViewPortOptions ViewPortOptions { get; set; } = ViewPortOptions.Default;
public string[] BrowserArgs { get; set; } = { "--no-sandbox" };
Expand Down

0 comments on commit b9a0a6d

Please sign in to comment.