How to use the lighthouse-logger.formatProtocol function in lighthouse-logger

To help you get started, we’ve selected a few lighthouse-logger 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 / lighthouse-core / gather / connections / connection.js View on Github external
handleRawMessage(message) {
    const object = /** @type {LH.Protocol.RawMessage} */(JSON.parse(message));

    // Responses to commands carry "id" property, while events do not.
    if (!('id' in object)) {
      log.formatProtocol('<= event',
          {method: object.method, params: object.params}, 'verbose');
      this.emitProtocolEvent(object);
      return;
    }

    const callback = this._callbacks.get(object.id);
    if (callback) {
      this._callbacks.delete(object.id);

      callback.resolve(Promise.resolve().then(_ => {
        if (object.error) {
          log.formatProtocol('method <= browser ERR', {method: callback.method}, 'error');
          throw LHError.fromProtocolMessage(callback.method, object.error);
        }

        log.formatProtocol('method <= browser OK',
github foo-software / lighthouse-check-action / node_modules / lighthouse / lighthouse-core / gather / driver.js View on Github external
once(eventName, cb) {
    if (this._eventEmitter === null) {
      throw new Error('connect() must be called before attempting to listen to events.');
    }
    // log event listeners being bound
    log.formatProtocol('listen once for event =>', {method: eventName}, 'verbose');
    this._eventEmitter.once(eventName, cb);
  }
github foo-software / lighthouse-check-action / node_modules / lighthouse / lighthouse-core / gather / driver.js View on Github external
on(eventName, cb) {
    if (this._eventEmitter === null) {
      throw new Error('connect() must be called before attempting to listen to events.');
    }

    // log event listeners being bound
    log.formatProtocol('listen for event =>', {method: eventName}, 'verbose');
    this._eventEmitter.on(eventName, cb);
  }
github GoogleChrome / lighthouse / lighthouse-core / gather / connections / extension.js View on Github external
chrome.debugger.sendCommand({tabId: this._tabId}, method, params || {}, result => {
        if (chrome.runtime.lastError) {
          // The error from the extension has a `message` property that is the
          // stringified version of the actual protocol error object.
          const message = chrome.runtime.lastError.message || '';
          let errorMessage;
          try {
            errorMessage = JSON.parse(message).message;
          } catch (e) {}
          errorMessage = errorMessage || message || 'Unknown debugger protocol error.';

          log.formatProtocol('method <= browser ERR', {method}, 'error');
          return reject(new Error(`Protocol error (${method}): ${errorMessage}`));
        }

        log.formatProtocol('method <= browser OK', {method, params: result}, 'verbose');
        resolve(result);
      });
    });
github GoogleChrome / lighthouse / lighthouse-core / gather / connections / connection.js View on Github external
callback.resolve(Promise.resolve().then(_ => {
        if (object.error) {
          log.formatProtocol('method <= browser ERR', {method: callback.method}, 'error');
          throw LHError.fromProtocolMessage(callback.method, object.error);
        }

        log.formatProtocol('method <= browser OK',
          {method: callback.method, params: object.result}, 'verbose');
        return object.result;
      }));
    } else {
      // In DevTools we receive responses to commands we did not send which we cannot act on, so we
      // just log these occurrences.
      const error = object.error && object.error.message;
      log.formatProtocol(`disowned method <= browser ${error ? 'ERR' : 'OK'}`,
          {method: 'UNKNOWN', params: error || object.result}, 'verbose');
    }
  }
github GoogleChrome / lighthouse / lighthouse-core / gather / connections / extension.js View on Github external
chrome.debugger.sendCommand({tabId: this._tabId}, method, params || {}, result => {
        if (chrome.runtime.lastError) {
          // The error from the extension has a `message` property that is the
          // stringified version of the actual protocol error object.
          const message = chrome.runtime.lastError.message || '';
          let errorMessage;
          try {
            errorMessage = JSON.parse(message).message;
          } catch (e) {}
          errorMessage = errorMessage || message || 'Unknown debugger protocol error.';

          log.formatProtocol('method <= browser ERR', {method}, 'error');
          return reject(new Error(`Protocol error (${method}): ${errorMessage}`));
        }

        log.formatProtocol('method <= browser OK', {method, params: result}, 'verbose');
        resolve(result);
      });
    });
github GoogleChrome / lighthouse / lighthouse-core / gather / driver.js View on Github external
once(eventName, cb) {
    if (this._eventEmitter === null) {
      throw new Error('connect() must be called before attempting to listen to events.');
    }
    // log event listeners being bound
    log.formatProtocol('listen once for event =>', {method: eventName}, 'verbose');
    this._eventEmitter.once(eventName, cb);
  }
github GoogleChrome / lighthouse / lighthouse-core / gather / connections / connection.js View on Github external
callback.resolve(Promise.resolve().then(_ => {
        if (object.error) {
          log.formatProtocol('method <= browser ERR', {method: callback.method}, 'error');
          throw LHError.fromProtocolMessage(callback.method, object.error);
        }

        log.formatProtocol('method <= browser OK',
          {method: callback.method, params: object.result}, 'verbose');
        return object.result;
      }));
    } else {
github GoogleChrome / lighthouse / lighthouse-core / gather / connections / connection.js View on Github external
callback.resolve(Promise.resolve().then(_ => {
        if (object.error) {
          log.formatProtocol('method <= browser ERR', {method: callback.method}, 'error');
          throw LHError.fromProtocolMessage(callback.method, object.error);
        }

        log.formatProtocol('method <= browser OK',
          {method: callback.method, params: object.result}, 'verbose');
        return object.result;
      }));
    } else {