How to use the lighthouse.Audit.DEFAULT_PASS 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 / first-ad-render.js View on Github external
static async audit(artifacts, context) {
    const trace = artifacts.traces[Audit.DEFAULT_PASS];
    const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
    const metricData = {
      devtoolsLog,
      trace,
      settings: context.settings,
    };
    const {timing} = await ComputedAdRenderTime.request(metricData, context);

    if (!(timing > 0)) { // Handle NaN, etc.
      context.LighthouseRunWarnings.push(runWarning.NoAdRendered);
      return auditNotApplicable.NoAdRendered;
    }

    const scoreOptions =
      context.options[global.isLightrider ? 'default' : 'lightrider'];

    return {
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.
github googleads / publisher-ads-lighthouse-plugin / lighthouse-plugin-publisher-ads / audits / bid-request-from-page-start.js View on Github external
static async audit(artifacts, context) {
    const trace = artifacts.traces[Audit.DEFAULT_PASS];
    const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
    const metricData = {trace, devtoolsLog, settings: context.settings};

    const {timing} = await ComputedBidRequestTime.request(metricData, context);
    if (!(timing > 0)) { // Handle NaN, etc.
      return auditNotApplicable.NoBids;
    }

    return {
      numericValue: timing * 1e-3,
      score: Audit.computeLogNormalScore(
        timing,
        context.options.scorePODR,
        context.options.scoreMedian
      ),
      displayValue: str_(UIStrings.displayValue, {timeInMs: timing}),
github thegreenwebfoundation / lighthouse-plugin-greenhouse / src / audits / greenhouse-audit.js View on Github external
static async audit(artifacts, context) {
    // Artifacts requested in `requiredArtifacts` above are passed to your audit.
    // See the "API -> Plugin Audits" section below for what artifacts are available.

    try {
      const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
      const requests = await NetworkRecords.request(devtoolsLog, context);

      let domains = new Set()
      requests.forEach(req => {
        domains.add(new URL(req.url).host)
      })

      // the spread syntax turns our deduped set into an array, then makes sure they're long enough to check
      const domainArray = [...domains].filter(domain => domain.length > 2)

      const checkResults = await Greencheck.checkDomains(domainArray)

      const greyDomainResults = checkResults.greenChecks.filter(res => res.green == false)
      const tableDetails = GreenAudit.convertToTableDetails(checkResults.greenChecks)
      return {
        score: checkResults.score,
github googleads / publisher-ads-lighthouse-plugin / lighthouse-plugin-publisher-ads / audits / ad-render-blocking-resources.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 networkRecords = await NetworkRecords.request(devtoolsLog, context);
    const tag = networkRecords.find((req) => isAdTag(new URL(req.url)));
    if (!tag) {
      return auditNotApplicable.NoTag;
    }

    /** @type {Map} */
    const timingsByRecord =
      await getTimingsByRecord(trace, devtoolsLog, context);

    // NOTE(warrengm): Ideally we would key be requestId here but LinkElements
    // don't have request IDs.
    /** @type {Set} */
    const blockingElementUrls = new Set();
    for (const link of artifacts.LinkElements) {
      // TODO(warrengm): Check for media queries? Or is the network filter below
github googleads / publisher-ads-lighthouse-plugin / lighthouse-plugin-publisher-ads / audits / bid-request-from-page-start.js View on Github external
static async audit(artifacts, context) {
    const trace = artifacts.traces[Audit.DEFAULT_PASS];
    const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
    const metricData = {trace, devtoolsLog, settings: context.settings};

    const {timing} = await ComputedBidRequestTime.request(metricData, context);
    if (!(timing > 0)) { // Handle NaN, etc.
      return auditNotApplicable.NoBids;
    }

    return {
      numericValue: timing * 1e-3,
      score: Audit.computeLogNormalScore(
        timing,
        context.options.scorePODR,
        context.options.scoreMedian
      ),
      displayValue: str_(UIStrings.displayValue, {timeInMs: timing}),
    };
github googleads / publisher-ads-lighthouse-plugin / lighthouse-plugin-publisher-ads / audits / loads-gpt-from-sgdn.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 gptUrl = networkRecords.map((r) => new URL(r.url)).find(isGptTag);
    if (!gptUrl) {
      return auditNotApplicable.NoGpt;
    }
    const passed = (gptUrl.host === 'securepubads.g.doubleclick.net');
    return {
      score: Number(passed),
      numericValue: Number(!passed),
    };
  }
}
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,
github googleads / publisher-ads-lighthouse-plugin / lighthouse-plugin-publisher-ads / audits / full-width-slots.js View on Github external
static async audit(artifacts, context) {
    const devtoolsLogs = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
    const networkRecords = await NetworkRecords.request(devtoolsLogs, context);
    const viewport = artifacts.ViewportDimensions;
    const vpWidth = viewport.innerWidth;

    /** @type {Array} */
    const adRequestUrls = networkRecords
        .filter(isAdRequest)
        .map((record) => new URL(record.url));

    if (!adRequestUrls.length) {
      return auditNotApplicable.NoAds;
    }

    const sizeArrs = adRequestUrls.map((url) =>
      url.searchParams.get('prev_iu_szs') || url.searchParams.get('sz'));