Skip to content

upgrade PuppeteerSharp and HeadlessChromium.Puppeteer.Lambda.Dotnet #2807

Closed as not planned
@satviktechie1986

Description

@satviktechie1986

I have upgrade PuppeteerSharp and HeadlessChromium.Puppeteer.Lambda.Dotnet to generate pdf using aws lambda. but somehow i am running into an error : as below

PuppeteerSharp Version : 20.0.3

HeadlessChromium.Puppeteer.Lambda.Dotnet Version : 1.1.0.94

PuppeteerSharp.ProcessException: Failed to create connection
---> System.Net.WebSockets.WebSocketException (0x80004005): Unable to connect to the remote server
---> System.Net.Http.HttpRequestException: An error occurred while sending the request.
---> System.IO.IOException: Unable to read data from the transport connection: Connection reset by peer.
---> System.Net.Sockets.SocketException (104): Connection reset by peer
--- End of inner exception stack trace ---
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource<System.Int32>.GetResult(Int16 token)
at System.Net.Http.HttpConnection.InitialFillAsync(Boolean async)
at System.Net.Http.HttpConnection.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
--- End of inner exception stack trace ---
at System.Net.Http.HttpConnection.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.WebSockets.WebSocketHandle.ConnectAsync(Uri uri, HttpMessageInvoker invoker, CancellationToken cancellationToken, ClientWebSocketOptions options)
at System.Net.WebSockets.WebSocketHandle.ConnectAsync(Uri uri, HttpMessageInvoker invoker, CancellationToken cancellationToken, ClientWebSocketOptions options)
at System.Net.WebSockets.ClientWebSocket.ConnectAsyncCore(Uri uri, HttpMessageInvoker invoker, CancellationToken cancellationToken)
at PuppeteerSharp.Transport.WebSocketTransport.CreateDefaultWebSocket(Uri url, IConnectionOptions options, CancellationToken cancellationToken) in /home/runner/work/puppeteer-sharp/puppeteer-sharp/lib/PuppeteerSharp/Transport/WebSocketTransport.cs:line 118
at PuppeteerSharp.Transport.WebSocketTransport.CreateDefaultTransport(Uri url, IConnectionOptions connectionOptions, CancellationToken cancellationToken) in /home/runner/work/puppeteer-sharp/puppeteer-sharp/lib/PuppeteerSharp/Transport/WebSocketTransport.cs:line 125
at PuppeteerSharp.Cdp.Connection.Create(String url, IConnectionOptions connectionOptions, ILoggerFactory loggerFactory, CancellationToken cancellationToken) in /home/runner/work/puppeteer-sharp/puppeteer-sharp/lib/PuppeteerSharp/Cdp/Connection.cs:line 151

Code :

                var chromeLocation = new ChromiumExtractor(new LoggerFactory().AddSerilog(Log.Logger)).ExtractChromium();

                var launchOptions = new LaunchOptions()
                {
                    ExecutablePath = chromeLocation,
                    Args = DefaultChromeArgs,
                    Headless = true,
                    Timeout = 0
                };

// var browserLauncher = new HeadlessChromiumPuppeteerLauncher(new LoggerFactory().AddSerilog(Log.Logger));
await using (var browser = await new Launcher(new LoggerFactory().AddSerilog(Log.Logger)).LaunchAsync(launchOptions))
{
await using var page = await browser.NewPageAsync();
await page.GoToAsync("http://www.google.com");
await page.EvaluateExpressionHandleAsync("document.fonts.ready");
context.Logger.LogInformation("EvaluateExpressionHandleAsync ");
var result = await page.PdfStreamAsync();
var fileTransferUtility = new TransferUtility(S3Client);
await fileTransferUtility.UploadAsync(result, report.BucketName, s3ObjectKey);
}

Dotnet Version : 8

Azure Pipeline Steps :

trigger:
branches:
include:
- refs/heads/lambda
resources:
repositories:

  • repository: self
    type: git
    ref: refs/heads/lambda
    jobs:
  • job: Job_1
    displayName: Agent job 1
    pool:
    vmImage: ubuntu-latest
    steps:
    • checkout: self
    • task: NuGetAuthenticate@1
      displayName: NuGet Authenticate
      inputs:
      forceReinstallCredentialProvider: true
    • task: DotNetCoreCLI@2
      displayName: dotnet restore
      inputs:
      command: restore
      projects: PIB.DocumentGeneration/PIB.DocumentGeneration.csproj
      feedRestore: d80f8f22-ac95-4ca4-aefb-24ca67302a57
    • task: DotNetCoreCLI@2
      displayName: dotnet publish
      inputs:
      command: publish
      publishWebProjects: false
      projects: PIB.DocumentGeneration/PIB.DocumentGeneration.csproj
      arguments: --configuration $(Build.Configuration) --output $(Build.ArtifactStagingDirectory)/dist/release/app -p:PublishReadyToRun=false
      zipAfterPublish: false
      modifyOutputPath: false
    • task: PublishBuildArtifacts@1
      displayName: 'Publish Artifact: drop'
    • task: ArchiveFiles@2
      displayName: Archive $(Build.ArtifactStagingDirectory)/dist/release/app/
      inputs:
      rootFolderOrFile: $(Build.ArtifactStagingDirectory)/dist/release/app/
      includeRootFolder: false
      archiveFile: $(Build.ArtifactStagingDirectory)/dist/release/test.zip
    • task: AmazonWebServices.aws-vsts-tools.S3Upload.S3Upload@1
      displayName: 'S3 Upload: optis-pipeline'
      inputs:
      awsCredentials: 7d33f0c0-8c2d-4058-862d-76bf06d51e82-123
      regionName: eu-west-2
      bucketName: optis-pipeline
      sourceFolder: $(Build.ArtifactStagingDirectory)/dist/release
      globExpressions: test.zip
      targetFolder: DEV/
      filesAcl: bucket-owner-read
      createBucket: true
    • task: AmazonWebServices.aws-vsts-tools.AWSCLI.AWSCLI@1
      displayName: 'AWS CLI: lambda'
      inputs:
      awsCredentials: 7d33f0c0-8c2d-4058-862d-76bf06d51e82-123
      regionName: eu-west-1
      awsCommand: lambda
      awsSubCommand: update-function-code
      awsArguments: --function-name local-testdocument --s3-bucket test --s3-key DEV/test.zip
      failOnStandardError: false

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions