Skip to content
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

Any chance for .NET 8 support? #122

Closed
auriorx opened this issue Jan 13, 2024 · 9 comments
Closed

Any chance for .NET 8 support? #122

auriorx opened this issue Jan 13, 2024 · 9 comments
Assignees

Comments

@auriorx
Copy link

auriorx commented Jan 13, 2024

Hi!

Not sure if you're already working on this, but the current preview SDK of AWS lambda dotnet:8 doesn't seem to be able to launch the browser.

Failed to launch browser! /tmp/chromium: error while loading shared libraries: libnspr4.so: cannot open shared object file: No such file or directory\n

Even after I build my Dockerfile to fetch that lib, it still leaves me with

Failed to launch browser! without any other error message.

Thank you!

@brianfeucht brianfeucht self-assigned this Jan 13, 2024
@brianfeucht
Copy link
Member

Hi @auriorx

There are a few changes related to the move from AL2 to AL2023 linux base.

I have some improvements in our tests and most of the work to support the dotnet8 preview on this PR

Right now chrome is launching and loading a page, but then crashing. I believe it is due to the underlying lib used for SSL. I have gotten pulled away due to other priorities, but I'm hopeful I can get this working before .NET 8 is launched officially.

Feel free to take a look and let me know if you are able to find any more details.

@auriorx
Copy link
Author

auriorx commented Jan 14, 2024

Hi again!

Thanks for the quick reply. I've tried to do some things to fix the issue for my specific use-case (which is PDF generation, not browsing and downloading an image).

I see the exact same error (bottom of my post). It appears the browser also crashes when injecting a new page with some HTML content and trying to conver that to a PDF. I've also ran the chromium browser with --ignore-certificate-errors to see if that changes anything. Unfortunately it doesn't.

I've changed the test to the following to try and test the PDF generation.

using Amazon.Lambda.Core;
using HeadlessChromium.Puppeteer.Lambda.Dotnet;
using Microsoft.Extensions.Logging;
using PuppeteerSharp;
using PuppeteerSharp.Media;
using System.Threading.Tasks;

namespace SampleLambda
{
    public class HelloWorldHandler
    {
        [LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]
        public async Task<byte[]> Handle(ILambdaContext context)
        {
            var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
            var browserLauncher = new HeadlessChromiumPuppeteerLauncher(loggerFactory);
            var htmlContent = "<html><body><h1>Hello, Puppeteer!</h1></body></html>";

            await using (var browser = await browserLauncher.LaunchAsync())
            {
                var page = await browser.NewPageAsync();
                await page.SetContentAsync(htmlContent);

                // Call the method to get PDF content while the page is still open
                return await GetPdfContent(page, htmlContent);
            }
        }


        private async Task<byte[]> GetPdfContent(IPage page, string html)
        {
            await page.SetContentAsync(html);

            var pdfOptions = new PdfOptions
            {
                Format = PaperFormat.A4,
                PrintBackground = true
            };

            // Note: Do not dispose of the page here, as it's being used in the calling method
            byte[] pdfBytes = await page.PdfDataAsync(pdfOptions);
            return pdfBytes;
        }
    }
}

Unfortunately, my lack of expertise halts my progress at this time. I hope this information is useful to you when you (or someone else) get(s) back to this project

