3

I have a skill for the Amazon Echo. The lambda function is written in C#/.Net Core, and hosted on AWS. I now need to extend it with functionality that uses PuppeteerSharp. My first problem with this was that it downloads chromium and puts it in your application's directory by default. This gave me an error, as the filesystem is read only. I then tried the package HeadlessChromium.Puppeteer.Lambda.Dotnet, but my resulting skill was too large to upload as a lambda function, because it now had chromium embedded.

I'm now trying to override the default puppeteer downloadpath, using a BrowserFetchOption. This allows me to download chromium on AWS to the system temp path, but then Puppeteer can't find it. I need to add ExecutablePath to the LaunchOptions object when I try to launch puppeteer. I've tested this locally under windows and it works, I now just need to write some general code to find the chromium executable under AWS.

  1. Is there a better way than searching for either chrome or chrome.exe under my download path (I need it to run under windows as well as AWS for the unit tests)? It feels like if Puppeteer provides this pair of options then there must be a better way to use them?
  2. Is there a better way to use Puppeteer in a lambda function than what I'm attempting?

Here is the windows code that is currently working, with the chrome path hard coded:

            string cpath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "chromium");

            var bfopt = new BrowserFetcherOptions() { Path = cpath };

            await new BrowserFetcher(bfopt).DownloadAsync(BrowserFetcher.DefaultRevision);

            var browser = await Puppeteer.LaunchAsync(new LaunchOptions { 
                ExecutablePath=System.IO.Path.Combine(cpath, "Win64-674921\\chrome-win\\chrome.exe"),
                Headless = true
            });
Kevin O'Donovan
  • 1,620
  • 1
  • 13
  • 24
  • So part 1 is simple - return value from DownloadAsync provides everything I need. Still interested to hear a better solution though – Kevin O'Donovan Aug 23 '19 at 17:48
  • 1
    While `HeadlessChromium.Puppeteer.Lambda.Dotnet` does make the lambda upload bigger than 50mb... I was able to make this work by uploading the zip to an S3 bucket... and having the lambda point to that. – brandonhein Sep 29 '22 at 21:09
  • +10 @brandonhein for `HeadlessChromium.Puppeteer.Lambda.Dotnet`. And a bonus +100 for the upload workaround. – Metro Smurf Nov 27 '22 at 00:59

0 Answers0