How to use the lighthouse/lighthouse-core/computed/main-resource.request function in lighthouse

To help you get started, we’ve selected a few lighthouse examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github googleads / publisher-ads-lighthouse-plugin / lighthouse-plugin-publisher-ads / audits / duplicate-tags.js View on Github external
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);
    }
github googleads / publisher-ads-lighthouse-plugin / lighthouse-plugin-publisher-ads / audits / serial-header-bidding.js View on Github external
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)) {
github googleads / publisher-ads-lighthouse-plugin / lighthouse-plugin-publisher-ads / audits / async-ad-tags.js View on Github external
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,
    };
  }
}