You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//App Moduleimport{Injectable}from"@nestjs/common";import{ConfigModule}from'@nestjs/config';//App Moduleimport{CertificateDetailsService}from"src/modules/certificate_details/certificate_details.service";// import { constantData } from '../common/constant/certificate_constant';//Thirdy Party Moduleimport*asfsfrom'fs';importaws_sdkfrom'aws-sdk';importpuppeteerfrom'puppeteer-core';importchromiumfrom'@sparticuz/chromium';consthbs=require('handlebars');ConfigModule.forRoot();
@Injectable()exportclassGeneratePdf{data={};constructor(privatereadonlycertificatedetailsservice: CertificateDetailsService){}/** * generate pdf and upload */asyncgetDetails(dataFinal,certificateDet){try{returnnewPromise(async(resolve,reject)=>{this.data=dataFinal;leturl=awaitthis.uploadToS3(certificateDet);resolve(url)})// this.data = dataFinal;// this.uploadToS3(certificateDet)}catch(e){throwe}}/** * get the certificate html and attach hbs and compile * @returns HTML string */asyncinjectDataToPdf(){try{consthtml=fs.readFileSync(__dirname+'/ecert.hbs','utf-8');constpdf_html=hbs.compile(html)(this.data);returnpdf_html;}catch(e){throwe}}/** * create and upload the pdf and create new record into certificate_details table */asyncuploadToS3(certificateDet){try{returnnewPromise(async(resolve,reject)=>{console.log('PDF uploaded successfully:');consts3=newaws_sdk.S3({region: "ap-south-1",// credentials,});console.log('PDF uploaded successfully:2');constbrowser=awaitpuppeteer.launch({args: chromium.args,defaultViewport: chromium.defaultViewport,executablePath: awaitchromium.executablePath(),headless: chromium.headless,ignoreHTTPSErrors: true,});console.log('PDF uploaded successfully:3');constpage=awaitbrowser.newPage();constcontent=awaitthis.injectDataToPdf();awaitpage.setContent(content,{waitUntil: "networkidle2",timeout: 60000});// Increase timeout to 60 secondsawaitpage.waitForSelector('img');constpdfBuffer=awaitpage.pdf({format: 'A4',printBackground: true,headerTemplate: "<div>header</div>",footerTemplate: "<div>footer</div>"});constcurrentTimestampSeconds=Math.floor(Date.now()/1000);constuploadParams={Bucket: process.env.ECERTIFICATE_BUCKET,Key: this.data["certificate_no"]+"_"+currentTimestampSeconds+".pdf",Body: pdfBuffer,ACL: 'public-read'//enable it for stage};s3.upload(uploadParams,async(err,data)=>{if(err){console.error('Error uploading PDF to S3:',err);}else{console.log('PDF uploaded successfully:',data.Location);awaitthis.certificatedetailsservice.createRecord(certificateDet,uploadParams["Key"],this.data);this.flushData();}browser.close();resolve("pdf generated")});});}catch(error){console.error('Error generating PDF:',error);}}flushData(){this.data={};}}
Error string
Navigation failed because browser has disconnected!
Bug behavior
Flaky
PDF
Background
No response
Expectation
it should not show the error
Reality
it is showing this error
Puppeteer configuration file (if used)
No response
Puppeteer version
"puppeteer": "^19.11.1",
Node version
18
Package manager
npm
Package manager version
10.2.3
Operating system
Linux
The text was updated successfully, but these errors were encountered:
Is this on AWS Lambda? This indicates that the browser crashes during navigation. Please report the issue to @sparticuz/chromium as those are not builds we support. If you can re-produce it with bundles Chrome for Testing binaries outside of Lambda, please provide a minimal reproducible example.
Minimal, reproducible example
Error string
Navigation failed because browser has disconnected!
Bug behavior
Background
No response
Expectation
it should not show the error
Reality
it is showing this error
![Screenshot 2024-05-06 at 2 39 24 PM](https://private-user-images.githubusercontent.com/44834497/328130492-1e56601b-7b3e-48e8-8ef5-7fdca7af7c49.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTkwMDU2NzgsIm5iZiI6MTcxOTAwNTM3OCwicGF0aCI6Ii80NDgzNDQ5Ny8zMjgxMzA0OTItMWU1NjYwMWItN2IzZS00OGU4LThlZjUtN2ZkY2E3YWY3YzQ5LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MjElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjIxVDIxMjkzOFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTNjN2M1Nzc1NzlmMjgwNDI4ZTIzMWVkOGM5ZGExOGQ1YTg3OTk1YzhkZGE2ZTE0OTAyZmEyNTM4YjNhYmE0YmYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.772vYQu1hpClz7CD6sPS4-XBClZkNLLP7aGaKtOgQL8)
Puppeteer configuration file (if used)
No response
Puppeteer version
Node version
18
Package manager
npm
Package manager version
10.2.3
Operating system
Linux
The text was updated successfully, but these errors were encountered: