Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_shouldToggleDomain(domain, sessionId, enable) {
const key = domain + (sessionId || '');
const enabledCount = this._domainEnabledCounts.get(key) || 0;
const newCount = enabledCount + (enable ? 1 : -1);
this._domainEnabledCounts.set(key, Math.max(0, newCount));
// Switching to enabled or disabled, respectively.
if ((enable && newCount === 1) || (!enable && newCount === 0)) {
log.verbose('Driver', `${domain}.${enable ? 'enable' : 'disable'}`);
return true;
} else {
if (newCount < 0) {
log.error('Driver', `Attempted to disable domain '${domain}' when already disabled.`);
}
return false;
}
}
const status = {
msg: 'Retrieving devtoolsLog & network records',
id: `lh:gather:getDevtoolsLog`,
};
log.time(status);
const devtoolsLog = driver.endDevtoolsLog();
const networkRecords = NetworkRecorder.recordsFromLogs(devtoolsLog);
log.timeEnd(status);
let pageLoadError = GatherRunner.getPageLoadError(passContext.url, networkRecords);
// If the driver was offline, a page load error is expected, so do not save it.
if (!driver.online) pageLoadError = undefined;
if (pageLoadError) {
log.error('GatherRunner', pageLoadError.message, passContext.url);
passContext.LighthouseRunWarnings.push(pageLoadError.friendlyMessage);
}
// Expose devtoolsLog, networkRecords, and trace (if present) to gatherers
/** @type {LH.Gatherer.LoadData} */
const passData = {
networkRecords,
devtoolsLog,
trace,
};
const apStatus = {msg: `Running afterPass methods`, id: `lh:gather:afterPass`};
// Disable throttling so the afterPass analysis isn't throttled
await driver.setThrottling(passContext.settings, {useThrottling: false});
log.time(apStatus, 'verbose');
if (line === null) {
log.error('BundleAnalysis', `${map.url()} mapping for line out of bounds: ${lineNum + 1}`);
return failureResult;
}
if (colNum > line.length) {
// eslint-disable-next-line max-len
log.error('BundleAnalysis', `${map.url()} mapping for column out of bounds: ${lineNum + 1}:${colNum}`);
return failureResult;
}
let mappingLength = 0;
if (lastColNum !== undefined) {
if (lastColNum > line.length) {
// eslint-disable-next-line max-len
log.error('BundleAnalysis', `${map.url()} mapping for last column out of bounds: ${lineNum + 1}:${lastColNum}`);
return failureResult;
}
mappingLength = lastColNum - colNum;
} else {
// TODO Buffer.byteLength?
// Add +1 to account for the newline.
mappingLength = line.length - colNum + 1;
}
files[source] = (files[source] || 0) + mappingLength;
unmappedBytes -= mappingLength;
}
return {
files,
unmappedBytes,
totalBytes,
.catch(err => {
if (retries > launcher.maxConnectionRetries) {
log.error('ChromeLauncher', err.message);
const stderr =
this.fs.readFileSync(`${this.userDataDir}/chrome-err.log`, {encoding: 'utf-8'});
log.error(
'ChromeLauncher', `Logging contents of ${this.userDataDir}/chrome-err.log`);
log.error('ChromeLauncher', stderr);
return reject(err);
}
delay(launcher.connectionPollInterval).then(poll);
});
};
}).catch(err => {
log.error('PerformanceXServer', err.code, err);
response.writeHead(500);
response.end(http.STATUS_CODES[500]);
});
});
.catch(function (err) {
if (retries > launcher.maxConnectionRetries) {
log.error('ChromeLauncher', err.message);
var stderr = _this.fs.readFileSync(_this.userDataDir + "/chrome-err.log", { encoding: 'utf-8' });
log.error('ChromeLauncher', "Logging contents of " + _this.userDataDir + "/chrome-err.log");
log.error('ChromeLauncher', stderr);
return reject(err);
}
utils_1.delay(launcher.connectionPollInterval).then(poll);
});
};
generateFakeEvents() {
const metrics = this.gatherMetrics();
if (metrics.length === 0) {
log.error('metrics-events', 'Metrics collection had errors, not synthetizing trace events');
return [];
}
const navigationStartEvt = this.getNavigationStartEvt(metrics);
if (!navigationStartEvt) {
log.error('pwmetrics-events', 'Reference navigationStart not found');
return [];
}
/** @type {Array} */
const fakeEvents = [];
metrics.forEach(metric => {
if (metric.id === 'navstart') {
return;
}
if (!metric.ts) {
return this._queryCurrentTab().then(tab => {
if (!tab.url) {
log.error('ExtensionConnection', 'getCurrentTabURL returned empty string', tab);
throw new Error('getCurrentTabURL returned empty string');
}
return tab.url;
});
}
generateFakeEvents() {
const metrics = this.gatherMetrics();
if (metrics.length === 0) {
log.error('metrics-events', 'Metrics collection had errors, not synthetizing trace events');
return [];
}
const navigationStartEvt = this.getNavigationStartEvt(metrics);
if (!navigationStartEvt) {
log.error('pwmetrics-events', 'Reference navigationStart not found');
return [];
}
/** @type {Array} */
const fakeEvents = [];
metrics.forEach(metric => {
if (metric.id === 'navstart') {
return;
}
if (!metric.ts) {
log.error('pwmetrics-events', `(${metric.name}) missing timestamp. Skipping…`);
return;
}
log.verbose('pwmetrics-events', `Sythesizing trace events for ${metric.name}`);
fakeEvents.push(...this.synthesizeEventPair(metric, navigationStartEvt));
});
.catch(err => {
if (retries > launcher.maxConnectionRetries) {
log.error('ChromeLauncher', err.message);
const stderr =
this.fs.readFileSync(`${this.userDataDir}/chrome-err.log`, {encoding: 'utf-8'});
log.error(
'ChromeLauncher', `Logging contents of ${this.userDataDir}/chrome-err.log`);
log.error('ChromeLauncher', stderr);
return reject(err);
}
delay(launcher.connectionPollInterval).then(poll);
});
};