lighthouse-plugin-publisher-ads/audits/script-injected-tags.js
/**
 * Finds requests for tags that could have been loaded statically but were not.
 * @param {LH.Artifacts} artifacts
 * @param {LH.Audit.Context} context
 * @return {Promise<NetworkRequest[]>}
 */
Finds requests for tags that could have been loaded statically but were not.
Finds requests for tags that could have been loaded statically but were not .
async function findStaticallyLoadableTags(artifacts, context) {
  const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
  const trace = artifacts.traces[Audit.DEFAULT_PASS];
  const tagReqs = [];
  const criticalRequests =
    await computeAdRequestWaterfall(trace, devtoolsLog, context);
  for (const {record} of criticalRequests) {
    if (!record || record.resourceType !== 'Script') {
      continue;
    }
    if (initiatedByInlineScript(record) ||
      STATICALLY_LOADABLE_TAGS.find((t) => record.url.match(t))) {
      tagReqs.push(record);
    }
  }
  return tagReqs;
}
async function findStaticallyLoadableTags ( artifacts , context ) { const devtoolsLog = artifacts . devtoolsLogs [ Audit . DEFAULT_PASS ] ; const trace = artifacts . traces [ Audit . DEFAULT_PASS ] ; const tagReqs = [ ] ; const criticalRequests = await computeAdRequestWaterfall ( trace , devtoolsLog , context ) ; for ( const { record } of criticalRequests ) { if ( ! record || record . resourceType !== 'Script' ) { continue ; } if ( initiatedByInlineScript ( record ) || STATICALLY_LOADABLE_TAGS . find ( ( t ) => record . url . match ( t ) ) ) { tagReqs . push ( record ) ; } } return tagReqs ; }
Finds requests for tags that could have been loaded statically but were not.
Finds requests for tags that could have been loaded statically but were not .
// Next add any scripts that appear that they can be loaded statically based // on page analysis. // Don't count resources that aren't scripts.