Chrome-remote-interface: how to get This site can鈥檛 be reached event?

Created on 14 May 2017  路  2Comments  路  Source: cyrus-and/chrome-remote-interface

for example,let's run Page.navigate({url:'http://cant.reached.com'})
browser can't reach to this site,is there a event will be fired when site can鈥檛 be reached ?
from Page doc can't find any about it.

protocol question

All 2 comments

You need to keep track of the first request, if it fails then you can assume that the page is failed. AFAIK there's no easier way to accomplish that.

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

CDP(async (client) => {
    const {Page, Network} = client;
    let requestId;
    let failed = false;
    Network.requestWillBeSent((params) => {
        requestId = params.requestId;
    });
    Network.loadingFailed((params) => {
        if (params.requestId === requestId) {
            failed = true;
        }
    });
    Page.loadEventFired(() => {
        if (failed) {
            console.log('FAIL');
        } else {
            console.log('OK');
        }
        client.close();
    });
    try {
        await Page.enable();
        await Network.enable();
        await Page.navigate({url: 'http://cantreached.com'});
    } catch (err) {
        console.error(err);
    }
}).on('error', (err) => {
    console.error(err);
});

Note cant.reached.com can actually be reached :)

you are awesome馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

westy92 picture westy92  路  7Comments

hbakhtiyor picture hbakhtiyor  路  7Comments

paambaati picture paambaati  路  7Comments

sergueyarellano picture sergueyarellano  路  6Comments

Bnaya picture Bnaya  路  4Comments