'Puppeteer not working anymore in Azure Function
I have an Azure Function where I convert an HTML to PDF and then download the result.
Yesterday I updated the function to version 4 and .NET 6 and I also saw that the BrowserFetcher.DefaultRevision is obsoleted and I replaced it with recommended BrowserFetcher.DefaultChromiumRevision and the function is not working anymore after publish.
I also tried locally but there is all good. The error I received is Invalid URI: The hostname could not be parsed. and I suspect the Puppeteer.
This is my Startup function code:
public override void Configure(IFunctionsHostBuilder builder)
{
var bfOptions = new BrowserFetcherOptions();
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
bfOptions.Path = Path.GetFullPath("mounted");
}
var bf = new BrowserFetcher(bfOptions);
try
{
bf.DownloadAsync(BrowserFetcher.DefaultChromiumRevision).Wait();
}
catch (Exception)
{
string zipPath = Path.Combine(bf.DownloadsFolder, $"download-{bf.Platform}-{BrowserFetcher.DefaultChromiumRevision}.zip");
string folderPath = Path.Combine(bf.DownloadsFolder, $"{bf.Platform}-{BrowserFetcher.DefaultChromiumRevision}");
using (var process = new Process())
{
process.StartInfo.FileName = "unzip";
process.StartInfo.Arguments = $"\"{zipPath}\" -d \"{folderPath}\"";
process.Start();
process.WaitForExit();
}
new FileInfo(zipPath).Delete();
}
builder.Services.AddHttpClient();
builder.Services.AddSingleton<IPdfPrinterService>((s) =>
{
return new ChromiumPdfPrinterService(bf.GetExecutablePath(BrowserFetcher.DefaultChromiumRevision));
});
}
Has anyone else faced this problem?
Solution 1:[1]
I found the issue. That was caused by RazorLight upgrade to stable version 2.0.0.
Rollback to version 2.0.0-rc.3 works fine.
Here is the GitHub issue: https://github.com/toddams/RazorLight/issues/481
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sergiu Molnar |
