Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
static async audit(artifacts, context) {
const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
const networkRecords = await NetworkRecords.request(devtoolsLog, context);
const mainResource =
await MainResource.request({URL: artifacts.URL, devtoolsLog}, context);
const tagReqs = networkRecords
.filter((r) => r.frameId === mainResource.frameId)
.filter((r) => containsAnySubstring(r.url, tags))
.filter((r) => (r.resourceType === NetworkRequest.TYPES.Script));
if (!tagReqs.length) {
return auditNotApplicable.NoTags;
}
/** @type {Map} */
const tagCounts = new Map;
for (const record of tagReqs) {
// Groups by path to account for scripts hosted on multiple domains.
const script = new URL(record.url).pathname;
const count = tagCounts.get(script) || 0;
tagCounts.set(script, count + 1);
}
static async audit(artifacts, context) {
const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
const trace = artifacts.traces[Audit.DEFAULT_PASS];
const unfilteredNetworkRecords =
await NetworkRecords.request(devtoolsLog, context);
if (!unfilteredNetworkRecords.length) {
return auditNotApplicable.NoRecords;
}
const mainResource =
await MainResource.request({URL: artifacts.URL, devtoolsLog}, context);
// Filter out requests without responses, image responses, and responses
// taking less than 50ms.
const networkRecords = unfilteredNetworkRecords
.filter(isPossibleBid)
.filter((r) => r.frameId == mainResource.frameId);
// We filter for URLs that are related to header bidding.
// Then we create shallow copies of each record. This is because the records
// by default have circular structure, which causes an error to be thrown
// when we return them unmodified in the details field of the audit.
// So, we create objects that only have the relevant information, and return
// in the details field.
const recordsByType = bucket(networkRecords, checkRecordType);
if (!recordsByType.has(RequestType.BID)) {
static async audit(artifacts, context) {
const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
const networkRecords = await NetworkRecords.request(devtoolsLog, context);
const mainResource =
await MainResource.request({URL: artifacts.URL, devtoolsLog}, context);
const tagReqs = networkRecords
.filter((req) => isAdTag(new URL(req.url)))
.filter((req) => req.frameId === mainResource.frameId);
if (!tagReqs.length) {
return auditNotApplicable.NoTag;
}
const numSync = array.count(tagReqs, isAsync) - tagReqs.length;
const passed = (numSync === 0);
return {
score: Number(passed),
numericValue: numSync,
};
}
}