Skip to content

Bypass certificate errors ("Your connection is not private")

Andrea Cardaci edited this page May 9, 2017 · 2 revisions

This warning page is modal and requires user action which cannot happen in headless mode thus causing the page loading to hang. The following example shows how to override certificate errors.

const CDP = require('chrome-remote-interface');

CDP(async (client) => {
    const {Page, Security} = client;
    // ignore all the certificate errors
    Security.certificateError(({eventId}) => {
        Security.handleCertificateError({
            eventId,
            action: 'continue'
        });
    });
    try {
        await Page.enable();
        await Security.enable();
        // enable the override
        await Security.setOverrideCertificateErrors({override: true});
        // load the URL as usual
        await Page.navigate({url: 'https://93.184.216.34'}); // example.com
        await Page.loadEventFired();
        console.log('Finished!');
    } catch (err) {
        console.error(err);
    } finally {
        await client.close();
    }
}).on('error', (err) => {
    console.error(err);
});