Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var logs = _this.driver.getLogs('performance');
// in one instance, logs was not iterable for some reason - hence the following check:
if (!logs || typeof logs[Symbol.iterator] !== 'function') {
console.error('harGet: logs not iterable: ' + JSON.stringify(logs));
return null;
}
var events = [];
for (var log of logs) {
var msgObj = JSON.parse(log.message); // returned as string
events.push(msgObj.message);
}
try {
const har = harFromMessages(events);
return JSON.stringify(har);
} catch (e) {
console.error('Unable to fetch HAR: ' + e.toString());
return null;
}
}
}
}
};
if (result.cpu) {
result.cpu.longTasks = cpu.longTasks;
} else {
result.cpu = cpu;
}
}
// CLEANUP since Chromedriver 2.29 there's a bug
// https://bugs.chromium.org/p/chromedriver/issues/detail?id=1811
await runner.getLogs(Type.PERFORMANCE);
const har = perflogParser.harFromMessages(messages);
if (
this.chrome.includeResponseBodies === 'html' ||
this.chrome.includeResponseBodies === 'all'
) {
await this.cdpClient.setResponseBodies(har);
}
const versionInfo = (await this.cdpClient.send(
'Browser.getVersion'
)).product.split('/');
const info = {
name: versionInfo[0],
version: versionInfo[1]
};
async afterPass(passContext, loadData) {
/** @type {Array} */
const networkEvents = this.devtoolsEvents_.slice();
log.log('Debug', 'Network: Get trace snapshot');
const har = chromeHar.harFromMessages(networkEvents);
const parsedUrls = har.log.entries.map((e) => new URL(e.request.url));
if (isDebugMode()) {
// These entries are present in our network artifacts, but are missing in
// the builtin loadData network records.
const missingEntries =
findMissingEntries(har.log.entries, loadData.networkRecords);
missingEntries.forEach((entry) => {
log.warn('Debug', 'Missing URL', entry.request.url.substr(0, 100));
});
}
return {har, networkEvents, parsedUrls};
}
}
stop(zip?: JSZip) {
chrome.debugger.onEvent.removeListener(this.onEvent);
chrome.debugger.detach(this.debuggee, () => {
const lastError = chrome.runtime.lastError;
if (lastError !== undefined) {
console.warn(lastError.message);
}
});
const harOptions = {
includeResourcesFromDiskCache: true,
includeTextFromResponseBody: true
};
const har = harFromMessages(this.harEvents, harOptions);
const log = this.logEntries
.map(entry => {
const value = entry.args.map((arg: LogEntryArg) => arg.value).join(" ");
const timestamp = new Date(entry.timestamp).toISOString();
return `${entry.type} ${timestamp} ${value}`;
})
.join("\n");
const exceptionLogs = this.exceptions
.map(exceptionParams => {
const timestamp = new Date(exceptionParams.timestamp).toISOString();
return `${timestamp} ${exceptionParams.exceptionDetails.exception.description}`;
})
.join("\n");
async stop() {
this.inProgress = false;
await Promise.all(this.response_body_promises);
await this.client.detach();
const har = harFromMessages(
this.page_events.concat(this.network_events),
{includeTextFromResponseBody: this.saveResponse}
);
this.cleanUp();
if (this.path) {
await promisify(fs.writeFile)(this.path, JSON.stringify(har));
} else {
return har;
}
}
}