How to use the lighthouse.Gatherer 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 GoogleChrome / lighthouse / docs / recipes / custom-audit / searchable-gatherer.js View on Github external
/**
 * @license Copyright 2017 Google Inc. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 */
'use strict';

const Gatherer = require('lighthouse').Gatherer;

/**
 * @fileoverview Extracts `window.myLoadMetrics` from the test page.
 */

class TimeToSearchable extends Gatherer {
  afterPass(options) {
    const driver = options.driver;

    return driver.evaluateAsync('window.myLoadMetrics')
      // Ensure returned value is what we expect.
      .then(loadMetrics => {
        if (!loadMetrics || loadMetrics.searchableTime === undefined) {
          // Throw if page didn't provide the metrics we expect. This isn't
          // fatal -- the Lighthouse run will continue, but any audits that
          // depend on this gatherer will show this error string in the report.
github voorhoede / lighthouse-security / gather / ssl-grade.js View on Github external
const Gatherer = require('lighthouse').Gatherer
const ssllabs = require('node-ssllabs');
const { URL } = require('url');

const MAX_DURATION_SECONDS = 120;
const LOCAL_DOMAINS = ['localhost', '127.0.0.1'];

const isLocalDomain = host => LOCAL_DOMAINS.includes(host);

class SslGrade extends Gatherer {
  beforePass(options) {
    const driver = options.driver;
    const origin = new URL(options.url).origin;
    const timeout = options._testTimeout || MAX_DURATION_SECONDS * 1000;

    const sslTestPromise = new Promise((resolve, reject) => {
        if (isLocalDomain(origin)) {
github voorhoede / lighthouse-security / gather / gatherers / generator-meta.js View on Github external
'use strict';

const Gatherer = require('lighthouse').Gatherer;

class GeneratorMeta extends Gatherer {
  /**
   * @param {{driver: !Object}} options Run options
   * @return {!Promise} The value of the generator meta's content attribute, or null
   */
  afterPass(options) {
    const driver = options.driver;

    return driver.querySelector('head meta[name="generator"]')
      .then(node => node && node.getAttribute('content'));
  }
}

module.exports = GeneratorMeta;
github voorhoede / lighthouse-security / gather / gatherers / csp-meta.js View on Github external
'use strict';

const Gatherer = require('lighthouse').Gatherer;

class CspMetaGatherer extends Gatherer {
  afterPass(options) {
    const driver = options.driver;
    const metaSelector = 'meta[http-equiv=Content-Security-Policy]';
    return driver.evaluateAsync(`window.document.querySelectorAll('${metaSelector}')`);
  }
}

module.exports = CspMetaGatherer;
github voorhoede / lighthouse-security / gather / gatherers / redirect.js View on Github external
'use strict';

const Gatherer = require('lighthouse').Gatherer;
const request = require('request-promise');

class HttpRedirect extends Gatherer {
  afterPass(options) {
    const driver = options.driver;

    return driver.evaluateAsync('window.location.host')
      .then(host => {
        return request({
          uri: 'http://' + host,
          method: 'HEAD',
          headers: {
            'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) ' +
                          'AppleWebKit/537.36 (KHTML, like Gecko) ' +
                          'Chrome/59.0.3071.115 Safari/537.36'
          },
github voorhoede / lighthouse-security / gather / gatherers / response-headers.js View on Github external
'use strict';

const Gatherer = require('lighthouse').Gatherer;
const request = require('request');

class ResponseHeaders extends Gatherer {
  afterPass(options) {
    return options.driver.evaluateAsync('window.location.href')
      .then(location => new Promise((resolve, reject) => {
        request({
          uri: location,
          method: 'GET',
          headers: {
            'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) ' +
                          'AppleWebKit/537.36 (KHTML, like Gecko) ' +
                          'Chrome/59.0.3071.115 Safari/537.36'
          }
        }, (err, res) => {
          if (err) {