Маяк пользовательский объект ответа - PullRequest
0 голосов
/ 15 марта 2019

Можно ли указать, какие свойства следует добавить в объект ответа lighthouse?

Например, я хочу исключить свойства lhr.i18n и artifacts.Это текущая структура объекта маяка (более вероятно, что в дополнение к ним есть еще свойства):

{
  "lhr": {
    "userAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/72.0.3626.121 Safari/537.36",
    "environment": {
      "networkUserAgent": "Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3694.0 Mobile Safari/537.36 Chrome-Lighthouse",
      "hostUserAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/72.0.3626.121 Safari/537.36",
      "benchmarkIndex": 424
    },
    "lighthouseVersion": "4.2.0",
    "fetchTime": "2019-03-14T14:30:25.256Z",
    "requestedUrl": "https://www.realtor.com/",
    "finalUrl": "https://www.realtor.com/",
    "runWarnings": [],
    "audits": { ... },
    "i18n": { ... },
  }
  "artifacts": { ... }
} 

Я пытался добиться этого с помощью пользовательской конфигурации:

const UIStrings = {
  performanceCategoryTitle: 'Performance',
  metricGroupTitle: 'Metrics',
  loadOpportunitiesGroupTitle: 'Opportunities',
  loadOpportunitiesGroupDescription: 'These optimizations can speed up your page load.',
  diagnosticsGroupTitle: 'Diagnostics',
  diagnosticsGroupDescription: 'More information about the performance of your application.',
};

/** @type {LH.Config.Json} */
const customLighthouseConfig = {
  passes: [{
    passName: 'defaultPass',
    recordTrace: true,
    useThrottling: true,
    pauseAfterLoadMs: 1000,
    networkQuietThresholdMs: 1000,
    cpuQuietThresholdMs: 1000,
    gatherers: [
      'scripts',
      'css-usage',
      'viewport-dimensions',
      'runtime-exceptions',
      'chrome-console-messages',
      'accessibility',
      'anchor-elements',
      'image-elements',
      'link-elements',
      'meta-elements',
      'dobetterweb/appcache',
      'dobetterweb/doctype',
      'dobetterweb/domstats',
      'dobetterweb/js-libraries',
      'dobetterweb/optimized-images',
      'dobetterweb/password-inputs-with-prevented-paste',
      'dobetterweb/response-compression',
      'dobetterweb/tags-blocking-first-paint',
    ],
  },
  {
    passName: 'offlinePass',
    gatherers: [
      'service-worker',
      'offline',
      'start-url',
    ],
  },
  {
    passName: 'redirectPass',
    // Speed up the redirect pass by blocking stylesheets, fonts, and images
    blockedUrlPatterns: ['*.css', '*.jpg', '*.jpeg', '*.png', '*.gif', '*.svg', '*.ttf', '*.woff', '*.woff2'],
    gatherers: [
      'http-redirect',
      'html-without-javascript',
    ],
  }],
  audits: [
    'metrics/first-contentful-paint',
    'metrics/first-meaningful-paint',
    'metrics/speed-index',
    'metrics/estimated-input-latency',
    'time-to-first-byte',
    'metrics/first-cpu-idle',
    'metrics/interactive',
    'mainthread-work-breakdown',
    'bootup-time',
    'uses-rel-preload',
    'uses-rel-preconnect',
    'metrics',
    'byte-efficiency/uses-text-compression',
    'byte-efficiency/uses-long-cache-ttl',
    'byte-efficiency/total-byte-weight',
    'byte-efficiency/render-blocking-resources',
    'byte-efficiency/unminified-javascript',
  ],

  groups: {
    'metrics': {
      title: UIStrings.metricGroupTitle,
    },
    'load-opportunities': {
      title: UIStrings.loadOpportunitiesGroupTitle,
      description: UIStrings.loadOpportunitiesGroupDescription,
    },
    'diagnostics': {
      title: UIStrings.diagnosticsGroupTitle,
      description: UIStrings.diagnosticsGroupDescription,
    },
  },
  categories: {
    'performance': {
      title: UIStrings.performanceCategoryTitle,
      auditRefs: [
        {id: 'first-contentful-paint', weight: 3, group: 'metrics'},
        {id: 'first-meaningful-paint', weight: 1, group: 'metrics'},
        {id: 'speed-index', weight: 4, group: 'metrics'},
        {id: 'interactive', weight: 5, group: 'metrics'},
        {id: 'first-cpu-idle', weight: 2, group: 'metrics'},
        {id: 'estimated-input-latency', weight: 0, group: 'metrics'},
        {id: 'unminified-javascript', weight: 0, group: 'load-opportunities'},
        {id: 'uses-text-compression', weight: 0, group: 'load-opportunities'},
        {id: 'uses-rel-preconnect', weight: 0, group: 'load-opportunities'},
        {id: 'uses-rel-preload', weight: 0, group: 'load-opportunities'},
        {id: 'total-byte-weight', weight: 0, group: 'diagnostics'},
        {id: 'bootup-time', weight: 0, group: 'diagnostics'},
        {id: 'mainthread-work-breakdown', weight: 0, group: 'diagnostics'},
        {id: 'render-blocking-resources', weight: 0, group: 'load-opportunities'},
        {id: 'uses-long-cache-ttl', weight: 0, group: 'diagnostics'},
      ],
    }
  }
};
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...