-
-
Notifications
You must be signed in to change notification settings - Fork 439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for Azure #383
Comments
You won't be able to run chrome on Azure, you'll have to use an external chrome process. I wrote a post about this http://www.hardkoded.com/blogs/azure-chrome-puppeteer-browserless |
Too bad. thanks! |
When you say it won't work in Azure, will Puppeteer-Sharp not run within a .net core web application? Or are talking about Azure Functions, or both? |
@brightertools I didn't have the time to test it again. If you can test it and let us know how it went it would be great. |
@kblok : ok, I just found your project today so am a little early in terms of deploying anything just yet, but will need to test that to make sure what we are doing works... |
@brightertools cool, Let us know how it goes. |
I tried to run it in an azure web app and it fails. This is my code var options = new LaunchOptions
{
Headless = true
};
await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);
using (var browser = await Puppeteer.LaunchAsync(options))
using (var page = await browser.NewPageAsync())
{
await page.GoToAsync(htmlurl);
document = await page.PdfStreamAsync();
}
return document; It fails on this line using (var browser = await Puppeteer.LaunchAsync(options)) and I |
@PradeepLoganathan is that a WebApp? |
I have the same issue |
Same issue here can't run it on my web app EDIT: Just spent all morning implementing this to replace 'SelectPDF' and it failed upon deployment. Also using a web app and tried to copy across chrome files manually still no luck. |
@kblok are you planning on looking into this? SelectPDF is working fine, but slow and far more limited than this library. |
@ravtakhar I don't think I will be able to dig into this in the following 30 days. |
@kblok wondering if we can open this issue again. I tried to take a look, but I think it's a little too over my head. |
@ravtakhar reopened |
I got a little bit further, but still no success. My code is: public class PuppeteerRenderer : IPdfRenderer {
public async Task<byte[]> RenderPdfAsync(string htmlInput)
{
var fetcher = new BrowserFetcher(new BrowserFetcherOptions()
{
Path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Puppeteer")
});
await fetcher.DownloadAsync(BrowserFetcher.DefaultRevision);
var path = fetcher.GetExecutablePath(BrowserFetcher.DefaultRevision);
var options = new LaunchOptions()
{
Headless = true,
ExecutablePath = path
};
using (var browser = await Puppeteer.LaunchAsync(options))
{
var page = await browser.NewPageAsync();
await page.SetContentAsync(htmlInput);
return await page.PdfDataAsync();
}
}
} The only interesting part is the one where I specify the folder for the Chromium download. When attempting this with MVC 5 running locally on IIS Express, I noticed that the default working directory is one where the app can't write, so specifying this helped. In Azure App Service, though, execution hangs at |
BrowserFetcher uses Directory.GetCurrentDirectory() to download to but if you are running PuppeteerSharp in a service it'll be something like "C:\Windows\System32". I added a statement to when my service was starting and gave the service user permissions on the install folder: |
May be this is a idea to solve this: https://oren.codes/2018/02/25/registration-free-com-with-azure-app-services/ |
Status update? Is this a viable feature? |
We are using PuppeteerSharp in Azure (AppService) with the browserless.io service and it works well. I followed @kblok 's example here: http://www.hardkoded.com/blogs/azure-chrome-puppeteer-browserless |
I am deploying my application on azure, seems I cannot use BrowserFetcher. (In local anyhow I am using this, sometimes chrome.exe from Program files) |
Can confirm that it's currently not possible to run Puppeteer on Azure Functions either. You get the same error as raupes:
Which gets triggered as soon as you call: var browser = await Puppeteer.LaunchAsync(new LaunchOptions
{
Headless = true
}); Looks like it's a known issue: Azure/azure-functions-host/issues/2417 |
I wrote about a possible solution here http://www.hardkoded.com/blog/running-puppeteer-sharp-azure-functions |
@kblok Kinda a cop-out to use a Linux Docker image rather than running in-place within an Azure App Service or Azure Function. FWIW, I'm able to work-around (fix?) the I first posted my semi-solution to here ( Azure/azure-functions-host#2417 ) but I've replicated it here: I was able to get For those wondering, do this:
This is the
|
I've just managed to do the same before seeing your comment. I'm getting the same, but everything appears to be working. Have you experienced any issues with this approach of just ignoring the error? Memory-buildup or restarts or anything? |
You can now use Puppeteer on Azure Functions running on Linux: Consumption plan only at time of writing. The article talks about Node.js but I've tested the code below and it works fine. public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
string url = req.Query["url"];
url = url ?? "https://google.com";
var downloadsFolder = Path.GetTempPath(); // Need to use a folder with write permissions. "/tmp/" in Azure
log.LogInformation($"downloadsFolder: {downloadsFolder}");
var browserFetcher = new BrowserFetcher(new BrowserFetcherOptions
{
Path = downloadsFolder
});
await browserFetcher.DownloadAsync(BrowserFetcher.DefaultRevision);
var browser = await Puppeteer.LaunchAsync(new LaunchOptions
{
Headless = true,
ExecutablePath = browserFetcher.RevisionInfo(BrowserFetcher.DefaultRevision).ExecutablePath
});
var page = await browser.NewPageAsync();
await page.GoToAsync(url);
var screenshotStream = await page.ScreenshotStreamAsync(new ScreenshotOptions { Type = ScreenshotType.Png, FullPage = true });
return new FileStreamResult(screenshotStream, "image/png");
} |
@GFoley83 does the same implementation work on Azure Functions running on Windows also? |
Honestly, no - I gave up :) |
hey thanks for this solution. it works for english language. does anyone know a way to make the project to use unicode/east asian fonts for east asian websites ? |
Any updated for deploy puppeteer in Azure Apps ? (OS version: Microsoft Windows NT 10.0.14393.0) |
I've created a docker image to run a proxy server that provide WebSocket endpoint to use Chromium headless browser from your application. You can run it on your local environment or server such as render.com, Azure VMs, and so on even though your application is running on Azure App Service that does not allow apps to run headless browsers. https://github.com/sashiyama/browserless var options = new ConnectOptions
{
BrowserWSEndpoint = "ws://localhost/chromium?token=xxx"
};
return await Puppeteer.ConnectAsync(options); |
@nickticket2u I had to add lines of codes on docker file. RUN apt update -y && apt install -y fonts-noto-core && apt install -y fonts-noto-cjk && fc-cache -fv |
Description
Trying hole day. Is it possible to run on Azure App Service?
Also when trying to copy installation result from npm install puppeteer to output I still get the error
Win32Exception: The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail
at this line
PuppeteerSharp.Launcher.LaunchAsync(LaunchOptions options)
And I simply can't install chrome there.
Hope you can help or be able how to get this cool project running on azure.
thank you
Complete minimal example reproducing the issue
}
Expected behavior:
Please add description how to run within Azure App Service or add support to it.
Versions
The text was updated successfully, but these errors were encountered: