Network.emulateNetworkConditions在chrome 59中不起作用 - 无头

时间:2017-06-07 21:43:18

标签: javascript performance google-chrome google-chrome-devtools headless-browser

我正在尝试使用chrome-remote-interface example作为起点,在chrome --headless(Chrome版本59)中模拟常规3G连接

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

CDP(async (client) => {
    try {
        const {Page, Tracing, Network} = client;

        Network.emulateNetworkConditions({
            offline: false,
            latency: 100,
            downloadThroughput: 750 * 1024 / 8,
            uploadThroughput: 250 * 1024 / 8
        });

        await Promise.all([Network.enable(), Page.enable()]);

        const { result } = await Network.canEmulateNetworkConditions();
        console.log(result); // always false

        // trace a page load
        const events = [];
        Tracing.dataCollected(({value}) => {
            events.push(...value);
        });
        await Tracing.start();
        await Page.navigate({url: 'https://github.com'});
        await Page.loadEventFired();
        await Tracing.end();
        await Tracing.tracingComplete();
        // save the tracing data
        fs.writeFileSync('./timeline.json', JSON.stringify(events));
    } catch (err) {
        console.error(err);
    } finally {
        await client.close();
    }
}).on('error', (err) => {
    console.error(err);
});

Network.emulateNetworkConditions似乎没有用。要证明Network.canEmulateNetworkConditions()始终返回false。没有--headless标记Network.canEmulateNetworkConditions()会返回true

chrome-canary --headless(第61版)给出了相同的结果。

我的示例是否包含错误或chrome 59目前缺少此功能?

0 个答案:

没有答案