FAILURE: The lambda did not return expected png value starting with iVB
{
  "errorType": "TargetClosedException",
  "errorMessage": "Protocol error(Runtime.callFunctionOn): Target closed. (The remote party closed the WebSocket connection without completing the close handshake.)",
  "stackTrace": [
    "at PuppeteerSharp.CDPSession.SendAsync(String method, Object args, Boolean waitForCallback) in /home/runner/work/puppeteer-sharp/puppeteer-sharp/lib/PuppeteerSharp/CDPSession.cs:line 101",
    "at PuppeteerSharp.CDPSession.SendAsync[T](String method, Object args) in /home/runner/work/puppeteer-sharp/puppeteer-sharp/lib/PuppeteerSharp/CDPSession.cs:line 58",
    "at PuppeteerSharp.ExecutionContext.ExecuteEvaluationAsync(String method, Object args) in /home/runner/work/puppeteer-sharp/puppeteer-sharp/lib/PuppeteerSharp/ExecutionContext.cs:line 172",
    "at PuppeteerSharp.ExecutionContext.EvaluateFunctionInternalAsync(Boolean returnByValue, String script, Object[] args) in /home/runner/work/puppeteer-sharp/puppeteer-sharp/lib/PuppeteerSharp/ExecutionContext.cs:line 158",
    "at PuppeteerSharp.ExecutionContext.RemoteObjectTaskToObject[T](Task`1 remote) in /home/runner/work/puppeteer-sharp/puppeteer-sharp/lib/PuppeteerSharp/ExecutionContext.cs:line 143",
    "at PuppeteerSharp.IsolatedWorld.EvaluateFunctionAsync(String script, Object[] args) in /home/runner/work/puppeteer-sharp/puppeteer-sharp/lib/PuppeteerSharp/IsolatedWorld.cs:line 205",
    "at PuppeteerSharp.Frame.SetContentAsync(String html, NavigationOptions options) in /home/runner/work/puppeteer-sharp/puppeteer-sharp/lib/PuppeteerSharp/Frame.cs:line 362",
    "at SampleLambda.HelloWorldHandler.Handle(ILambdaContext context) in /home/runner/work/HeadlessChromium.Puppeteer.Lambda.Dotnet/HeadlessChromium.Puppeteer.Lambda.Dotnet/sample/SampleLambda-dotnet8/HelloWorldHandler.cs:line 22",
    "at SampleLambda.HelloWorldHandler.Handle(ILambdaContext context) in /home/runner/work/HeadlessChromium.Puppeteer.Lambda.Dotnet/HeadlessChromium.Puppeteer.Lambda.Dotnet/sample/SampleLambda-dotnet8/HelloWorldHandler.cs:line [25](https://github.com/auriorx/HeadlessChromium.Puppeteer.Lambda.Dotnet/actions/runs/7521091334/job/20471501394#step:8:26)",
    "at lambda_method1(Closure, Stream, ILambdaContext, Stream)",
    "at Amazon.Lambda.RuntimeSupport.HandlerWrapper.<>c__DisplayClass8_0.<GetHandlerWrapper>b__0(InvocationRequest invocation) in /src/Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/HandlerWrapper.cs:line 54",
    "at Amazon.Lambda.RuntimeSupport.LambdaBootstrap.InvokeOnceAsync(CancellationToken cancellationToken) in /src/Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/LambdaBootstrap.cs:line 185"
  ]
}

@brianfeucht
Copy link
Member

I moved work for this over to #123

@daria-shershneva-cko
Copy link

Hi @brianfeucht

Are there any updates regarding this issue?

@brianfeucht
Copy link
Member

@daria-shershneva-cko

We still have the same issue with the new OS used for the .NET 8 lambda image. You can repo it locally building and running the sample .net 8 app.

I have this PR open and it is failing on GHA: https://github.com/litmus/HeadlessChromium.Puppeteer.Lambda.Dotnet/actions/runs/8300910966/job/22719842699?pr=123

I have not been able to make any progress in figuring out why this is failing. Feel free to jump in. If you are able to resolve it, I'd be happy to accept a PR for it.

@nromano32
Copy link

Our .net 8 build runs fine on the new .NET 8 (C#/PowerShell) runtime, however, it is missing the fonts so the result is missing all the text. We use this for receipt generation so we had to roll back to the .NET version.

@zlangner
Copy link

I think the fonts are missing because when the brotli files are extracted the fonts.tar.br file isn't. If it were extracted it includes the font.conf so the logic about /tmp/.fonts at line 75-82 can be removed.

@brianfeucht
Copy link
Member

brianfeucht commented Apr 21, 2024

@nromano32 & @zlangner best place to find documentation on fonts is on the upstream chromium project - https://github.com/Sparticuz/chromium?tab=readme-ov-file#fonts

Feel free to either open a PR or a different github issue if you run into a specific bugs or improvements to this lib. I'd like to keep this issue dedicated to getting .NET 8 runtime support working

@brianfeucht
Copy link
Member

This is resolved via #136

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants