2017-09-24 136 views
1

我有一個木偶專家的問題。 所以我想要做的是啓動一個網站和登錄。但是,該網站嘗試加載因其不安全而被阻止的資源。運行代碼後,我收到此錯誤信息和代碼停止運行:node.js中的SSL證書錯誤

(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. 

我的代碼:

'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'); 

這就是鉻consule推出:

Failed to load resource: net::ERR_INSECURE_RESPONSE 

我的環境: 最新木偶版/ Windows 10

回答

3

ignoreHTTPSErrors: true。注意:這將忽略所有SSL錯誤。

'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');