question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for Azure

See original GitHub issue

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

      public class HomeController : Controller
{
    string path;
    public HomeController(IHostingEnvironment hostingEnvironment) {
        this.path = hostingEnvironment.ContentRootPath;
    }
    public async Task<IActionResult> Index()
    {
        bool exist = false;
        using(var browser = await PuppeteerSharp.Puppeteer.LaunchAsync(new LaunchOptions() {
            Headless = true,
            ExecutablePath = this.path + @"\node_modules\puppeteer\.local-chromium\win64-564778\chrome-win32\chrome.exe"
        })) {
            using(var page =await browser.NewPageAsync()) {
                var response = await page.GoToAsync("http://www.sales-suckers.com");
                var res = await page.EvaluateExpressionAsync<dynamic>("window.salessuckers");
                exist = res != null;
            }
        }
        ViewData.Add("EXIST", exist);
        return View();
    }

}

Expected behavior:

Please add description how to run within Azure App Service or add support to it.

Versions

  • Which version of PuppeteerSharp are you using? 1.1
  • Which .NET runtime and version are you targeting? .NET Core 2.0. .NET Core 2.1

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:30 (8 by maintainers)

github_iconTop GitHub Comments

8reactions
GFoley83commented, Sep 26, 2020

You can now use Puppeteer on Azure Functions running on Linux: https://anthonychu.ca/post/azure-functions-headless-chromium-puppeteer-playwright/

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");
}

5reactions
PradeepLoganathancommented, Oct 17, 2018

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 don’t even get an exception. The call fails with a 502 invalid gateway error. I was hopeful of using this to generate pdf’s 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Azure Support Options
Learn about the types of Microsoft Azure support resources that are available to you. View Azure support plans and options to get started...
Read more >
Contact Microsoft Azure Support
Get answers in Azure forums. · Connect with @AzureSupport- answers, support, experts. · If you have a support plan, open a support request....
Read more >
Azure support ticket
Create and manage support requests for Microsoft Azure and Azure Dev Ops Services, including technical and billing help.
Read more >
How to create an Azure support request
Select the ? in the global header, then select Help + support. Screenshot of the Help menu in the Azure portal. Select Create...
Read more >
Contact Microsoft Azure Sales
Country Regional number Hours Brazil 0800‑047‑4894 9:00 AM–6:00 PM Brasilia Time, Monday–Friday Canada 1‑855‑270‑0615 8:00 AM–6:00 PM Central Time, Monday–Friday Hong Kong 800‑938‑398 9:00 AM–6:00 PM...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found