Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

puppeteer
ssl
network security
browser

SSL certificate in puppeteer

Educative Answers Team

Puppeteer is a Node library used for browser automation.

You can use Puppeteer to get the security details of a request, including information about the SSL certificate.
As of puppeteer v1.7.0, you can use the Network.SecurityDetails class to inspect details of the certificate.

Syntax

response.securityDetails()

Returns an object that contains the following certificate security details: subject name, issuer name, protocol, and the beginning and the end of the certificate’s validity. You can access these properties using the following methods.

Method Description
securityDetails.issuer() Returns a string with the name of certificate’s issuer.
securityDetails.protocol() Returns a string with the security protocol, e.g., “TLS 1.2.”
securityDetails.subjectName() Returns the name of the subject that the certificate was issued to.
securityDetails.validFrom() Returns the UnixTime number, which states the beginning of the certificate’s validity.
securityDetails.validTo() Returns the UnixTime number, which states the end of the certificate’s validity.

Code

Let’s try to get the security details of the example website https://example.com/.

We will get the security details as an object and store it as securityDetails variable. We can then use the methods listed above to get the certificate’s details.

const browser = await puppeteer.launch();

const page = await browser.newPage();

const pageUrl = 'https://example.com/'
const response = await page.goto(pageUrl, {waitUntil: 'networkidle0'})
const securityDetails = await response.securityDetails()

console.log(securityDetails)
console.log(securityDetails.protocol())

await browser.close();

RELATED TAGS

puppeteer
ssl
network security
browser
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring