How to use chrome-har - 5 common examples

To help you get started, we’ve selected a few chrome-har 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 oxygenhq / oxygen / ox_modules / module-web.js View on Github external
var logs = _this.driver.getLogs('performance');

        // in one instance, logs was not iterable for some reason - hence the following check:
        if (!logs || typeof logs[Symbol.iterator] !== 'function') {
            console.error('harGet: logs not iterable: ' + JSON.stringify(logs));
            return null;
        }

        var events = [];
        for (var log of logs) {
            var msgObj = JSON.parse(log.message);   // returned as string
            events.push(msgObj.message);
        }

        try {
            const har = harFromMessages(events);
            return JSON.stringify(har);
        } catch (e) {
            console.error('Unable to fetch HAR: ' + e.toString());
            return null;
        }
    }
github sitespeedio / browsertime / lib / chrome / webdriver / chromeDelegate.js View on Github external
}
        }
      };

      if (result.cpu) {
        result.cpu.longTasks = cpu.longTasks;
      } else {
        result.cpu = cpu;
      }
    }

    // CLEANUP since Chromedriver 2.29 there's a bug
    // https://bugs.chromium.org/p/chromedriver/issues/detail?id=1811
    await runner.getLogs(Type.PERFORMANCE);

    const har = perflogParser.harFromMessages(messages);

    if (
      this.chrome.includeResponseBodies === 'html' ||
      this.chrome.includeResponseBodies === 'all'
    ) {
      await this.cdpClient.setResponseBodies(har);
    }

    const versionInfo = (await this.cdpClient.send(
      'Browser.getVersion'
    )).product.split('/');
    const info = {
      name: versionInfo[0],
      version: versionInfo[1]
    };
github googleads / publisher-ads-lighthouse-plugin / gatherers / network.js View on Github external
async afterPass(passContext, loadData) {
    /** @type {Array} */
    const networkEvents = this.devtoolsEvents_.slice();
    log.log('Debug', 'Network: Get trace snapshot');

    const har = chromeHar.harFromMessages(networkEvents);
    const parsedUrls = har.log.entries.map((e) => new URL(e.request.url));

    if (isDebugMode()) {
      // These entries are present in our network artifacts, but are missing in
      // the builtin loadData network records.
      const missingEntries =
          findMissingEntries(har.log.entries, loadData.networkRecords);
      missingEntries.forEach((entry) => {
        log.warn('Debug', 'Missing URL', entry.request.url.substr(0, 100));
      });
    }
    return {har, networkEvents, parsedUrls};
  }
}
github juvirez / bug-recorder / src / devToolsRecorder.ts View on Github external
stop(zip?: JSZip) {
    chrome.debugger.onEvent.removeListener(this.onEvent);

    chrome.debugger.detach(this.debuggee, () => {
      const lastError = chrome.runtime.lastError;
      if (lastError !== undefined) {
        console.warn(lastError.message);
      }
    });

    const harOptions = {
      includeResourcesFromDiskCache: true,
      includeTextFromResponseBody: true
    };
    const har = harFromMessages(this.harEvents, harOptions);

    const log = this.logEntries
      .map(entry => {
        const value = entry.args.map((arg: LogEntryArg) => arg.value).join(" ");
        const timestamp = new Date(entry.timestamp).toISOString();
        return `${entry.type} ${timestamp} ${value}`;
      })
      .join("\n");

    const exceptionLogs = this.exceptions
      .map(exceptionParams => {
        const timestamp = new Date(exceptionParams.timestamp).toISOString();
        return `${timestamp} ${exceptionParams.exceptionDetails.exception.description}`;
      })
      .join("\n");
github Everettss / puppeteer-har / lib / PuppeteerHar.js View on Github external
async stop() {
        this.inProgress = false; 
        await Promise.all(this.response_body_promises);
        await this.client.detach();
        const har = harFromMessages(
            this.page_events.concat(this.network_events),
            {includeTextFromResponseBody: this.saveResponse}
        );
        this.cleanUp();
        if (this.path) {
            await promisify(fs.writeFile)(this.path, JSON.stringify(har));
        } else {
            return har;
        }
    }
}

chrome-har

Create HAR files from Chrome Debugging Protocol data.

MIT
Latest version published 1 month ago

Package Health Score

84 / 100
Full package analysis

Popular chrome-har functions