Search code examples
javascriptnode.jssslwebautomationpuppeteer

SSL Certificate error in node.js


I´m having an issue with puppeteer. So what I want to do is to launch a website and login. However, this website tries to load a resource which is blocked because its insecure. After running the code I get this error message and the code stops running:

(node:11684) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: SSL Certificate error: ERR_CERT_COMMON_NAME_INVALID
(node:11684) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

My code:

'use strict';

const puppeteer = require('puppeteer');

async function Login(username, password){
  const browser = await puppeteer.launch({
    headless: false
  });
  const page = await browser.newPage();
  await page.goto('https://shop.adidas.ae/en/customer/account/login', {waitUntil: 'networkidle'});
  /*await page.type(username);
  await page.focus('#pass');
  await page.type(password);
  await page.click('#send2');*/
  await browser.close();
}

Login('xxx', 'xxx');

This is what the chrome consule puts out:

Failed to load resource: net::ERR_INSECURE_RESPONSE

My enviroment: Latest Puppeteer version / Windows 10


Solution

  • Set ignoreHTTPSErrors: true. Beware: this will ignore all SSL errors.

    'use strict';
    
    const puppeteer = require('puppeteer');
    
    async function Login(username, password){
      const browser = await puppeteer.launch({
        headless: false,
        ignoreHTTPSErrors: true
      });
      const page = await browser.newPage();
      await page.goto('https://shop.adidas.ae/en/customer/account/login', {waitUntil: 'networkidle'});
      /*await page.type(username);
      await page.focus('#pass');
      await page.type(password);
      await page.click('#send2');*/
      await browser.close();
    }
    
    Login('xxx', 'xxx');