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

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

Closed
satviktechie1986 opened this issue Oct 28, 2024 · 1 comment
Closed

Comments

@satviktechie1986
Copy link

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
@kblok
Copy link
Member

kblok commented Oct 28, 2024

Duplicated of #2785

@kblok kblok closed this as not planned Won't fix, can't repro, duplicate, stale Oct 28, 2024
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

2 participants