Chrome-har
创建 哈尔 基于的文件 Chrome DevTools协议 数据。
我们已经厌倦了等待b谷歌的3万多名工程师实现一种自动获取HAR文件的方法 https://issues.chromium.org/issues/40809195 因此,我们同时实现了自己的解决方案。
最初从 Browsertime,初步实施的灵感来源于 Chromedriver_har.
创建一个新的bug报告
确保生成一个事件跟踪日志文件,我们可以使用它来重新创建您的问题。如果使用Browsertime,则可以使用 --chrome.collectPerfLog:
$ browsertime --chrome.collectPerfLog -n 1 https://www.sitespeed.io
然后取文件名 chromeperflog json.gz——1. 把它放在要点中,或者以任何你想要的方式提供给我们。
如果你使用sitesspeed .io:
$ sitespeed.io --browsertime.chrome.collectPerfLog -n 1 https://www.sitespeed.io
流消息
harFromMessages 接受消息数组(或任何可迭代对象)。如果消息来自流,则使用 harFromMessagesAsync。它接受一个异步可迭代对象,在消息到达时处理每个消息,并为HAR返回一个承诺。您不需要将所有消息都保存在内存中。
import { harFromMessagesAsync } from 'chrome-har';
const har = await harFromMessagesAsync(messageStream);
支援响应机构
如果你使用Chrome-har独立(没有Browsertime/站点速度。如果在HARs中设置了响应体,则可以在HARs中使用get 响应对象 由呼叫者和如果 includeTextFromResponseBody 选项设置为 true.
例如:
const harEvents: Array<any> = [];
client.on('Network.requestIntercepted', async (params: any) => {
// Get the response body
const response = await client.send(
'Network.getResponseBodyForInterception',
{ interceptionId: params.interceptionId },
);
// Set the body on the response object
if (params.response != null) {
params.response.body = response.body;
} else {
params.response = response;
}
// Continue the request
await client.send(
'Network.continueInterceptedRequest',
{ interceptionId: params.interceptionId },
);
harEvents.push({ method, params });
});
const har = harFromMessages(harEvents, {includeTextFromResponseBody: true});