lighthouse-plugin-publisher-ads/utils/graph.js
/**
 * Returns all requests in the loading graph of ads. This will return the empty
 * set if no ad requests are present.
 * @param {LH.Trace} trace
 * @param {LH.DevtoolsLog} devtoolsLog
 * @param {LH.Audit.Context} context
 * @return {Promise<SimpleRequest[]>}
 */
Returns all requests in the loading graph of ads. This will return the empty
set if no ad requests are present.
Returns all requests in the loading graph of ads . This will return the empty set if no ad requests are present .
async function computeAdRequestWaterfall(trace, devtoolsLog, context) {
  const networkRecords = await NetworkRecords.request(devtoolsLog, context);
  const maybeFirstAdRequest =
    networkRecords.find(isAdRequest) ||
    networkRecords.find(isBidRequest) || networkRecords.find(isAdRelated);
  if (maybeFirstAdRequest == null) {
    return Promise.resolve([]);
  }
  const criticalRequests = new Set();
  const firstAdRequest = assert(maybeFirstAdRequest);
  const tagRequests = networkRecords.filter((r) =>
    isGpt(r.url) || isAdSense(r.url));
  const bidRequests = networkRecords.filter((r) =>
    isBidRequest(r) && r.endTime <= firstAdRequest.startTime);
  const summary = buildNetworkSummary(networkRecords, trace.traceEvents);
  for (const req of [firstAdRequest, ...bidRequests, ...tagRequests]) {
    linkGraph(summary, req, criticalRequests);
  }
  const REQUEST_TYPES = new Set([
    'Script', 'XHR', 'Fetch', 'EventStream', 'Document', undefined]);
  const waterfall = Array.from(criticalRequests)
      .filter((r) => r.endTime < firstAdRequest.startTime)
      .filter((r) => REQUEST_TYPES.has(r.resourceType))
      .filter((r) => r.mimeType != 'text/css');
  const timingsByRecord =
      await getTimingsByRecord(trace, devtoolsLog, context);
  const timedWaterfall = waterfall.map((req) => {
    const {startTime, endTime} = timingsByRecord.get(req) || req;
    return {
      startTime,
      endTime,
      duration: endTime - startTime,
      selfTime: 0, 
      url: trimUrl(req.url),
      nameOrTld: getNameOrTld(req.url),
      type: req.resourceType,
      record: req,
    };
  });
  const result = computeSummaries(timedWaterfall);
  computeSelfTimes(result);
  return result;
}
async function computeAdRequestWaterfall ( trace , devtoolsLog , context ) { const networkRecords = await NetworkRecords . request ( devtoolsLog , context ) ; const maybeFirstAdRequest = networkRecords . find ( isAdRequest ) || networkRecords . find ( isBidRequest ) || networkRecords . find ( isAdRelated ) ; if ( maybeFirstAdRequest == null ) { return Promise . resolve ( [ ] ) ; } const criticalRequests = new Set ( ) ; const firstAdRequest = assert ( maybeFirstAdRequest ) ; const tagRequests = networkRecords . filter ( ( r ) => isGpt ( r . url ) || isAdSense ( r . url ) ) ; const bidRequests = networkRecords . filter ( ( r ) => isBidRequest ( r ) && r . endTime <= firstAdRequest . startTime ) ; const summary = buildNetworkSummary ( networkRecords , trace . traceEvents ) ; for ( const req of [ firstAdRequest , ... bidRequests , ... tagRequests ] ) { linkGraph ( summary , req , criticalRequests ) ; } const REQUEST_TYPES = new Set ( [ 'Script' , 'XHR' , 'Fetch' , 'EventStream' , 'Document' , undefined ] ) ; const waterfall = Array . from ( criticalRequests ) . filter ( ( r ) => r . endTime < firstAdRequest . startTime ) . filter ( ( r ) => REQUEST_TYPES . has ( r . resourceType ) ) . filter ( ( r ) => r . mimeType != 'text/css' ) ; const timingsByRecord = await getTimingsByRecord ( trace , devtoolsLog , context ) ; const timedWaterfall = waterfall . map ( ( req ) => { const { startTime , endTime } = timingsByRecord . get ( req ) || req ; return { startTime , endTime , duration : endTime - startTime , selfTime : 0 , url : trimUrl ( req . url ) , nameOrTld : getNameOrTld ( req . url ) , type : req . resourceType , record : req , } ; } ) ; const result = computeSummaries ( timedWaterfall ) ; computeSelfTimes ( result ) ; return result ; }
Returns all requests in the loading graph of ads.
Returns all requests in the loading graph of ads .
// Fallback to another ad request /** @type {Map<NetworkRequest, NodeTiming>} */ // Computed below.